Memberbuy.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 下单控制器
  16. */
  17. class Memberbuy extends MobileMember {
  18. public function initialize() {
  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. $cart_id = explode(',', input('param.cart_id'));
  134. $logic_buy = model('buy', 'logic');
  135. $transport_model = model('transport');
  136. $chain_model = model('chain');
  137. //得到会员等级
  138. $member_model = model('member');
  139. $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  140. if (!$member_info['is_buylimit']) {
  141. ds_json_encode(10001, lang('cart_buy_noallow'));
  142. }
  143. if (config('ds_config.member_auth') && $this->member_info['member_auth_state'] != 3) {
  144. ds_json_encode(10001, lang('cart_buy_noauth'));
  145. }
  146. /*
  147. if ($member_info) {
  148. $member_gradeinfo = $member_model->getOneMemberGrade(intval($member_info['member_exppoints']));
  149. $member_discount = $member_gradeinfo['orderdiscount'];
  150. $member_level = $member_gradeinfo['level'];
  151. }
  152. else {
  153. $member_discount = $member_level = 0;
  154. } */
  155. //得到购买数据
  156. $ifcart = !empty(input('param.ifcart')) ? true : false;
  157. //额外数据用来处理拼团等其他活动
  158. $pintuan_id = intval(input('param.pintuan_id'));
  159. $extra = array();
  160. if ($pintuan_id > 0) {
  161. $extra['pintuan_id'] = $pintuan_id; #拼团ID
  162. #是否为开团订单
  163. $extra['pintuangroup_id'] = empty(input('param.pintuangroup_id')) ? 0 : intval(input('param.pintuangroup_id'));
  164. }
  165. //砍价活动
  166. $bargainorder_id = intval(input('param.bargainorder_id'));
  167. if ($bargainorder_id > 0) {
  168. $extra['bargainorder_id'] = $bargainorder_id; #砍价ID
  169. }
  170. $result = $logic_buy->buyStep1($cart_id, $ifcart, $this->member_info['member_id'], $this->member_info['store_id'], $extra);
  171. if (!$result['code']) {
  172. ds_json_encode(10001, $result['msg']);
  173. } else {
  174. $result = $result['data'];
  175. }
  176. if (intval(input('post.address_id')) > 0) {
  177. $result['address_info'] = model('address')->getDefaultAddressInfo(array('address_id' => intval(input('post.address_id')), 'member_id' => $this->member_info['member_id']));
  178. }
  179. if ($result['address_info']) {
  180. $data_area = $logic_buy->changeAddr($result['freight_list'], $result['address_info']['city_id'], $result['address_info']['area_id'], $this->member_info['member_id']);
  181. if (!empty($data_area) && $data_area['state'] == 'success') {
  182. if (is_array($data_area['content'])) {
  183. foreach ($data_area['content'] as $store_id => $value) {
  184. $data_area['content'][$store_id] = ds_price_format($value);
  185. }
  186. }
  187. }
  188. }
  189. //判断商品是否限制配送
  190. foreach ($result['store_cart_list'] as $key => $val) {
  191. foreach ($val as $kk => $vv) {
  192. $transport = $transport_model->getTransportInfo(array('transport_id' => $vv['transport_id']));
  193. if(is_array($transport) && $transport['transport_is_limited'] == 1){
  194. $extend_list = $transport_model->getTransportextendList(array('transport_id' => $vv['transport_id']));
  195. if(is_array($extend_list)){
  196. foreach($extend_list as $k => $v){
  197. if($v['transportext_area_id'] != ''){
  198. if (strpos($v['transportext_area_id'], "," . $result['address_info']['city_id'] . ",") === false) {
  199. $result['store_cart_list'][$key][$kk]['limit'] = true;
  200. }else{
  201. $result['store_cart_list'][$key][$kk]['limit'] = false;
  202. }
  203. }
  204. }
  205. }else{
  206. $result['store_cart_list'][$key][$kk]['limit'] = false;
  207. }
  208. }else{
  209. $result['store_cart_list'][$key][$kk]['limit'] = false;
  210. }
  211. }
  212. }
  213. //整理数据
  214. $store_cart_list = array();
  215. $store_total_list = $result['store_goods_total'];
  216. foreach ($result['store_cart_list'] as $key => $value) {
  217. $store_cart_list[$key]['goods_list'] = $value;
  218. $store_cart_list[$key]['store_goods_total'] = $result['store_goods_total'][$key];
  219. $store_cart_list[$key]['store_goods_original_total'] = $result['store_goods_original_total'][$key];
  220. $store_cart_list[$key]['store_goods_discount_total'] = $result['store_goods_discount_total'][$key];
  221. $store_cart_list[$key]['store_mansong_rule_list'] = isset($result['store_mansong_rule_list'][$key]) ? $result['store_mansong_rule_list'][$key] : '';
  222. if ($store_cart_list[$key]['store_mansong_rule_list'] && $store_cart_list[$key]['store_mansong_rule_list']['discount'] > 0) {
  223. $store_total_list[$key] -= $store_cart_list[$key]['store_mansong_rule_list']['discount'];
  224. }
  225. if (isset($result['store_voucher_list'][$key]) && is_array($result['store_voucher_list'][$key]) && count($result['store_voucher_list'][$key]) > 0) {
  226. current($result['store_voucher_list'][$key]);
  227. $store_cart_list[$key]['store_voucher_info'] = reset($result['store_voucher_list'][$key]);
  228. $store_cart_list[$key]['store_voucher_info']['voucher_price'] = ds_price_format($store_cart_list[$key]['store_voucher_info']['voucher_price']);
  229. $store_cart_list[$key]['store_voucher_info']['voucher_enddate_text'] = date('Y年m月d日', $store_cart_list[$key]['store_voucher_info']['voucher_enddate']);
  230. // $store_total_list[$key]-=$store_cart_list[$key]['store_voucher_info']['voucher_price'];
  231. } else {
  232. $store_cart_list[$key]['store_voucher_info'] = array();
  233. }
  234. $store_cart_list[$key]['store_voucher_list'] = isset($result['store_voucher_list'][$key]) ? array_values($result['store_voucher_list'][$key]) : array();
  235. if (!empty($result['cancel_calc_sid_list'][$key])) {
  236. $store_cart_list[$key]['freight'] = '0';
  237. $store_cart_list[$key]['freight_message'] = $result['cancel_calc_sid_list'][$key]['desc'];
  238. }
  239. $store_cart_list[$key]['store_name'] = $value[0]['store_name'];
  240. $store_cart_list[$key]['store_id'] = $value[0]['store_id'];
  241. }
  242. foreach ($result['mall_voucher_list'] as $key => $value) {
  243. $result['mall_voucher_list'][$key]['mallvoucheruser_price'] = ds_price_format($result['mall_voucher_list'][$key]['mallvoucheruser_price']);
  244. $result['mall_voucher_list'][$key]['mallvoucheruser_enddate_text'] = date('Y年m月d日', $result['mall_voucher_list'][$key]['mallvoucheruser_enddate']);
  245. }
  246. $buy_list = array();
  247. $buy_list['if_presell'] = $result['if_presell'];
  248. $buy_list['presell_deposit_amount'] = $result['presell_deposit_amount'];
  249. $buy_list['store_cart_list'] = $store_cart_list;
  250. $buy_list['store_cart_list_api'] = array_values($store_cart_list);
  251. $buy_list['pay_goods_list'] = $result['pay_goods_list'];
  252. $buy_list['freight_hash'] = $result['freight_list'];
  253. $buy_list['address_info'] = $result['address_info'];
  254. $buy_list['ifshow_offpay'] = $result['ifshow_offpay'];
  255. $buy_list['vat_deny'] = $result['vat_deny'];
  256. $buy_list['vat_hash'] = $result['vat_hash'];
  257. $buy_list['inv_info'] = $result['inv_info'];
  258. $buy_list['available_predeposit'] = isset($result['available_predeposit']) ? $result['available_predeposit'] : array();
  259. $buy_list['available_rc_balance'] = isset($result['available_rc_balance']) ? $result['available_rc_balance'] : array();
  260. $buy_list['member_paypwd'] = isset($result['member_paypwd']) ? $result['member_paypwd'] : false;
  261. $buy_list['zk_list'] = isset($result['zk_list']) ? $result['zk_list'] : array();
  262. $buy_list['mall_voucher_list'] = $result['mall_voucher_list'];
  263. $buy_list['limit'] = false;
  264. //判断是否有限制配送的商品,如果有则订单限制下单
  265. foreach($buy_list['store_cart_list'] as $key => $val){
  266. foreach($val['goods_list'] as $k => $v){}
  267. if($v['limit'] == true){
  268. $buy_list['limit'] = true;
  269. }
  270. }
  271. if (isset($data_area['content']) && $data_area['content']) {
  272. $store_total_list = model('buy_1', 'logic')->reCalcGoodsTotal($store_total_list, $data_area['content'], 'freight');
  273. }
  274. $buy_list['order_amount'] = ds_price_format(array_sum($store_total_list));
  275. $buy_list['address_api'] = (isset($data_area) && $data_area) ? $data_area : '';
  276. foreach ($store_total_list as $store_id => $value) {
  277. $store_total_list[$store_id] = ds_price_format($value);
  278. }
  279. $buy_list['store_final_total_list'] = $store_total_list;
  280. ds_json_encode(10000, '', $buy_list);
  281. }
  282. /**
  283. * @api {POST} api/Memberbuy/buy_step2 购物车、直接购买第二步:保存订单入库,产生订单号,开始选择支付方式
  284. * @apiVersion 1.0.0
  285. * @apiGroup MemberBuy
  286. *
  287. * @apiHeader {String} X-DS-KEY 用户授权token
  288. *
  289. * @apiParam {String} ifcart 购买数据
  290. * @apiParam {String} cart_id 购物车ID
  291. * @apiParam {String} address_id 地址ID
  292. * @apiParam {String} vat_hash 增值税
  293. * @apiParam {String} invoice_id 发票ID
  294. * @apiParam {String} voucher 代金券
  295. * @apiParam {String} pd_pay 预存款支付金额
  296. * @apiParam {String} password 支付密码
  297. * @apiParam {String} rcb_pay 充值卡支付金额
  298. * @apiParam {String} pay_message 支付留言
  299. *
  300. * @apiSuccess {String} code 返回码,10000为成功
  301. * @apiSuccess {String} message 返回消息
  302. * @apiSuccess {Object} result 返回数据
  303. * @apiSuccess {String} result.pay_sn 支付单号
  304. * @apiSuccess {String} result.payment_code 支付方式代码
  305. */
  306. public function buy_step2() {
  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. if (empty(input('post.password'))) {
  395. ds_json_encode(10001, lang('param_error'));
  396. }
  397. $member_model = model('member');
  398. $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  399. if ($member_info['member_paypwd'] == md5(input('post.password'))) {
  400. ds_json_encode(10000, '', 1);
  401. } else {
  402. ds_json_encode(10001, lang('password_mistake'));
  403. }
  404. }
  405. /**
  406. * 更换收货地址
  407. */
  408. public function change_address() {
  409. $logic_buy = model('buy', 'logic');
  410. $city_id = input('post.city_id');
  411. $area_id = input('post.area_id');
  412. if (empty($city_id)) {
  413. $city_id = $area_id;
  414. }
  415. $data = $logic_buy->changeAddr(input('post.freight_hash'), $city_id, $area_id, $this->member_info['member_id']);
  416. if (!empty($data) && $data['state'] == 'success') {
  417. ds_json_encode(10000, '', $data);
  418. } else {
  419. ds_json_encode(10001, lang('ds_common_op_fail'));
  420. }
  421. }
  422. /**
  423. * @api {POST} api/Memberbuy/pay 实物订单支付(新接口)
  424. * @apiVersion 1.0.0
  425. * @apiGroup MemberBuy
  426. *
  427. * @apiHeader {String} X-DS-KEY 用户授权token
  428. *
  429. * @apiParam {String} pay_sn 支付单号
  430. *
  431. * @apiSuccess {String} code 返回码,10000为成功
  432. * @apiSuccess {String} message 返回消息
  433. * @apiSuccess {Object} result 返回数据
  434. * @apiSuccess {Float} result.member_available_pd 预存款余额
  435. * @apiSuccess {Float} result.member_available_rcb 充值卡余额
  436. * @apiSuccess {Boolean} result.member_paypwd 已设置支付密码 true是false否
  437. * @apiSuccess {Float} result.pay_amount 支付金额
  438. * @apiSuccess {String} result.pay_sn 支付单号
  439. * @apiSuccess {Float} result.payed_amount 已支付金额
  440. * @apiSuccess {Object[]} result.payment_list 支付方式列表
  441. * @apiSuccess {String} result.payment_list.payment_code 支付方式代码
  442. * @apiSuccess {String} result.payment_list.payment_name 支付方式名称
  443. * @apiSuccess {String} result.payment_list.payment_platform 支付方式适用平台
  444. */
  445. public function pay() {
  446. $pay_sn = input('post.pay_sn');
  447. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  448. ds_json_encode(10001, lang('param_error'));
  449. }
  450. //查询支付单信息
  451. $order_model = model('order');
  452. $pay_info = $order_model->getOrderpayInfo(array(
  453. 'pay_sn' => $pay_sn, 'buyer_id' => $this->member_info['member_id']
  454. ));
  455. if (empty($pay_info)) {
  456. ds_json_encode(10001, lang('cart_order_pay_not_exists'));
  457. }
  458. //取子订单列表
  459. $condition = array();
  460. $condition[] = array('pay_sn', '=', $pay_sn);
  461. $condition[] = array('order_state', 'in', array(ORDER_STATE_NEW, ORDER_STATE_DEPOSIT, ORDER_STATE_REST, ORDER_STATE_PAY, ORDER_STATE_PICKUP));
  462. $order_list = $order_model->getOrderList($condition);
  463. if (empty($order_list)) {
  464. ds_json_encode(10001, lang('no_order_paid_was_found'));
  465. }
  466. //定义输出数组
  467. $pay = array();
  468. //支付提示主信息
  469. //订单总支付金额(不包含货到付款)
  470. $pay['pay_amount'] = 0;
  471. //充值卡支付金额(之前支付中止,余额被锁定)
  472. $pay['payed_rcb_amount'] = 0;
  473. //预存款支付金额(之前支付中止,余额被锁定)
  474. $pay['payed_pd_amount'] = 0;
  475. //还需在线支付金额(之前支付中止,余额被锁定)
  476. $pay['pay_diff_amount'] = 0;
  477. //账户可用金额
  478. $pay['member_available_pd'] = 0;
  479. $pay['member_available_rcb'] = 0;
  480. $logic_order = model('order', 'logic');
  481. //计算相关支付金额
  482. foreach ($order_list as $key => $order_info) {
  483. if (!in_array($order_info['payment_code'], array('offline', 'chain'))) {
  484. if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT || $order_info['order_state'] == ORDER_STATE_REST) {
  485. $pay['payed_rcb_amount'] += $order_info['rcb_amount'];
  486. $pay['payed_pd_amount'] += $order_info['pd_amount'];
  487. if($order_info['order_state'] == ORDER_STATE_DEPOSIT){
  488. $pay['pay_diff_amount'] += $order_info['presell_deposit_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'];
  489. }else{
  490. $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'];
  491. }
  492. }
  493. }
  494. }
  495. if (isset($order_info['chain_id']) && $order_info['payment_code'] == 'chain') {
  496. $order_list[0]['order_remind'] = sprintf(lang('chain_order_remind'), CHAIN_ORDER_PAYPUT_DAY);
  497. $flag_chain = 1;
  498. }
  499. //如果线上线下支付金额都为0,转到支付成功页
  500. if (empty($pay['pay_diff_amount'])) {
  501. ds_json_encode(12001, lang('pay_repeat'));
  502. }
  503. $condition = array();
  504. $condition[] = array('payment_platform', '=', 'h5');
  505. $payment_list = model('payment')->getPaymentOpenList($condition);
  506. if (!empty($payment_list)) {
  507. foreach ($payment_list as $k => $value) {
  508. unset($payment_list[$k]['payment_config']);
  509. unset($payment_list[$k]['payment_state']);
  510. unset($payment_list[$k]['payment_state_text']);
  511. }
  512. }
  513. if (in_array($this->member_info['member_clienttype'], array('ios', 'android'))) {
  514. foreach ($payment_list as $k => $value) {
  515. if (!strpos($payment_list[$k]['payment_code'], 'app')) {
  516. unset($payment_list[$k]);
  517. }
  518. }
  519. }
  520. //显示预存款、支付密码、充值卡
  521. $pay['member_available_pd'] = $this->member_info['available_predeposit'];
  522. $pay['member_available_rcb'] = $this->member_info['available_rc_balance'];
  523. $pay['member_paypwd'] = $this->member_info['member_paypwd'] ? true : false;
  524. $pay['pay_sn'] = $pay_sn;
  525. $pay['payed_amount'] = ds_price_format($pay['payed_rcb_amount'] + $pay['payed_pd_amount']);
  526. unset($pay['payed_pd_amount']);
  527. unset($pay['payed_rcb_amount']);
  528. $pay['pay_amount'] = ds_price_format($pay['pay_diff_amount']);
  529. unset($pay['pay_diff_amount']);
  530. $pay['member_available_pd'] = ds_price_format($pay['member_available_pd']);
  531. $pay['member_available_rcb'] = ds_price_format($pay['member_available_rcb']);
  532. $pay['payment_list'] = $payment_list ? array_values($payment_list) : array();
  533. ds_json_encode(10000, '', array('pay_info' => $pay));
  534. }
  535. /**
  536. * AJAX验证支付密码
  537. */
  538. public function check_pd_pwd() {
  539. if (empty(input('post.password'))) {
  540. ds_json_encode(10001, lang('param_error'));
  541. }
  542. $buyer_info = model('member')->getMemberInfoByID($this->member_info['member_id']);
  543. if ($buyer_info['member_paypwd'] != '') {
  544. if ($buyer_info['member_paypwd'] === md5(input('post.password'))) {
  545. ds_json_encode(10000, '', 1);
  546. }
  547. }
  548. ds_json_encode(10001, lang('payment_password_error'));
  549. }
  550. /**
  551. * F码验证
  552. */
  553. public function check_fcode() {
  554. $goods_id = intval(input('post.goods_id'));
  555. if ($goods_id <= 0) {
  556. ds_json_encode(10001, lang('param_error'));
  557. }
  558. if (input('post.fcode') == '') {
  559. ds_json_encode(10001, lang('param_error'));
  560. }
  561. $result = model('buy', 'logic')->checkFcode($goods_id, trim(input('post.fcode')));
  562. if ($result['code']) {
  563. ds_json_encode(10000, '', 1);
  564. } else {
  565. ds_json_encode(10001, $result['msg']);
  566. }
  567. }
  568. /**
  569. * 获取自提点
  570. */
  571. public function chain_list(){
  572. $chain_model=model('chain');
  573. $area_id=input('param.area_id');
  574. $goods_list=input('param.goods_list');
  575. $goods_list=json_decode(htmlspecialchars_decode($goods_list),true);
  576. $allchain_list = array();
  577. $chain_idsarr = array();
  578. $onechain_id = array();
  579. foreach($goods_list as $key => $val){
  580. if($val['bl_id'] == 1){
  581. foreach($val['bl_goods_list'] as $k => $v){
  582. $chain_ids=Db::name('chain_goods')->where(array(array('goods_id','=',$v['goods_id']),array('goods_storage','>=',1)))->column('chain_id');
  583. if($key == 0){
  584. $onechain_id = $chain_ids;
  585. $chain_idsarr = array_intersect($onechain_id,$chain_ids);
  586. }else{
  587. $chain_idsarr = array_intersect($chain_idsarr,$chain_ids);
  588. }
  589. }
  590. }else{
  591. $chain_ids=Db::name('chain_goods')->where(array(array('goods_id','=',$val['goods_id']),array('goods_storage','>=',$val['goods_num'])))->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. }
  600. foreach($goods_list as $key => $val){
  601. $condition=array();
  602. $condition[]=array('chain_if_pickup','=',1);
  603. $condition[]=array('chain_id','in',$chain_idsarr);
  604. if($area_id){
  605. $condition[]=array('chain_area_2|chain_area_3','=',$area_id);
  606. }
  607. $chain_list=$chain_model->getChainOpenList($condition);
  608. $allchain_list[] = $chain_list ;
  609. }
  610. $chain_list=array_values($chain_list);
  611. return ds_json_encode(10000, '',array('chain_list'=>$chain_list));
  612. }
  613. }