fcode.php 5.5 KB

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