Membervrbuy.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 虚拟购买控制器
  10. */
  11. class Membervrbuy extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/buy.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Membervrbuy/buy_step1 虚拟商品购买第一步,设置接收手机号
  20. * @apiVersion 1.0.0
  21. * @apiGroup Membervrbuy
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiParam {Int} goods_id 商品ID
  26. * @apiParam {Int} quantity 数量
  27. *
  28. * @apiSuccess {String} code 返回码,10000为成功
  29. * @apiSuccess {String} message 返回消息
  30. * @apiSuccess {Object} result 返回数据
  31. * @apiSuccess {Object} result.member_info 用户信息
  32. * @apiSuccess {Boolean} result.member_info.member_paypwd 是否已设置支付密码 true是false否
  33. * @apiSuccess {String} result.member_info.member_mobile 手机号
  34. * @apiSuccess {Float} result.member_info.available_predeposit 可用预存款余额
  35. * @apiSuccess {Float} result.member_info.available_rc_balance 可用充值卡余额
  36. */
  37. public function buy_step1()
  38. {
  39. if (!$this->member_info['is_buylimit']) {
  40. ds_json_encode(10001, lang('cart_buy_noallow'));
  41. }
  42. if (config('ds_config.member_auth') && $this->member_info['member_auth_state'] != 3) {
  43. ds_json_encode(10001, lang('cart_buy_noauth'));
  44. }
  45. $extra = array();
  46. //额外数据用来处理拼团等其他活动
  47. $pintuan_id = intval(input('param.pintuan_id'));
  48. if ($pintuan_id > 0) {
  49. $extra['pintuan_id'] = $pintuan_id; #拼团ID
  50. #是否为开团订单
  51. $extra['pintuangroup_id'] = empty(input('param.pintuangroup_id')) ? 0 : intval(input('param.pintuangroup_id'));
  52. }
  53. $logic_buyvirtual = model('buyvirtual', 'logic');
  54. $result = $logic_buyvirtual->getBuyStep2Data(input('post.goods_id'), input('post.quantity'), $this->member_info['member_id'], $extra);
  55. if (!$result['code']) {
  56. ds_json_encode(10001, $result['msg']);
  57. } else {
  58. $result = $result['data'];
  59. $member_info = array();
  60. $member_info['member_paypwd'] = $result['member_info']['member_paypwd'] ? true : false;
  61. $member_info['member_mobile'] = $result['member_info']['member_mobile'];
  62. $member_info['available_predeposit'] = $result['member_info']['available_predeposit'];
  63. $member_info['available_rc_balance'] = $result['member_info']['available_rc_balance'];
  64. unset($result['member_info']);
  65. $result['member_info'] = $member_info;
  66. if (isset($result['store_voucher_list']) && is_array($result['store_voucher_list']) && count($result['store_voucher_list']) > 0) {
  67. current($result['store_voucher_list']);
  68. $result['goods_info']['store_voucher_info'] = reset($result['store_voucher_list']);
  69. $result['goods_info']['store_voucher_info']['voucher_price'] = ds_price_format($result['goods_info']['store_voucher_info']['voucher_price']);
  70. $result['goods_info']['store_voucher_info']['voucher_enddate_text'] = date('Y年m月d日', $result['goods_info']['store_voucher_info']['voucher_enddate']);
  71. } else {
  72. $result['goods_info']['store_voucher_info'] = array();
  73. }
  74. $result['goods_info']['store_voucher_list'] = isset($result['store_voucher_list']) ? array_values($result['store_voucher_list']) : array();
  75. ds_json_encode(10000, '', $result);
  76. }
  77. }
  78. /**
  79. * @api {POST} api/Membervrbuy/buy_step1 虚拟订单第二步,产生订单
  80. * @apiVersion 1.0.0
  81. * @apiGroup Membervrbuy
  82. *
  83. * @apiHeader {String} X-DS-KEY 用户授权token
  84. *
  85. * @apiParam {Int} goods_id 商品ID
  86. * @apiParam {Int} quantity 数量
  87. * @apiParam {String} buyer_phone 手机号
  88. * @apiParam {String} buyer_msg 买家留言
  89. * @apiParam {String} password 密码
  90. * @apiParam {String} rcb_pay 使用充值卡支付0是/1否
  91. * @apiParam {String} pd_pay 使用预存款支付0是/1否
  92. *
  93. * @apiSuccess {String} code 返回码,10000为成功
  94. * @apiSuccess {String} message 返回消息
  95. * @apiSuccess {Object} result 返回数据
  96. * @apiSuccess {Int} result.order_id 订单ID
  97. * @apiSuccess {String} result.order_sn 订单编号
  98. */
  99. public function buy_step2()
  100. {
  101. $logic_buyvirtual = model('buyvirtual', 'logic');
  102. $input = array();
  103. $input['goods_id'] = input('post.goods_id');
  104. $input['quantity'] = input('post.quantity');
  105. $input['buyer_phone'] = input('post.buyer_phone');
  106. $input['buyer_msg'] = input('post.buyer_msg');
  107. //支付密码
  108. $input['password'] = !empty(input('post.password')) ? input('post.password') : '';
  109. //是否使用充值卡支付0是/1否
  110. $input['rcb_pay'] = empty(input('post.rcb_pay')) ? '0' : '1';
  111. //是否使用预存款支付0是/1否
  112. $input['pd_pay'] = empty(input('post.pd_pay')) ? '0' : '1';
  113. $input['pintuan_id'] = input('post.pintuan_id');
  114. $input['pintuangroup_id'] = input('post.pintuangroup_id');
  115. $input['order_from'] = 2;
  116. $input['voucher'] = input('post.voucher');
  117. $result = $logic_buyvirtual->buyStep3($input, $this->member_info['member_id']);
  118. if (!$result['code']) {
  119. ds_json_encode(10001, $result['msg']);
  120. } else {
  121. ds_json_encode(10000, '', $result['data']);
  122. }
  123. }
  124. /**
  125. * 验证密码
  126. */
  127. public function check_password()
  128. {
  129. if (empty(input('post.password'))) {
  130. ds_json_encode(10001, lang('param_error'));
  131. }
  132. $member_model = model('member');
  133. $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  134. if ($member_info['member_paypwd'] == md5(input('post.password'))) {
  135. ds_json_encode(10000, '', 1);
  136. } else {
  137. ds_json_encode(10001, lang('password_mistake'));
  138. }
  139. }
  140. /**
  141. * 更换收货地址
  142. */
  143. public function change_address()
  144. {
  145. $logic_buy = model('buy', 'logic');
  146. $city_id = 0;
  147. if (empty(input('post.city_id'))) {
  148. $city_id = input('post.area_id');
  149. }
  150. $data = $logic_buy->changeAddr(input('post.freight_hash'), $city_id, input('post.area_id'), $this->member_info['member_id']);
  151. if (!empty($data) && $data['state'] == 'success') {
  152. ds_json_encode(10000, '', $data);
  153. } else {
  154. ds_json_encode(10001, lang('param_error'));
  155. }
  156. }
  157. /**
  158. * @api {POST} api/Membervrbuy/pay 支付方式
  159. * @apiVersion 1.0.0
  160. * @apiGroup Membervrbuy
  161. *
  162. * @apiHeader {String} X-DS-KEY 用户授权token
  163. *
  164. * @apiParam {String} pay_sn 支付单号
  165. *
  166. * @apiSuccess {String} code 返回码,10000为成功
  167. * @apiSuccess {String} message 返回消息
  168. * @apiSuccess {Object} result 返回数据
  169. * @apiSuccess {Float} result.pay_info 支付信息
  170. * @apiSuccess {Float} result.pay_info.member_available_pd 预存款余额
  171. * @apiSuccess {Float} result.pay_info.member_available_rcb 充值卡余额
  172. * @apiSuccess {Boolean} result.pay_info.member_paypwd 已设置支付密码 true是false否
  173. * @apiSuccess {Float} result.pay_info.pay_amount 支付金额
  174. * @apiSuccess {String} result.pay_info.pay_sn 支付单号
  175. * @apiSuccess {Float} result.pay_info.payed_amount 已支付金额
  176. * @apiSuccess {Object[]} result.pay_info.payment_list 支付方式列表
  177. * @apiSuccess {String} result.pay_info.payment_list.payment_code 支付方式代码
  178. * @apiSuccess {String} result.pay_info.payment_list.payment_name 支付方式名称
  179. * @apiSuccess {String} result.pay_info.payment_list.payment_platform 支付方式适用平台
  180. */
  181. public function pay()
  182. {
  183. $pay_sn = input('post.pay_sn');
  184. $condition = array();
  185. $condition[] = array('order_sn', '=', $pay_sn);
  186. $order_info = model('vrorder')->getVrorderInfo($condition);
  187. $condition = array();
  188. $condition[] = array('payment_platform', '=', 'h5');
  189. $payment_list = model('payment')->getPaymentOpenList($condition);
  190. $pay_info['pay_amount'] = $order_info['order_amount'];
  191. $pay_info['member_available_pd'] = $this->member_info['available_predeposit'];
  192. $pay_info['member_available_rcb'] = $this->member_info['available_rc_balance'];
  193. $pay_info['member_paypwd'] = true;
  194. if (empty($this->member_info['member_paypwd'])) {
  195. $pay_info['member_paypwd'] = false;
  196. }
  197. $pay_info['pay_sn'] = $order_info['order_sn'];
  198. $pay_info['payed_amount'] = $order_info['pd_amount'] + $order_info['rcb_amount'];
  199. if ($pay_info['payed_amount'] > '0.00') {
  200. $pay_info['pay_amount'] = $pay_info['pay_amount'] - $pay_info['payed_amount'];
  201. }
  202. //如果线上线下支付金额都为0,转到支付成功页
  203. if (empty($pay_info['pay_amount'])) {
  204. ds_json_encode(12001, lang('pay_repeat'));
  205. }
  206. $pay_in["pay_info"] = $pay_info;
  207. $pay_in["pay_info"]["payment_list"] = $payment_list;
  208. ds_json_encode(10000, '', $pay_in);
  209. }
  210. /**
  211. * 支付密码确认
  212. */
  213. public function check_pd_pwd()
  214. {
  215. if ($this->member_info['member_paypwd'] != md5(input('post.password'))) {
  216. ds_json_encode(10001, lang('payment_password_error'));
  217. } else {
  218. ds_json_encode(10000, '', 'OK');
  219. }
  220. }
  221. }