Memberbuy.php 34 KB

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