diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 4e4177fe6..086308e48 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -81,10 +81,13 @@ class OrderLogic extends BaseLogic $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 - $onePrice = bcsub($find['price'], $find['cost'], 2); - + if ($user && $user['user_ship'] == 4) { + $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); + $cart_select[$k]['deduction_price'] =$deduction_price_count; + self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + } //利润 - $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 + // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 $cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额 $cart_select[$k]['product_id'] = $find['product_id']; @@ -107,9 +110,9 @@ class OrderLogic extends BaseLogic self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2); - self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); + // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); } - $pay_price =self::$pay_price;// bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 + $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 $vipPrice = 0; //成本价 收益 $order = [ @@ -117,7 +120,7 @@ class OrderLogic extends BaseLogic 'order_id' => $params['order_id'] ?? getNewOrderId('PF'), 'total_price' => self::$total_price, //总价 'cost' => self::$cost, //成本价1- - 'profit' => self::$profit, //利润 + 'profit' =>0, //利润 'pay_price' => $pay_price, //后期可能有降价抵扣 'vip_price' => $vipPrice, 'total_num' => count($cart_select), //总数 @@ -128,14 +131,19 @@ class OrderLogic extends BaseLogic 'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 ,2=门店自提 'activity' => '减免', 'activity_price' => self::$activity_price, - 'activities' =>0, - 'deduction_price' => self::$activity_price + 'activities' => self::$activity_price>0?1:0, + 'deduction_price' => self::$activity_price, + 'is_vip' => 0, ]; $order['default_delivery'] = 0; if ($params['store_id']) { $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send'); } + if($user['user_ship']>=1 &&$user['user_ship']<=3){ + $order['is_vip'] = 1; + + } } catch (\Exception $e) { self::setError($e->getMessage()); return false; @@ -159,10 +167,8 @@ class OrderLogic extends BaseLogic return false; } $_order = $orderInfo['order']; - $_order['uid'] = request()->userId; - $user = User::where('id', \request()->userId)->find(); - $_order['is_vip'] = $user['user_ship']; - $_order['spread_uid'] = UserSpreadLog::where('uid',request()->userId)->value('old_spread_uid')??0;//预留分享关系 + $_order['uid'] = $user['id']; + $_order['spread_uid'] =$params['spread_uid'];// UserSpreadLog::where('uid',request()->userId)->value('old_spread_uid')??0;//预留分享关系 $_order['real_name'] = $user['real_name']; $_order['mobile'] = $user['mobile']; $_order['pay_type'] = $orderInfo['order']['pay_type']; @@ -173,7 +179,7 @@ class OrderLogic extends BaseLogic $_order['reservation'] = YesNoEnum::YES; } if ($addressId > 0) { - $address = UserAddress::where(['id' => $addressId, 'uid' => Request()->userId])->find(); + $address = UserAddress::where(['id' => $addressId, 'uid' => $user['id']])->find(); if ($address) { $_order['real_name'] = $address['real_name']; $_order['user_phone'] = $address['phone']; @@ -197,7 +203,7 @@ class OrderLogic extends BaseLogic $updateData = []; foreach ($goods_list as $k => $v) { $goods_list[$k]['oid'] = $order->id; - $goods_list[$k]['uid'] = request()->userId; + $goods_list[$k]['uid'] = $user['id']; $goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id $StoreBranchProduct = StoreBranchProduct::where('id',$v['branch_product_id'])->withTrashed()->find(); diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 01399ff7a..3ba2bc34e 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -4,8 +4,6 @@ namespace app\store\controller\store_order; use app\api\logic\order\OrderLogic; use app\api\validate\OrderValidate; -use app\common\model\order\Cart; -use app\common\model\user\User; use app\store\lists\store_order\StoreOrderLists; use app\common\controller\Definitions; use app\common\enum\PayEnum; @@ -17,7 +15,6 @@ use app\common\logic\store_order\StoreOrderLogic; use app\common\model\store_order\StoreOrder; use app\common\model\user_recharge\UserRecharge; use app\store\validate\store_order\StoreOrderValidate; -use support\Cache; use support\Log; use Webman\RedisQueue\Redis; @@ -127,36 +124,11 @@ class StoreOrderController extends BaseAdminController return $this->data($res); } - - public function checkSms() - { - $params = (new StoreOrderValidate())->post()->goCheck('check'); - - $params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id,用于判断是否是当前店铺的订单 - $user= User::where('id',$params['uid'])->find(); - if(empty($user)){ - return $this->fail('无该用户请检查'); - } - $order = StoreOrderLogic::cartIdByOrderInfo($params['cartId'], null, $user, $params); - if($order['order']['pay_price'] > $user['purchase_funds']){ - return $this->fail('当前用户采购款不足支付'); - } - $res = (new StoreOrderLogic())->dealSendSms($params); - if($res){ - return $this->success('发送成功',[],1,1); - }else{ - return $this->fail('发送失败'); - } - - } - - public function createOrder() { $cartId = (array)$this->request->post('cart_id', []); $pay_type = (int)$this->request->post('pay_type'); $addressId = (int)$this->request->post('address_id'); - $sms_code = $this->request->post('sms_code',''); $auth_code = $this->request->post('auth_code'); //微信支付条码 $params = $this->request->post(); if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) { @@ -165,23 +137,6 @@ class StoreOrderController extends BaseAdminController if (count($cartId) > 100) { return $this->fail('购物车商品不能超过100个'); } - - if($pay_type == PayEnum::PURCHASE_FUNDS && $sms_code){ - if(empty($cartId)){ - return $this->fail('缺失购物车数据'); - } - $uid = Cart::where('id',$cartId[0])->value('uid'); - $remark = $uid.'_smsPay'; - $code = Cache::get($remark); - if(empty($code)){ - return $this->fail('验证码过期请重新发送'); - } - if ($code !== $sms_code) { - return $this->fail('验证码错误'); - } - - } - $params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id,用于判断是否是当前店铺的订单 $order = StoreOrderLogic::createOrder($cartId, $addressId, null, $params); if ($order != false) {