fcode.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/4/6
  6. * Time: 下午1:41
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/fcode/operator.php');
  9. require_once(BASE_ROOT_PATH . '/helper/fcode/mfcode.php');
  10. class fcodeControl extends mobileControl
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. public function indexOp()
  17. {
  18. $common_id = intval($_GET['common_id']);
  19. $batch_code = $_GET['batch_code'];
  20. $sid = $_SESSION['MPHPSESSID'];
  21. $status = intval($_GET['status']);
  22. $mobile = $_GET['mobile'];
  23. if($common_id <= 0 || empty($batch_code)) {
  24. return self::outerr(errcode::ErrParamter,"错误的参数","fcode/error");
  25. }
  26. $oper = new fcode\operator($common_id,$batch_code);
  27. if(empty($mobile)) {
  28. $fcode = $oper->grabed();
  29. } else {
  30. $fcode = $oper->grabed($mobile);
  31. }
  32. $goods = $this->goods($common_id);
  33. if($fcode == false)
  34. {
  35. if(empty($goods)) {
  36. return self::outsuccess(array('error' => "商品已经下架,请关注其它F码"),"fcode/error");
  37. }
  38. elseif($status < 0) {
  39. return self::outsuccess(array('error' => "该商品F码已经被抢光~"),"fcode/error");
  40. }
  41. else {
  42. $name = $goods['goods_name'];
  43. $price = $goods['goods_price'];
  44. $image = $goods['goods_image'];
  45. $image = cthumb($image, 1280, 6);
  46. return self::outsuccess(array('name' => $name,'price' => $price,'image' => $image,
  47. 'common_id' => $common_id,'batch_code' => $batch_code,'sid' => $sid), "fcode/index",'wap');
  48. }
  49. }
  50. else
  51. {
  52. $name = $goods['goods_name'];
  53. $price = $goods['goods_price'];
  54. $image = $goods['goods_image'];
  55. $image = cthumb($image, 1280, 6);
  56. $fcoder = new \fcode\mfcode($fcode);
  57. if($fcoder->binded()) {
  58. return self::outsuccess(array('fcode' => $fcode,'sid' => $sid,'name' => $name,'price' => $price,'image' => $image),"fcode/success");
  59. } else {
  60. return self::outsuccess(array('fcode' => $fcode,'sid' => $sid,'name' => $name,'price' => $price,'image' => $image),"fcode/bind");
  61. }
  62. }
  63. }
  64. private function goods($common_id)
  65. {
  66. $goods_id = commonid_helper::instance()->one_goods($common_id);
  67. $mod = Model('goods');
  68. $goods = $mod->find($goods_id);
  69. return $goods;
  70. }
  71. public function openOp()
  72. {
  73. $common_id = intval($_GET['common_id']);
  74. $batch_code = $_GET['batch_code'];
  75. $sid = $_SESSION['MPHPSESSID'];
  76. if($common_id <= 0 || empty($batch_code)) {
  77. $url = BASE_SITE_URL . "/mobile/index.php?act=fcode&op=index&common_id={$common_id}&batch_code={$batch_code}&HPHPSESSID={$sid}";
  78. return self::outsuccess(array('url' => $url));
  79. }
  80. $oper = new fcode\operator($common_id,$batch_code);
  81. $fcode = $oper->grabed();
  82. if($fcode == false)
  83. {
  84. $fcode = $oper->grab();
  85. if($fcode == false) {
  86. $url = BASE_SITE_URL . "/mobile/index.php?act=fcode&op=index&common_id={$common_id}&batch_code={$batch_code}&HPHPSESSID={$sid}&status=-1";
  87. return self::outsuccess(array('url' => $url));
  88. }
  89. }
  90. else {
  91. $url = BASE_SITE_URL . "/mobile/index.php?act=fcode&op=index&common_id={$common_id}&batch_code={$batch_code}&HPHPSESSID={$sid}";
  92. return self::outsuccess(array('url' => $url));
  93. }
  94. }
  95. public function bindOp()
  96. {
  97. $common_id = intval($_GET['common_id']);
  98. $batch_code = $_GET['batch_code'];
  99. if($common_id <= 0 || empty($batch_code)) {
  100. return self::outerr(errcode::ErrParamter,"错误的参数");
  101. }
  102. $mobile = $_GET['mobile'];
  103. $validator = new Validator();
  104. $validator->setValidate(Validator::verify_mobile($mobile));
  105. $err = $validator->validate();
  106. if ($err != '') {
  107. return self::outerr(errcode::ErrParamter, $err);
  108. }
  109. $oper = new fcode\operator($common_id,$batch_code);
  110. $fcode = $oper->grabed($mobile);
  111. if($fcode == false) {
  112. return self::outerr(errcode::ErrParamter, "您没有该批次商品的F码.");
  113. }
  114. $fcoder = new \fcode\mfcode($fcode);
  115. if($fcoder->binded()) {
  116. return self::outsuccess(null);
  117. }
  118. if(!isset($_GET['code']) || empty($_GET['code'])) {
  119. return self::outerr(errcode::ErrParamter, "请输入验证码.");
  120. }
  121. $code = $_GET['code'];
  122. $ret = sms_helper::check_code(Sms::getfcode_code,$code,$mobile);
  123. if(is_array($ret)) {
  124. return self::outerr($ret['code'], $ret['msg']);
  125. }
  126. else
  127. {
  128. $oper->bind($fcode,$mobile);
  129. return self::outsuccess(null);
  130. }
  131. }
  132. }