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