Memberbuy.php 35 KB

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