Memberbuy.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 下单控制器
  16. */
  17. class Memberbuy extends MobileMember
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize(); // TODO: Change the autogenerated stub
  22. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/buy.lang.php');
  23. }
  24. /**
  25. * @api {POST} api/Memberbuy/buy_step1 购物车、直接购买第一步:选择收获地址和配置方式
  26. * @apiVersion 1.0.0
  27. * @apiGroup MemberBuy
  28. *
  29. * @apiHeader {String} X-DS-KEY 用户授权token
  30. *
  31. * @apiParam {String} cart_id 购买ID
  32. * @apiParam {String} ifcart 购买数据
  33. *
  34. * @apiSuccess {String} code 返回码,10000为成功
  35. * @apiSuccess {String} message 返回消息
  36. * @apiSuccess {Object} result 返回数据
  37. * @apiSuccess {Object} result.address_api 运费信息
  38. * @apiSuccess {String} result.address_api.allow_offpay 是否允许货到付款 0否1是
  39. * @apiSuccess {Object} result.address_api.allow_offpay_batch 货到付款支持列表 键为店铺ID,值为是否支持
  40. * @apiSuccess {Object} result.address_api.content 店铺运费列表 键为店铺ID,值为运费
  41. * @apiSuccess {String} result.address_api.offpay_hash 是否允许货到付款哈希值(PHP验证使用)
  42. * @apiSuccess {String} result.address_api.offpay_hash_batch 货到付款支持列表哈希值(PHP验证使用)
  43. * @apiSuccess {String} result.address_api.state 状态 success成功fail失败
  44. * @apiSuccess {Object} result.address_info 地址信息
  45. * @apiSuccess {String} result.address_info.address_detail 收货人信息地址
  46. * @apiSuccess {Int} result.address_info.address_id 地址ID
  47. * @apiSuccess {String} result.address_info.address_is_default 默认地址 1是0否
  48. * @apiSuccess {String} result.address_info.address_latitude 纬度
  49. * @apiSuccess {String} result.address_info.address_longitude 经度
  50. * @apiSuccess {String} result.address_info.address_mob_phone 收货人手机号
  51. * @apiSuccess {String} result.address_info.address_realname 收货人真实姓名
  52. * @apiSuccess {String} result.address_info.address_tel_phone 收货人座机号
  53. * @apiSuccess {Int} result.address_info.area_id 地区ID
  54. * @apiSuccess {String} result.address_info.area_info 地区信息
  55. * @apiSuccess {Int} result.address_info.city_id 城市ID
  56. * @apiSuccess {Int} result.address_info.chain_id 门店ID
  57. * @apiSuccess {Int} result.address_info.member_id 用户ID
  58. * @apiSuccess {Float} result.available_predeposit 可用预存款余额
  59. * @apiSuccess {Float} result.available_rc_balance 充值卡余额
  60. * @apiSuccess {String} result.freight_hash 运费哈希值
  61. * @apiSuccess {Boolean} result.ifshow_offpay 可用货到付款 true是false否
  62. * @apiSuccess {Object} result.inv_info 发票信息
  63. * @apiSuccess {String} result.inv_info.content 发票信息描述
  64. * @apiSuccess {Boolean} result.member_paypwd 已设置支付密码 true是false否
  65. * @apiSuccess {Float} result.order_amount 订单总价
  66. * @apiSuccess {Object} result.store_cart_list 购物车信息
  67. * @apiSuccess {Object[]} result.store_cart_list.goods_list 商品列表
  68. * @apiSuccess {Int} result.store_cart_list.goods_list.bl_id 优惠套餐ID
  69. * @apiSuccess {Int} result.store_cart_list.goods_list.buyer_id 买家ID
  70. * @apiSuccess {Int} result.store_cart_list.goods_list.cart_id 购物车ID
  71. * @apiSuccess {Int} result.store_cart_list.goods_list.gc_id 分类ID
  72. * @apiSuccess {Int} result.store_cart_list.goods_list.goods_commonid 商品公共ID
  73. * @apiSuccess {Float} result.store_cart_list.goods_list.goods_freight 运费
  74. * @apiSuccess {Int} result.store_cart_list.goods_list.goods_id 商品ID
  75. * @apiSuccess {String} result.store_cart_list.goods_list.goods_image 商品图片名称
  76. * @apiSuccess {String} result.store_cart_list.goods_list.goods_image_url 商品图片完整路径
  77. * @apiSuccess {String} result.store_cart_list.goods_list.goods_name 商品名称
  78. * @apiSuccess {Int} result.store_cart_list.goods_list.goods_num 购买数量
  79. * @apiSuccess {Float} result.store_cart_list.goods_list.goods_price 商品价格
  80. * @apiSuccess {Int} result.store_cart_list.goods_list.goods_storage 商品库存
  81. * @apiSuccess {Int} result.store_cart_list.goods_list.goods_storage_alarm 商品预警库存
  82. * @apiSuccess {Float} result.store_cart_list.goods_list.goods_total 商品总价
  83. * @apiSuccess {Boolean} result.store_cart_list.goods_list.goods_vat 是否支持发票 0否1是
  84. * @apiSuccess {Object} result.store_cart_list.goods_list.groupbuy_info 抢购信息
  85. * @apiSuccess {Int} result.store_cart_list.goods_list.is_goodsfcode 是否F码 0否1是
  86. * @apiSuccess {Int} result.store_cart_list.goods_list.is_have_gift 是否含赠品 0否1是
  87. * @apiSuccess {Object} result.store_cart_list.goods_list.mgdiscount_info 会员折扣信息
  88. * @apiSuccess {Boolean} result.store_cart_list.goods_list.state 商品状态 true上架false下架
  89. * @apiSuccess {Boolean} result.store_cart_list.goods_list.storage_state 库存状态 true足够false不足
  90. * @apiSuccess {Int} result.store_cart_list.goods_list.store_id 店铺ID
  91. * @apiSuccess {Int} result.store_cart_list.goods_list.store_name 店铺名称
  92. * @apiSuccess {Int} result.store_cart_list.goods_list.transport_id 售卖区域id
  93. * @apiSuccess {Object} result.store_cart_list.goods_list.xianshi_info 限时折扣信息
  94. * @apiSuccess {Float} result.store_cart_list.store_goods_total 商品总价
  95. * @apiSuccess {Object} result.store_cart_list.store_id 店铺ID
  96. * @apiSuccess {Object} result.store_cart_list.store_mansong_rule_list 满赠列表
  97. * @apiSuccess {String} result.store_cart_list.store_mansong_rule_list.desc 满赠描述
  98. * @apiSuccess {String} result.store_cart_list.store_mansong_rule_list.discount 优惠金额
  99. * @apiSuccess {Int} result.store_cart_list.store_mansong_rule_list.goods_id 满就送商品ID
  100. * @apiSuccess {Int} result.store_cart_list.store_mansong_rule_list.mansong_endtime 满赠结束时间,Unix时间戳
  101. * @apiSuccess {String} result.store_cart_list.store_mansong_rule_list.mansong_goods_name 满就送礼品名称
  102. * @apiSuccess {Int} result.store_cart_list.store_mansong_rule_list.mansong_id 满赠ID
  103. * @apiSuccess {String} result.store_cart_list.store_mansong_rule_list.mansong_name 满赠名称
  104. * @apiSuccess {Int} result.store_cart_list.store_mansong_rule_list.mansong_starttime 满赠开始时间,Unix时间戳
  105. * @apiSuccess {Float} result.store_cart_list.store_mansong_rule_list.mansongrule_discount 优惠金额
  106. * @apiSuccess {Int} result.store_cart_list.store_mansong_rule_list.mansongrule_id 满就送规则ID
  107. * @apiSuccess {Float} result.store_cart_list.store_mansong_rule_list.mansongrule_price 最低消费金额
  108. * @apiSuccess {String} result.store_cart_list.store_name 店铺ID
  109. * @apiSuccess {Object} result.store_cart_list.store_voucher_info 优先使用的优惠券信息
  110. * @apiSuccess {String} result.store_cart_list.store_voucher_info.desc 优惠券描述
  111. * @apiSuccess {String} result.store_cart_list.store_voucher_info.voucher_activedate 代金券发放日期,Unix时间戳
  112. * @apiSuccess {String} result.store_cart_list.store_voucher_info.voucher_code 代金券编码
  113. * @apiSuccess {String} result.store_cart_list.store_voucher_info.voucher_desc 优惠券详情
  114. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_enddate 代金券有效期结束时间,Unix时间戳
  115. * @apiSuccess {String} result.store_cart_list.store_voucher_info.voucher_enddate_text 代金券有效期结束时间描述
  116. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_id 优惠券ID
  117. * @apiSuccess {Float} result.store_cart_list.store_voucher_info.voucher_limit 优惠券最低金额
  118. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_order_id 优惠券关联订单ID
  119. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_owner_id 优惠券所属用户ID
  120. * @apiSuccess {String} result.store_cart_list.store_voucher_info.voucher_owner_name 优惠券所属用户名称
  121. * @apiSuccess {Float} result.store_cart_list.store_voucher_info.voucher_price 优惠金额
  122. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_startdate 代金券有效期开始时间,Unix时间戳
  123. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_state 代金券状态 1:未用 2:已用 3:过期 4:收回
  124. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_store_id 优惠券发放店铺ID
  125. * @apiSuccess {String} result.store_cart_list.store_voucher_info.voucher_title 优惠券标题
  126. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.voucher_type 代金券类别
  127. * @apiSuccess {Int} result.store_cart_list.store_voucher_info.vouchertemplate_id 优惠券模板ID
  128. * @apiSuccess {Object[]} result.store_cart_list.store_voucher_list 优惠券列表
  129. * @apiSuccess {Object[]} result.store_cart_list_api 去除result.store_cart_list键的数组
  130. * @apiSuccess {Object} result.store_final_total_list 总价列表,键为店铺ID,值为总价
  131. * @apiSuccess {Boolean} result.vat_deny 不支持发票 true是false否
  132. * @apiSuccess {String} result.vat_hash 不支持发票哈希值
  133. */
  134. public function buy_step1()
  135. {
  136. $cart_id = explode(',', input('param.cart_id'));
  137. $logic_buy = model('buy', 'logic');
  138. //得到会员等级
  139. $member_model = model('member');
  140. $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  141. if (!$member_info['is_buylimit']) {
  142. ds_json_encode(10001, lang('cart_buy_noallow'));
  143. }
  144. if (config('ds_config.member_auth') && $this->member_info['member_auth_state'] != 3) {
  145. ds_json_encode(10001, lang('cart_buy_noauth'));
  146. }
  147. /*
  148. if ($member_info) {
  149. $member_gradeinfo = $member_model->getOneMemberGrade(intval($member_info['member_exppoints']));
  150. $member_discount = $member_gradeinfo['orderdiscount'];
  151. $member_level = $member_gradeinfo['level'];
  152. }
  153. else {
  154. $member_discount = $member_level = 0;
  155. } */
  156. //得到购买数据
  157. $ifcart = !empty(input('param.ifcart')) ? true : false;
  158. //额外数据用来处理拼团等其他活动
  159. $pintuan_id = intval(input('param.pintuan_id'));
  160. $extra = [];
  161. if ($pintuan_id > 0) {
  162. $extra['pintuan_id'] = $pintuan_id; #拼团ID
  163. #是否为开团订单
  164. $extra['pintuangroup_id'] = empty(input('param.pintuangroup_id')) ? 0 : intval(input('param.pintuangroup_id'));
  165. }
  166. //砍价活动
  167. $bargainorder_id = intval(input('param.bargainorder_id'));
  168. if ($bargainorder_id > 0) {
  169. $extra['bargainorder_id'] = $bargainorder_id; #砍价ID
  170. }
  171. $result = $logic_buy->buyStep1($cart_id, $ifcart, $this->member_info['member_id'], $this->member_info['store_id'], $extra);
  172. if (!$result['code']) {
  173. ds_json_encode(10001, $result['msg']);
  174. } else {
  175. $result = $result['data'];
  176. }
  177. if (intval(input('post.address_id')) > 0) {
  178. $result['address_info'] = model('address')->getDefaultAddressInfo(['address_id' => intval(input('post.address_id')), 'member_id' => $this->member_info['member_id']]);
  179. }
  180. if ($result['address_info']) {
  181. $data_area = $logic_buy->changeAddr($result['freight_list'], $result['address_info']['city_id'], $result['address_info']['area_id'], $this->member_info['member_id']);
  182. if (!empty($data_area) && $data_area['state'] == 'success') {
  183. if (is_array($data_area['content'])) {
  184. foreach ($data_area['content'] as $store_id => $value) {
  185. $data_area['content'][$store_id] = ds_price_format($value);
  186. }
  187. }
  188. } else {
  189. ds_json_encode(10001, lang('address_request_fail'));
  190. }
  191. }
  192. //整理数据
  193. $store_cart_list = [];
  194. $store_total_list = $result['store_goods_total'];
  195. foreach ($result['store_cart_list'] as $key => $value) {
  196. $store_cart_list[$key]['goods_list'] = $value;
  197. $store_cart_list[$key]['store_goods_total'] = $result['store_goods_total'][$key];
  198. $store_cart_list[$key]['store_goods_original_total'] = $result['store_goods_original_total'][$key];
  199. $store_cart_list[$key]['store_goods_discount_total'] = $result['store_goods_discount_total'][$key];
  200. $store_cart_list[$key]['store_mansong_rule_list'] = isset($result['store_mansong_rule_list'][$key]) ? $result['store_mansong_rule_list'][$key] : '';
  201. if ($store_cart_list[$key]['store_mansong_rule_list'] && $store_cart_list[$key]['store_mansong_rule_list']['discount'] > 0) {
  202. $store_total_list[$key] -= $store_cart_list[$key]['store_mansong_rule_list']['discount'];
  203. }
  204. if (isset($result['store_voucher_list'][$key]) && is_array($result['store_voucher_list'][$key]) && count($result['store_voucher_list'][$key]) > 0) {
  205. current($result['store_voucher_list'][$key]);
  206. $store_cart_list[$key]['store_voucher_info'] = reset($result['store_voucher_list'][$key]);
  207. $store_cart_list[$key]['store_voucher_info']['voucher_price'] = ds_price_format($store_cart_list[$key]['store_voucher_info']['voucher_price']);
  208. $store_cart_list[$key]['store_voucher_info']['voucher_enddate_text'] = date('Y年m月d日', $store_cart_list[$key]['store_voucher_info']['voucher_enddate']);
  209. // $store_total_list[$key]-=$store_cart_list[$key]['store_voucher_info']['voucher_price'];
  210. } else {
  211. $store_cart_list[$key]['store_voucher_info'] = [];
  212. }
  213. $store_cart_list[$key]['store_voucher_list'] = isset($result['store_voucher_list'][$key]) ? array_values($result['store_voucher_list'][$key]) : [];
  214. if (!empty($result['cancel_calc_sid_list'][$key])) {
  215. $store_cart_list[$key]['freight'] = '0';
  216. $store_cart_list[$key]['freight_message'] = $result['cancel_calc_sid_list'][$key]['desc'];
  217. }
  218. $store_cart_list[$key]['store_name'] = $value[0]['store_name'];
  219. $store_cart_list[$key]['store_id'] = $value[0]['store_id'];
  220. }
  221. $buy_list = [];
  222. $buy_list['if_presell'] = $result['if_presell'];
  223. $buy_list['presell_deposit_amount'] = $result['presell_deposit_amount'];
  224. $buy_list['store_cart_list'] = $store_cart_list;
  225. $buy_list['store_cart_list_api'] = array_values($store_cart_list);
  226. $buy_list['pay_goods_list'] = $result['pay_goods_list'];
  227. $buy_list['freight_hash'] = $result['freight_list'];
  228. $buy_list['address_info'] = $result['address_info'];
  229. $buy_list['ifshow_offpay'] = $result['ifshow_offpay'];
  230. $buy_list['vat_deny'] = $result['vat_deny'];
  231. $buy_list['vat_hash'] = $result['vat_hash'];
  232. $buy_list['inv_info'] = $result['inv_info'];
  233. $buy_list['available_predeposit'] = isset($result['available_predeposit']) ? $result['available_predeposit'] : [];
  234. $buy_list['available_rc_balance'] = isset($result['available_rc_balance']) ? $result['available_rc_balance'] : [];
  235. $buy_list['member_paypwd'] = isset($result['member_paypwd']) ? $result['member_paypwd'] : false;
  236. $buy_list['zk_list'] = isset($result['zk_list']) ? $result['zk_list'] : [];
  237. if (isset($data_area['content']) && $data_area['content']) {
  238. $store_total_list = model('buy_1', 'logic')->reCalcGoodsTotal($store_total_list, $data_area['content'], 'freight');
  239. }
  240. $buy_list['order_amount'] = ds_price_format(array_sum($store_total_list));
  241. $buy_list['address_api'] = (isset($data_area) && $data_area) ? $data_area : '';
  242. foreach ($store_total_list as $store_id => $value) {
  243. $store_total_list[$store_id] = ds_price_format($value);
  244. }
  245. $buy_list['store_final_total_list'] = $store_total_list;
  246. ds_json_encode(10000, '', $buy_list);
  247. }
  248. /**
  249. * @api {POST} api/Memberbuy/buy_step2 购物车、直接购买第二步:保存订单入库,产生订单号,开始选择支付方式
  250. * @apiVersion 1.0.0
  251. * @apiGroup MemberBuy
  252. *
  253. * @apiHeader {String} X-DS-KEY 用户授权token
  254. *
  255. * @apiParam {String} ifcart 购买数据
  256. * @apiParam {String} cart_id 购物车ID
  257. * @apiParam {String} address_id 地址ID
  258. * @apiParam {String} vat_hash 增值税
  259. * @apiParam {String} invoice_id 发票ID
  260. * @apiParam {String} voucher 代金券
  261. * @apiParam {String} pd_pay 预存款支付金额
  262. * @apiParam {String} password 支付密码
  263. * @apiParam {String} rcb_pay 充值卡支付金额
  264. * @apiParam {String} pay_message 支付留言
  265. *
  266. * @apiSuccess {String} code 返回码,10000为成功
  267. * @apiSuccess {String} message 返回消息
  268. * @apiSuccess {Object} result 返回数据
  269. * @apiSuccess {String} result.pay_sn 支付单号
  270. * @apiSuccess {String} result.payment_code 支付方式代码
  271. */
  272. public function buy_step2()
  273. {
  274. $param = [];
  275. $param['ifcart'] = input('post.ifcart');
  276. $param['cart_id'] = explode(',', input('post.cart_id'));
  277. $param['address_id'] = input('post.address_id');
  278. $param['vat_hash'] = input('post.vat_hash');
  279. $param['offpay_hash'] = input('post.offpay_hash');
  280. $param['offpay_hash_batch'] = input('post.offpay_hash_batch');
  281. $param['pay_name'] = input('post.pay_name');
  282. $param['invoice_id'] = input('post.invoice_id');
  283. $param['pintuan_id'] = input('post.pintuan_id');
  284. $param['pintuangroup_id'] = input('post.pintuangroup_id');
  285. // $cardId = input('post.card_id');
  286. // if(!empty($cardId) || $cardId !=0){
  287. // //卡券id存在
  288. // $cardInfo = Db::name('sub_card')->where([
  289. // ['id','=',$cardId],
  290. // ['member_id','=',$this->member_info['member_id']]
  291. // ])->find();
  292. // }
  293. //
  294. //
  295. // echo "我打印一下";
  296. // echo input('post.card_id');exit;
  297. //砍价活动
  298. $bargainorder_id = intval(input('param.bargainorder_id'));
  299. if ($bargainorder_id > 0) {
  300. $param['bargainorder_id'] = $bargainorder_id; #砍价ID
  301. }
  302. //处理代金券
  303. $voucher = [];
  304. $post_voucher = explode(',', input('post.voucher'));
  305. if (!empty($post_voucher)) {
  306. foreach ($post_voucher as $value) {
  307. list($vouchertemplate_id, $store_id, $voucher_price) = explode('|', $value);
  308. $voucher[$store_id] = $value;
  309. }
  310. }
  311. $param['voucher'] = $voucher;
  312. $pay_message = trim(input('post.pay_message'), ',');
  313. $pay_message = explode(',', $pay_message);
  314. $param['pay_message'] = [];
  315. if (is_array($pay_message) && $pay_message) {
  316. foreach ($pay_message as $v) {
  317. if (strpos($v, '|') !== false) {
  318. $v = explode('|', $v);
  319. $param['pay_message'][$v[0]] = $v[1];
  320. }
  321. }
  322. }
  323. $param['pd_pay'] = input('post.pd_pay');
  324. $param['rcb_pay'] = input('post.rcb_pay');
  325. $param['password'] = input('post.password');
  326. $param['fcode'] = input('post.fcode');
  327. $param['order_from'] = 2;
  328. $param['chain_goods'] = input('post.chain_goods');
  329. $param['presell_pay'] = input('post.presell_pay');
  330. $logic_buy = model('buy', 'logic');
  331. //得到会员等级
  332. /* $member_model = model('member');
  333. $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  334. if ($member_info) {
  335. $member_gradeinfo = $member_model->getOneMemberGrade(intval($member_info['member_exppoints']));
  336. $member_discount = $member_gradeinfo['orderdiscount'];
  337. $member_level = $member_gradeinfo['level'];
  338. }
  339. else {
  340. $member_discount = $member_level = 0;
  341. } */
  342. // var_dump(1345);exit();
  343. $result = $logic_buy->buyStep2($param, $this->member_info['member_id'], $this->member_info['member_name'], $this->member_info['member_email']);
  344. if (!$result['code']) {
  345. ds_json_encode(10001, $result['msg']);
  346. }
  347. $order_info = current($result['data']['order_list']);
  348. ds_json_encode(10000, '', ['pay_sn' => $result['data']['pay_sn'], 'payment_code' => $order_info['payment_code']]);
  349. }
  350. /**
  351. * 验证密码
  352. */
  353. public function check_password()
  354. {
  355. if (empty(input('post.password'))) {
  356. ds_json_encode(10001, lang('param_error'));
  357. }
  358. $member_model = model('member');
  359. $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  360. if ($member_info['member_paypwd'] == md5(input('post.password'))) {
  361. ds_json_encode(10000, '', 1);
  362. } else {
  363. ds_json_encode(10001, lang('password_mistake'));
  364. }
  365. }
  366. /**
  367. * 更换收货地址
  368. */
  369. public function change_address()
  370. {
  371. $logic_buy = model('buy', 'logic');
  372. $city_id = input('post.city_id');
  373. $area_id = input('post.area_id');
  374. if (empty($city_id)) {
  375. $city_id = $area_id;
  376. }
  377. $data = $logic_buy->changeAddr(input('post.freight_hash'), $city_id, $area_id, $this->member_info['member_id']);
  378. if (!empty($data) && $data['state'] == 'success') {
  379. ds_json_encode(10000, '', $data);
  380. } else {
  381. ds_json_encode(10001, lang('ds_common_op_fail'));
  382. }
  383. }
  384. /**
  385. * @api {POST} api/Memberbuy/pay 实物订单支付(新接口)
  386. * @apiVersion 1.0.0
  387. * @apiGroup MemberBuy
  388. *
  389. * @apiHeader {String} X-DS-KEY 用户授权token
  390. *
  391. * @apiParam {String} pay_sn 支付单号
  392. *
  393. * @apiSuccess {String} code 返回码,10000为成功
  394. * @apiSuccess {String} message 返回消息
  395. * @apiSuccess {Object} result 返回数据
  396. * @apiSuccess {Float} result.member_available_pd 预存款余额
  397. * @apiSuccess {Float} result.member_available_rcb 充值卡余额
  398. * @apiSuccess {Boolean} result.member_paypwd 已设置支付密码 true是false否
  399. * @apiSuccess {Float} result.pay_amount 支付金额
  400. * @apiSuccess {String} result.pay_sn 支付单号
  401. * @apiSuccess {Float} result.payed_amount 已支付金额
  402. * @apiSuccess {Object[]} result.payment_list 支付方式列表
  403. * @apiSuccess {String} result.payment_list.payment_code 支付方式代码
  404. * @apiSuccess {String} result.payment_list.payment_name 支付方式名称
  405. * @apiSuccess {String} result.payment_list.payment_platform 支付方式适用平台
  406. */
  407. public function pay()
  408. {
  409. $pay_sn = input('post.pay_sn');
  410. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  411. ds_json_encode(10001, lang('param_error'));
  412. }
  413. //查询支付单信息
  414. $order_model = model('order');
  415. $pay_info = $order_model->getOrderpayInfo([
  416. 'pay_sn' => $pay_sn, 'buyer_id' => $this->member_info['member_id'],
  417. ]);
  418. if (empty($pay_info)) {
  419. ds_json_encode(10001, lang('cart_order_pay_not_exists'));
  420. }
  421. //取子订单列表
  422. $condition = [];
  423. $condition[] = ['pay_sn', '=', $pay_sn];
  424. $condition[] = ['order_state', 'in', [ORDER_STATE_NEW, ORDER_STATE_DEPOSIT, ORDER_STATE_REST, ORDER_STATE_PAY, ORDER_STATE_PICKUP]];
  425. $order_list = $order_model->getOrderList($condition);
  426. if (empty($order_list)) {
  427. ds_json_encode(10001, lang('no_order_paid_was_found'));
  428. }
  429. //定义输出数组
  430. $pay = [];
  431. //支付提示主信息
  432. //订单总支付金额(不包含货到付款)
  433. $pay['pay_amount'] = 0;
  434. //卡支付金额
  435. $pay['deduction_amount'] = 0;
  436. $pay['pay_amount'] = 0;
  437. //充值卡支付金额(之前支付中止,余额被锁定)
  438. $pay['payed_rcb_amount'] = 0;
  439. //预存款支付金额(之前支付中止,余额被锁定)
  440. $pay['payed_pd_amount'] = 0;
  441. //还需在线支付金额(之前支付中止,余额被锁定)
  442. $pay['pay_diff_amount'] = 0;
  443. //账户可用金额
  444. $pay['member_available_pd'] = 0;
  445. $pay['member_available_rcb'] = 0;
  446. $logic_order = model('order', 'logic');
  447. //计算相关支付金额
  448. foreach ($order_list as $key => $order_info) {
  449. if (!in_array($order_info['payment_code'], ['offline', 'chain'])) {
  450. if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT || $order_info['order_state'] == ORDER_STATE_REST) {
  451. $pay['payed_rcb_amount'] += $order_info['rcb_amount'];
  452. $pay['payed_pd_amount'] += $order_info['pd_amount'];
  453. if ($order_info['order_state'] == ORDER_STATE_DEPOSIT) {
  454. $pay['pay_diff_amount'] += $order_info['presell_deposit_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'];
  455. } else {
  456. $pay['pay_diff_amount'] += $order_info['order_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'];
  457. }
  458. }
  459. }
  460. $pay['deduction_amount'] += $order_info['deduction_amount'];
  461. // $pay['pay_diff_amount'] += $order_info['order_amount'] - $pay['deduction_amount'];
  462. }
  463. if (isset($order_info['chain_id']) && $order_info['payment_code'] == 'chain') {
  464. $order_list[0]['order_remind'] = sprintf(lang('chain_order_remind'), CHAIN_ORDER_PAYPUT_DAY);
  465. $flag_chain = 1;
  466. }
  467. // var_dump($pay['pay_diff_amount']);exit();
  468. //如果线上线下支付金额都为0,转到支付成功页
  469. if (empty($pay['pay_diff_amount'])) {
  470. ds_json_encode(12001, lang('pay_repeat'));
  471. }
  472. $pay['pay_diff_amount'] -= $pay['deduction_amount'];
  473. $condition = [];
  474. $condition[] = ['payment_platform', '=', 'h5'];
  475. $payment_list = model('payment')->getPaymentOpenList($condition);
  476. if (!empty($payment_list)) {
  477. foreach ($payment_list as $k => $value) {
  478. unset($payment_list[$k]['payment_config']);
  479. unset($payment_list[$k]['payment_state']);
  480. unset($payment_list[$k]['payment_state_text']);
  481. }
  482. }
  483. if (in_array($this->member_info['member_clienttype'], ['ios', 'android'])) {
  484. foreach ($payment_list as $k => $value) {
  485. if (!strpos($payment_list[$k]['payment_code'], 'app')) {
  486. unset($payment_list[$k]);
  487. }
  488. }
  489. }
  490. //显示预存款、支付密码、充值卡
  491. $pay['member_available_pd'] = $this->member_info['available_predeposit'];
  492. $pay['member_available_rcb'] = $this->member_info['available_rc_balance'];
  493. $pay['member_available_point'] = $this->member_info['point'];
  494. $pay['member_paypwd'] = $this->member_info['member_paypwd'] ? true : false;
  495. $pay['pay_sn'] = $pay_sn;
  496. $pay['payed_amount'] = ds_price_format($pay['payed_rcb_amount'] + $pay['payed_pd_amount'] + $pay['deduction_amount']);
  497. unset($pay['payed_pd_amount']);
  498. unset($pay['payed_rcb_amount']);
  499. $pay['pay_amount'] = ds_price_format($pay['pay_diff_amount']);
  500. unset($pay['pay_diff_amount']);
  501. $pay['member_available_pd'] = ds_price_format($pay['member_available_pd']);
  502. $pay['member_available_rcb'] = ds_price_format($pay['member_available_rcb']);
  503. $pay['payment_list'] = $payment_list ? array_values($payment_list) : [];
  504. ds_json_encode(10000, '', ['pay_info' => $pay]);
  505. }
  506. /**
  507. * AJAX验证支付密码
  508. */
  509. public function check_pd_pwd()
  510. {
  511. if (empty(input('post.password'))) {
  512. ds_json_encode(10001, lang('param_error'));
  513. }
  514. $buyer_info = model('member')->getMemberInfoByID($this->member_info['member_id']);
  515. if ($buyer_info['member_paypwd'] != '') {
  516. if ($buyer_info['member_paypwd'] === md5(input('post.password'))) {
  517. ds_json_encode(10000, '', 1);
  518. }
  519. }
  520. ds_json_encode(10001, lang('payment_password_error'));
  521. }
  522. /**
  523. * F码验证
  524. */
  525. public function check_fcode()
  526. {
  527. $goods_id = intval(input('post.goods_id'));
  528. if ($goods_id <= 0) {
  529. ds_json_encode(10001, lang('param_error'));
  530. }
  531. if (input('post.fcode') == '') {
  532. ds_json_encode(10001, lang('param_error'));
  533. }
  534. $result = model('buy', 'logic')->checkFcode($goods_id, trim(input('post.fcode')));
  535. if ($result['code']) {
  536. ds_json_encode(10000, '', 1);
  537. } else {
  538. ds_json_encode(10001, $result['msg']);
  539. }
  540. }
  541. }