Membervrbuy.php 10 KB

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