|
|
@@ -110,7 +110,7 @@ class StoreOrder extends BaseController
|
|
110
|
110
|
$coupon = (array)$this->request->param('coupon', []);
|
|
111
|
111
|
$take = (array)$this->request->param('take', []);
|
|
112
|
112
|
$mark = (array)$this->request->param('mark', []);
|
|
113
|
|
- $payType = $this->request->param('pay_type');
|
|
|
113
|
+ $payType = $this->request->param('pay_type');// 5积分 6京豆
|
|
114
|
114
|
$share_id = $this->request->param('share_id','');//分享id
|
|
115
|
115
|
$mer_id = $this->request->param('mer_id','');//分享id
|
|
116
|
116
|
$psType = $this->request->param('type',true);//是否需要地址Boolean
|
|
|
@@ -120,6 +120,8 @@ class StoreOrder extends BaseController
|
|
120
|
120
|
$distribution_mode = $this->request->param('distribution_mode','1');//配送方式
|
|
121
|
121
|
$ziti_address = $this->request->param('distribution_address','');//自提地址
|
|
122
|
122
|
$youhui_price_key = $this->request->param('youhui_price_key','');//优惠key
|
|
|
123
|
+ $decScore = $this->request->param('decScore','');//消耗积分值
|
|
|
124
|
+ $decJingScore = $this->request->param('decJingScore','');//消耗京豆值
|
|
123
|
125
|
$uid = $this->request->uid();
|
|
124
|
126
|
$gong = app()->make(ProductAttrValueRepository::class);
|
|
125
|
127
|
// Db::name('log')->insert(['data'=>'购物车ID---'.$cartId[0]]);
|
|
|
@@ -132,101 +134,42 @@ class StoreOrder extends BaseController
|
|
132
|
134
|
$special_merchant = merchantConfig($product_mer_id, 'special_merchant');
|
|
133
|
135
|
$member_settings=merchantConfig($product_mer_id, 'member_settings');
|
|
134
|
136
|
|
|
135
|
|
- return app('json')->fail('正在升级');
|
|
136
|
137
|
// 增加锁,防止同一用户重读点击
|
|
137
|
138
|
$redis = Cache::store('redis')->handler();
|
|
138
|
139
|
$key = 'createOrder'.$uid;
|
|
139
|
140
|
if (!$redis->setnx($key, 1))
|
|
140
|
141
|
return app('json')->fail('请勿重复下单');
|
|
141
|
142
|
$redis->expire($key, 3);
|
|
|
143
|
+ if (!in_array($payType, [5, 6])) {
|
|
|
144
|
+ return app('json')->fail('支付方式不正确');
|
|
|
145
|
+ }
|
|
|
146
|
+ if (!$decScore && !$decJingScore) {
|
|
|
147
|
+ return app('json')->fail('必须消耗京豆或积分');
|
|
|
148
|
+ }
|
|
142
|
149
|
|
|
143
|
150
|
$user_group = (int)Db::name('user') -> where('uid',$uid)->value('user_group');
|
|
144
|
|
- if($payType=='5'){
|
|
145
|
|
- //$product_mer_id!=148&&$product_mer_id!==290&&
|
|
146
|
|
-
|
|
147
|
|
-
|
|
148
|
|
- if(empty($mer_id) || ($product_mer_id!=148 && $special_merchant != "beishengtang")) {
|
|
149
|
|
- return app('json')->fail('此商户/商品不支持积分支付');
|
|
150
|
|
- }
|
|
151
|
|
-
|
|
152
|
|
-// Db::name('log')->insert(['data'=>'购物车ID'.json_encode($cartId)]);
|
|
153
|
|
- $cartIds=Db::name('store_cart')->where('cart_id','in',$cartId)->select()->toArray();
|
|
154
|
|
-
|
|
155
|
|
-// Db::name('log')->insert(['data'=>'购物车数据'.json_encode($cartIds)]);
|
|
156
|
|
- foreach ($cartIds as $k=>$item){
|
|
157
|
|
- $checkGong = $gong -> checkGong($item['product_id'],$item['product_attr_unique'],$item['cart_num'],$uid,$addressId);
|
|
158
|
|
- if(isset($checkGong['code']) && $checkGong['code'] == -1) return app('json')->fail($checkGong['message']);
|
|
159
|
|
- $money=Db::name('store_product_attr_value')->where('unique',$item['product_attr_unique'])->value('price');
|
|
160
|
|
- $price+=bcmul($money,$item['cart_num'],2);
|
|
161
|
|
- }
|
|
162
|
|
-// $have_money=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->value('integral');
|
|
163
|
|
- if ($special_merchant == "beishengtang"){
|
|
164
|
|
- $have_money = Db::name('user') -> where('uid',$uid) -> value('score_beishengtang');
|
|
165
|
|
- if($have_money<$price){
|
|
166
|
|
- return app('json')->fail('积分不足无法支付');
|
|
167
|
|
- }
|
|
168
|
|
- }else{
|
|
169
|
|
-
|
|
170
|
|
- $have_money = Db::name('user') -> where('uid',$uid) -> value('score');
|
|
171
|
|
- if($have_money<$price*30){
|
|
172
|
|
- return app('json')->fail('积分不足无法支付');
|
|
173
|
|
- }
|
|
174
|
|
- }
|
|
175
|
151
|
|
|
176
|
152
|
|
|
177
|
|
- }else if($payType==6){
|
|
178
|
|
- //一壶茶红积分兑换
|
|
179
|
|
- $cartIds=Db::name('store_cart')->where('cart_id','in',$cartId)->select()->toArray();
|
|
180
|
|
- $red_jifen=0;
|
|
181
|
|
- foreach ($cartIds as $k=>$item){
|
|
182
|
|
- $s_type = Db::name('store_product') -> where('product_id', $item['product_id']) -> value('type');
|
|
183
|
|
- if($s_type!=17){
|
|
184
|
|
- return app('json')->fail('只有会员商品才能使用积分');
|
|
185
|
|
- }
|
|
186
|
|
-
|
|
187
|
|
- $checkGong = $gong -> checkGong($item['product_id'],$item['product_attr_unique'],$item['cart_num'],$uid,$addressId);
|
|
188
|
|
- if(isset($checkGong['code']) && $checkGong['code'] == -1) return app('json')->fail($checkGong['message']);
|
|
189
|
|
- $money=Db::name('store_product_attr_value')->where('unique',$item['product_attr_unique'])->value('price');
|
|
190
|
|
- $red_jifen+=bcmul($money,$item['cart_num'],2);
|
|
191
|
|
- }
|
|
192
|
|
- $red_jifen=ceil($red_jifen);
|
|
193
|
|
-
|
|
194
|
|
- $enterprise_user_data = Db::name('enterprise_user') -> where('uid',$uid)-> where('mer_id',$this->merId) ->find();
|
|
195
|
|
- $green_integral = $enterprise_user_data['green_integral'];
|
|
196
|
|
- if(!$green_integral || $green_integral < $red_jifen){
|
|
197
|
|
- return app('json')->fail('用户红积分不足,请刷新后再试');
|
|
198
|
|
- }
|
|
199
|
|
- if($enterprise_user_data['identity'] < 100){
|
|
200
|
|
- return app('json')->fail('需要您升级为合伙人');
|
|
201
|
|
- }
|
|
202
|
|
-
|
|
203
|
|
-
|
|
204
|
|
- $exchange_phone = $this->request->param('phone','');
|
|
205
|
|
- if(!$exchange_phone || !preg_match("/^1[3456789]{1}\d{9}$/", $exchange_phone)){
|
|
206
|
|
- return app('json')->fail('请正确输入开通账号');
|
|
207
|
|
- }
|
|
208
|
|
- $ex_user=Db::name('user')->where('account',$exchange_phone)->find();
|
|
209
|
|
- if(!$ex_user){
|
|
210
|
|
- $userRepository = app()->make(UserRepository::class);
|
|
211
|
|
- $ex_user = $userRepository->registr($exchange_phone,'123456','APP',$uid);
|
|
212
|
|
- Db::name('user')->where('uid',$ex_user['uid'])->update(['spread_uid'=>$uid,'spread_time'=>date('Y-m-d H:i:s')]);
|
|
213
|
|
- }
|
|
214
|
|
- $enterprise_user_ex_user=Db::name('enterprise_user')->where('uid',$ex_user['uid'])-> where('mer_id',$this->merId)->find();
|
|
215
|
|
- if(!$enterprise_user_ex_user){
|
|
216
|
|
- $inset['uid']=$ex_user['uid'];
|
|
217
|
|
- $inset['mer_id']=$this->merId;
|
|
218
|
|
- $inset['puid']=$uid;
|
|
219
|
|
- $inset['node_uid']=$uid;
|
|
220
|
|
- Db::name('enterprise_user')->insert($inset);
|
|
221
|
|
- $enterprise_user_ex_user['identity']=0;
|
|
222
|
|
- }else if($enterprise_user_ex_user['node_uid']!=$uid){
|
|
223
|
|
- return app('json')->fail('红积分只能用于本人和直推用户使用');
|
|
|
153
|
+ $cartIds=Db::name('store_cart')->where('cart_id','in',$cartId)->select()->toArray();
|
|
|
154
|
+ $price = 0;
|
|
|
155
|
+ foreach ($cartIds as $k=>$item){
|
|
|
156
|
+ $checkGong = $gong -> checkGong($item['product_id'],$item['product_attr_unique'],$item['cart_num'],$uid,$addressId);
|
|
|
157
|
+ if(isset($checkGong['code']) && $checkGong['code'] == -1) return app('json')->fail($checkGong['message']);
|
|
|
158
|
+ $money=Db::name('store_product_attr_value')->where('unique',$item['product_attr_unique'])->value('price');
|
|
|
159
|
+ $price+=bcmul($money,$item['cart_num'],2);
|
|
|
160
|
+ }
|
|
|
161
|
+ if ($payType == '5') {
|
|
|
162
|
+ //积分兑换
|
|
|
163
|
+ $haveScore = Db::name('user')->where('uid', $uid)->value('score');
|
|
|
164
|
+ if ($haveScore < $decScore) {
|
|
|
165
|
+ return app('json')->fail('积分不足');
|
|
224
|
166
|
}
|
|
225
|
|
- if($enterprise_user_ex_user && in_array($enterprise_user_ex_user['identity'],[100,101,102,103,104,105])){
|
|
226
|
|
- return app('json')->fail('此用户已经是合伙人');
|
|
|
167
|
+ } else if ($payType == '6') {
|
|
|
168
|
+ //京豆兑换
|
|
|
169
|
+ $haveJingScore = Db::name('user')->where('uid', $uid)->value('jingdou');
|
|
|
170
|
+ if ($haveJingScore < $decJingScore) {
|
|
|
171
|
+ return app('json')->fail('京豆不足');
|
|
227
|
172
|
}
|
|
228
|
|
-
|
|
229
|
|
-
|
|
230
|
173
|
}
|
|
231
|
174
|
$cartIds=Db::name('store_cart')->where('cart_id','in',$cartId)->select()->toArray();
|
|
232
|
175
|
// $count=count($cartIds);
|
|
|
@@ -431,7 +374,7 @@ class StoreOrder extends BaseController
|
|
431
|
374
|
|
|
432
|
375
|
makeLock()->lock();
|
|
433
|
376
|
try {
|
|
434
|
|
- $groupOrder = $this->repository->createOrder($this->request->userInfo(), array_search($payType, StoreOrderRepository::PAY_TYPE), $cartId, $addressId, $coupon, $take, $mark,$psType,$table_id,$share_id,$payType,$mer_id,$dacang_id,$distribution_mode,$ziti_address,$area_manage_address_ids,$youhui_price_key);
|
|
|
377
|
+ $groupOrder = $this->repository->createOrder($this->request->userInfo(), array_search($payType, StoreOrderRepository::PAY_TYPE), $cartId, $addressId, $coupon, $take, $mark,$psType,$table_id,$share_id,$payType,$mer_id,$dacang_id,$distribution_mode,$ziti_address,$area_manage_address_ids,$youhui_price_key,$decScore,$decJingScore);
|
|
435
|
378
|
} catch (\Throwable $e) {
|
|
436
|
379
|
makeLock()->unlock();
|
|
437
|
380
|
throw $e;
|