Membervrbuy.php 11 KB

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