From 651bcaa8bab0f95806f157d546214a237fe89006 Mon Sep 17 00:00:00 2001 From: Yao <734770036@qq.com> Date: Sat, 28 Sep 2024 10:49:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=96=E6=B6=88=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=AE=A2=E5=8D=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/OrderLogic.php | 755 ++++++++++++++++++----------------- 1 file changed, 393 insertions(+), 362 deletions(-) diff --git a/app/api/logic/OrderLogic.php b/app/api/logic/OrderLogic.php index 8167d080..d838fe0a 100755 --- a/app/api/logic/OrderLogic.php +++ b/app/api/logic/OrderLogic.php @@ -94,9 +94,9 @@ class OrderLogic extends Logic // 初始化支付方式 $post['pay_way'] = 0; if (!empty($post['goods'])) { - $goods = is_array($post['goods']) ? $post['goods'] : json_decode($post['goods'], true); - foreach($goods as $key=>$value){ - $goods_msg = Goods::where('id',$value['goods_id'])->find(); + $goods = is_array($post['goods']) ? $post['goods'] : json_decode($post['goods'], true); + foreach ($goods as $key => $value) { + $goods_msg = Goods::where('id', $value['goods_id'])->find(); $goods[$key]['price_percent'] = $goods_msg['price_percent']; } } else { @@ -106,8 +106,8 @@ class OrderLogic extends Logic $goods = Cart::where($where) ->field(['goods_id', 'item_id', 'shop_id', 'goods_num as num']) ->select()->toArray(); - foreach($goods as $key=>$value){ - $goods_msg = Goods::where(['id',$value['goods_id']])->find(); + foreach ($goods as $key => $value) { + $goods_msg = Goods::where(['id', $value['goods_id']])->find(); $goods[$key]['price_percent'] = $goods_msg['price_percent']; } } @@ -138,6 +138,7 @@ class OrderLogic extends Logic } } + // 校验商品 self::checkGoods($goods); @@ -185,7 +186,7 @@ class OrderLogic extends Logic $order_log_add_data = self::getOrderLogData($key, $post['user_id'], $key); $order_log_datas_insert[] = $order_log_add_data; - $order_goods_data = self::getOrderGoodsData($post,$order_add, $value,$post['user_id']); + $order_goods_data = self::getOrderGoodsData($post, $order_add, $value, $post['user_id']); $order_goods_datas_insert = array_merge($order_goods_datas_insert, $order_goods_data); } @@ -196,14 +197,27 @@ class OrderLogic extends Logic OrderGoods::insertAll($order_goods_datas_insert); //处理抢购订单库存 - if($post['order_type'] == 4){ + if ($post['order_type'] == 4) { - foreach ($post['goods'] as $key=>$buyVal){ + foreach ($post['goods'] as $key => $buyVal) { + + $isOrder = Order::alias('o') + ->join('order_goods og', 'og.order_id = o.id') + ->where([ + 'og.goods_id' => $buyVal['goods_id'], + 'o.order_type' => 4, + 'o.user_id' => $post['user_id'] + ]) + ->where('o.order_status', '<>', '4')->find(); + if ($isOrder) { + throw new Exception('抢购商品每人只限抢购一次'); + } $groupBuy = GroupBuyLogic::isGroupbuy($buyVal['item_id']); - if(!isset($groupBuy)){ + + if (!isset($groupBuy)) { throw new Exception('商品不存在或已下架'); } - if($groupBuy['stock'] <=0){ + if ($groupBuy['stock'] <= 0) { throw new Exception('商品已售馨'); } @@ -231,13 +245,13 @@ class OrderLogic extends Logic // 检测包邮活动 $orders = Db::name('order')->where('trade_id', $order_trade_add)->select()->toArray(); - foreach($orders as $item) { + foreach ($orders as $item) { $address = [ 'province_id' => $item['province'], 'city_id' => $item['city'], 'district_id' => $item['district'], ]; - if(self::isFreeShipping($item['shop_id'], ($item['goods_price'] - $item['discount_amount']), $address)) { + if (self::isFreeShipping($item['shop_id'], ($item['goods_price'] - $item['discount_amount']), $address)) { // 符合包邮条件,去邮费 Db::name('order')->where('id', $item['id'])->update([ 'order_amount' => $item['order_amount'] - $item['shipping_price'], @@ -284,28 +298,28 @@ class OrderLogic extends Logic 'id', 'in', $post['cart_id']] ]; $post['goods'] = $goods = Cart::where($where) - ->field(['goods_id','p_id', 'item_id', 'shop_id', 'goods_num as num']) + ->field(['goods_id', 'p_id', 'item_id', 'shop_id', 'goods_num as num']) ->select()->toArray(); } $w_price = 0; // 检查店铺营业状态 - foreach($post['goods'] as $good) { + foreach ($post['goods'] as $good) { $shop = Shop::field('name,expire_time,is_run,is_freeze')->where(['del' => 0, 'id' => $good['shop_id']])->findOrEmpty(); - if($shop->isEmpty()) { + if ($shop->isEmpty()) { self::$error = '部分商品所属店铺不存在'; return false; } // 获取原始数据(不经获取器) $shop = $shop->getData(); - if(!empty($shop['expire_time']) && ($shop['expire_time'] <= time())) { + if (!empty($shop['expire_time']) && ($shop['expire_time'] <= time())) { self::$error = '部分商品所属店铺已到期'; return false; } - if($shop['is_freeze']) { + if ($shop['is_freeze']) { self::$error = '部分商品所属店铺已被冻结'; return false; } - if(!$shop['is_run']) { + if (!$shop['is_run']) { self::$error = '部分商品所属店铺暂停营业中'; return false; } @@ -326,7 +340,7 @@ class OrderLogic extends Logic ->field('id,contact,telephone,province_id,city_id,district_id,address') ->find()->toArray(); } else { - $address = UserAddress::where(['user_id' => $post['user_id'], 'is_default' => 1,'del' => 0]) + $address = UserAddress::where(['user_id' => $post['user_id'], 'is_default' => 1, 'del' => 0]) ->field('id,contact,telephone,province_id,city_id,district_id,address') ->find(); } @@ -358,9 +372,9 @@ class OrderLogic extends Logic $good['name'] = $goods_item['goods_name']; $good['price'] = $goods_item['price']; $good['original_price'] = $goods_item['price']; - $good['basic_num'] = isset($good['basic_num'])?$good['basic_num']:0; - $good['exc_num'] = isset($good['exc_num'])?$good['exc_num']:0; - $good['w_discount'] = isset($good['w_discount'])?$good['w_discount']:0; + $good['basic_num'] = isset($good['basic_num']) ? $good['basic_num'] : 0; + $good['exc_num'] = isset($good['exc_num']) ? $good['exc_num'] : 0; + $good['w_discount'] = isset($good['w_discount']) ? $good['w_discount'] : 0; $good['spec_value'] = $goods_item['spec_value_str']; $good['image'] = empty($goods_item['image']) ? $goods_item['image'] : $goods_item['image']; $good['image'] = UrlServer::getFileUrl($good['image']); @@ -369,8 +383,8 @@ class OrderLogic extends Logic $shop = []; foreach ($goods as $key => $value) { //按店铺区分商品 - if(isset($value['p_id'])){ - if($value['p_id']>0){ + if (isset($value['p_id'])) { + if ($value['p_id'] > 0) { $shop[$value['shop_id']]['p_id'] = $value['p_id']; } } @@ -405,7 +419,7 @@ class OrderLogic extends Logic // $value['is_groupbuy'] = 0; $groupBuy_price = GoodsItem::isGroupbuy($value['item_id']); - if($groupBuy_price !=0){ + if ($groupBuy_price != 0) { $value['price'] = $groupBuy_price; $value['is_groupbuy'] = 1; self::$order_type = OrderEnum::GROUP_BUY; //秒杀订单 @@ -434,7 +448,7 @@ class OrderLogic extends Logic } $user = User::where('id', $post['user_id'])->find(); - $discount = UserLevel::where(['id' => $user['level'],'del' => 0])->value('discount'); + $discount = UserLevel::where(['id' => $user['level'], 'del' => 0])->value('discount'); // 普通订单才参与会员价 // if (self::$order_type == OrderEnum::NORMAL_ORDER) { // if($discount == 0){ @@ -463,8 +477,8 @@ class OrderLogic extends Logic $num = 0; $total_amount = 0; foreach ($shop[$value['shop_id']]['goods'] as &$item) { - $is_member = Goods::where('id',$item['goods_id'])->value('is_member'); - $price_sum = round($item['price'] * $item['num'],2); + $is_member = Goods::where('id', $item['goods_id'])->value('is_member'); + $price_sum = round($item['price'] * $item['num'], 2); // 商品参与会员价 并且订单是 普通订单 if ($is_member && self::$order_type == OrderEnum::NORMAL_ORDER) { @@ -480,49 +494,49 @@ class OrderLogic extends Logic // } $item['sum_price'] = $price_sum; $num += $item['num']; - $total_amount += round($item['num']*$item['price'],2); + $total_amount += round($item['num'] * $item['price'], 2); } $shop[$value['shop_id']]['total_num'] = $num; } - foreach($shop as $key=>$value){ - $shop[$key]['total_amount'] =0; + foreach ($shop as $key => $value) { + $shop[$key]['total_amount'] = 0; $a = 0; - if(isset($value['p_id'])){ - if($value['p_id']>0){ - foreach($shop[$key]['goods'] as $k=>$v){ - $shop[$key]['total_amount']+= round($v['num']*$v['price'],2); - if($v['w_discount'] > 0){ - $a+=round($v['basic_num']*$v['w_price']*$v['w_discount']/100 + $v['exc_num']*$v['w_price'],2); - $shop[$key]['total_amount'] = round($a,2); - }else{ - $a+=round($v['num']*$v['w_price'],2); - $shop[$key]['total_amount'] = round($a,2); + if (isset($value['p_id'])) { + if ($value['p_id'] > 0) { + foreach ($shop[$key]['goods'] as $k => $v) { + $shop[$key]['total_amount'] += round($v['num'] * $v['price'], 2); + if ($v['w_discount'] > 0) { + $a += round($v['basic_num'] * $v['w_price'] * $v['w_discount'] / 100 + $v['exc_num'] * $v['w_price'], 2); + $shop[$key]['total_amount'] = round($a, 2); + } else { + $a += round($v['num'] * $v['w_price'], 2); + $shop[$key]['total_amount'] = round($a, 2); } } } - }else{ + } else { $all_goods_price = 0; - foreach($shop[$key]['goods'] as $k=>$v){ - $shop[$key]['total_amount']+= round($v['num']*$v['price'],2); + foreach ($shop[$key]['goods'] as $k => $v) { + $shop[$key]['total_amount'] += round($v['num'] * $v['price'], 2); $price_t = 0; - if(isset($v['price_type'])){ - if($v['price_type'] == "jicai_wholesale"){ + if (isset($v['price_type'])) { + if ($v['price_type'] == "jicai_wholesale") { $price_t = 1; } } - if($price_t == 1){ - $goods_w_price = GoodsItem::where("id",$v['item_id'])->find(); - $goods_price =round($v['num']*$goods_w_price['wholesale_pce'],2); + if ($price_t == 1) { + $goods_w_price = GoodsItem::where("id", $v['item_id'])->find(); + $goods_price = round($v['num'] * $goods_w_price['wholesale_pce'], 2); $all_goods_price = round($goods_price + $all_goods_price, 2); } // else{ // $all_goods_price+= round(round($v['price'] * $v['num'], 2) + $value['shipping_price'], 2); // } } - if($all_goods_price!= 0){ - $shop[$key]['total_amount'] = round($all_goods_price,2); + if ($all_goods_price != 0) { + $shop[$key]['total_amount'] = round($all_goods_price, 2); } } @@ -536,10 +550,10 @@ class OrderLogic extends Logic $orders['address'] = $address; $orders['shop'] = $shop; $orders['order_type'] = self::$order_type; - $orders['total_amount'] = round($total_amount,2); + $orders['total_amount'] = round($total_amount, 2); $orders['pay_way_text'] = "微信支付"; $orders['pay_way'] = OrderEnum::PAY_WAY_WECHAT; - if($w_price==0) { + if ($w_price == 0) { // 检验是否参与包邮活动,若参与去除邮费 $orders = self::checkFreeShipping($orders); // 重新算总价 @@ -564,7 +578,7 @@ class OrderLogic extends Logic return $orders; } $address = $orders['address']; - foreach($orders['shop'] as &$item) { + foreach ($orders['shop'] as &$item) { if (self::isFreeShipping($item['shop_id'], ($item['total_amount'] - $item['shipping_price']), $address)) { // 原总价格已算上邮费需减掉 $item['total_amount'] = $item['total_amount'] - $item['shipping_price']; @@ -742,8 +756,8 @@ class OrderLogic extends Logic $field = 'i.id as item_id,g.id as goods_id,g.name,g.del,g.status,i.stock, g.delivery_type as goods_delivery,s.delivery_type as shop_delivery'; $goodsData = (new Goods())->alias('g') - ->join('goods_item i','i.goods_id = g.id') - ->join('shop s','s.id = g.shop_id') + ->join('goods_item i', 'i.goods_id = g.id') + ->join('shop s', 's.id = g.shop_id') ->field($field) ->whereIn('i.id', $item_ids) ->select()->toArray(); @@ -777,22 +791,22 @@ class OrderLogic extends Logic if ($item['delivery_type'] == OrderEnum::DELIVERY_TYPE_EXPRESS) { // 快递发货-商家设置 if (!in_array(ShopEnum::DELIVERY_EXPRESS, explode(',', $goodsInfo['shop_delivery']))) { - throw new Exception( '商家(' . $shopName . ')未开启快递配送'); + throw new Exception('商家(' . $shopName . ')未开启快递配送'); } // 商品设置 if (!in_array(GoodsEnum::DELIVERY_EXPRESS, explode(',', $goodsInfo['goods_delivery']))) { - throw new Exception('商品('. $goodsName . ')暂不支持快递配送'); + throw new Exception('商品(' . $goodsName . ')暂不支持快递配送'); } } if ($item['delivery_type'] == OrderEnum::DELIVERY_TYPE_SELF) { // 线下自提-商家设置 if (!in_array(ShopEnum::DELIVERY_SELF, explode(',', $goodsInfo['shop_delivery']))) { - throw new Exception( '商家(' . $shopName . ')未开启线下自提'); + throw new Exception('商家(' . $shopName . ')未开启线下自提'); } // 商品设置 if (!in_array(GoodsEnum::DELIVERY_SELF, explode(',', $goodsInfo['goods_delivery']))) { - throw new Exception( '商品('. $goodsName .')暂不支持线下自提'); + throw new Exception('商品(' . $goodsName . ')暂不支持线下自提'); } } } @@ -807,7 +821,7 @@ class OrderLogic extends Logic * @author suny * @date 2021/7/13 6:20 下午 */ - public static function calculateGoodsPrice($goods,$discount) + public static function calculateGoodsPrice($goods, $discount) { if (!is_array($goods)) { return false; @@ -816,10 +830,10 @@ class OrderLogic extends Logic $all_goods_price = 0; foreach ($goods as $key => $value) { $price_type = 0; - if(isset($value['price_type'])){ + if (isset($value['price_type'])) { $price_type = $value['price_type']; } - $goods_price = $GoodsItem->sumGoodsPrice($price_type,$value['goods_id'], $value['item_id'], $value['num'],$discount); + $goods_price = $GoodsItem->sumGoodsPrice($price_type, $value['goods_id'], $value['item_id'], $value['num'], $discount); $all_goods_price = round($goods_price + $all_goods_price, 2); } return $all_goods_price; @@ -833,7 +847,7 @@ class OrderLogic extends Logic * @author suny * @date 2021/9/7 4:42 下午 */ - public static function memberGoodsPrice($goods,$discount) + public static function memberGoodsPrice($goods, $discount) { if (!is_array($goods)) { @@ -842,7 +856,7 @@ class OrderLogic extends Logic $GoodsItem = new GoodsItem(); $all_goods_price = 0; foreach ($goods as $key => $value) { - $goods_price = $GoodsItem->sumMemberPrice($value['goods_id'], $value['item_id'], $value['num'],$discount); + $goods_price = $GoodsItem->sumMemberPrice($value['goods_id'], $value['item_id'], $value['num'], $discount); $all_goods_price = round($goods_price + $all_goods_price, 2); } return $all_goods_price; @@ -921,10 +935,10 @@ class OrderLogic extends Logic //计算商品总价格 $user = User::where('id', $post['user_id'])->find(); $discount = UserLevel::where('id', $user['level'])->value('discount'); - if($discount == 0 || self::$order_type != OrderEnum::NORMAL_ORDER){ + if ($discount == 0 || self::$order_type != OrderEnum::NORMAL_ORDER) { $discount = 10; } - $all_goods_price = self::calculateGoodsPrice($post['goods'],$discount); + $all_goods_price = self::calculateGoodsPrice($post['goods'], $discount); //计算商品运费 $all_freight = self::calculateFreight($post['goods'], $address); @@ -970,13 +984,13 @@ class OrderLogic extends Logic $w_price = 0; foreach ($post['goods'] as $key => $value) { $shop_id .= ',' . $value['shop_id']; - if(isset($value['w_price'])){ - if($value['w_price'] != 0){ + if (isset($value['w_price'])) { + if ($value['w_price'] != 0) { $w_price = $value['w_price'] * $value['num']; } } } - if($w_price!=0){ + if ($w_price != 0) { $all_goods_price = $total_amount = $total_amount = $w_price; $discount_amount = 0; } @@ -1028,11 +1042,11 @@ class OrderLogic extends Logic $user = User::where('id', $post['user_id'])->find(); $discount = 0; // $discount = UserLevel::where('id', $user['level'])->value('discount'); - if($discount == 0 || self::$order_type != OrderEnum::NORMAL_ORDER){ + if ($discount == 0 || self::$order_type != OrderEnum::NORMAL_ORDER) { $discount = 10; } - $goods_price = self::calculateGoodsPrice($goods,$discount); //商品价格 - $member_amount = self::memberGoodsPrice($goods,$discount); //会员优惠价格 + $goods_price = self::calculateGoodsPrice($goods, $discount); //商品价格 + $member_amount = self::memberGoodsPrice($goods, $discount); //会员优惠价格 $shipping_price = self::calculateFreight($goods, $address); //计算优惠券优惠的金额 @@ -1044,9 +1058,9 @@ class OrderLogic extends Logic $coupon_list_id = $discount['coupon_list_id']; } - if($goods_price + $shipping_price <= $discount_amount){ + if ($goods_price + $shipping_price <= $discount_amount) { $total_amount = $order_amount = 0; - }else{ + } else { $total_amount = $order_amount = $goods_price + $shipping_price - $discount_amount; } @@ -1062,20 +1076,20 @@ class OrderLogic extends Logic } $order_data = []; $a = 0; - foreach($post['goods'] as $key=>$value){ - if(isset($value['p_id'])){ - if($value['p_id'] > 0){ + foreach ($post['goods'] as $key => $value) { + if (isset($value['p_id'])) { + if ($value['p_id'] > 0) { $a = 1; } } } - if($a==1){ + if ($a == 1) { $total_amount = 0; - foreach($goods as $k=>$v){ - if($v['w_discount'] > 0){ - $total_amount+=round($v['w_price']*$v['basic_num']*$v['w_discount']/100+$v['w_price']*$v['exc_num'],2); - }else{ - $total_amount+=round($v['w_price']*$v['num'],2); + foreach ($goods as $k => $v) { + if ($v['w_discount'] > 0) { + $total_amount += round($v['w_price'] * $v['basic_num'] * $v['w_discount'] / 100 + $v['w_price'] * $v['exc_num'], 2); + } else { + $total_amount += round($v['w_price'] * $v['num'], 2); } } $goods_price = $order_amount = $total_amount; @@ -1111,7 +1125,7 @@ class OrderLogic extends Logic $order_data['coupon_list_id'] = $coupon_list_id; $order_data['create_time'] = time(); - if(isset($post['billions_type'])){ + if (isset($post['billions_type'])) { $order_data['billions_type'] = $post['billions_type']; } @@ -1149,11 +1163,11 @@ class OrderLogic extends Logic * @author suny * @date 2021/7/13 6:21 下午 */ - public static function getOrderGoodsData($post,$order_id, $goods,$user_id) + public static function getOrderGoodsData($post, $order_id, $goods, $user_id) { $user = User::where('id', $user_id)->find(); $discount = UserLevel::where('id', $user['level'])->value('discount'); - if($discount == 0 || self::$order_type != OrderEnum::NORMAL_ORDER){ + if ($discount == 0 || self::$order_type != OrderEnum::NORMAL_ORDER) { $discount = 10; } $goods_data = []; @@ -1164,32 +1178,32 @@ class OrderLogic extends Logic ['goods_id', '=', $value['goods_id']], ])->field('wholesale_pce,price,image,spec_value_ids,spec_value_str,weight') ->find(); - if(isset($value['price_type'])){ - if($value['price_type'] == "jicai_wholesale"){ + if (isset($value['price_type'])) { + if ($value['price_type'] == "jicai_wholesale") { $goods_data[$key]['goods_price'] = $GoodsItem['wholesale_pce']; - }else{ + } else { $goods_data[$key]['goods_price'] = $GoodsItem['price']; } - }else{ + } else { $goods_data[$key]['goods_price'] = $GoodsItem['price']; } - $goods_data[$key]['total_price'] = round($GoodsItem['price'] * $value['num'],2); - $goods_data[$key]['total_pay_price'] = self::calculateGoodsPrice([$value],$discount); - if(isset($value['p_id'])){ + $goods_data[$key]['total_price'] = round($GoodsItem['price'] * $value['num'], 2); + $goods_data[$key]['total_pay_price'] = self::calculateGoodsPrice([$value], $discount); + if (isset($value['p_id'])) { $goods_data[$key]['p_id'] = $value['p_id']; - if($value['p_id']>0){ - $goods_data[$key]['goods_price'] = $value['w_price']; - $goods_data[$key]['total_price'] = round($value['w_price'] * $value['num'],2); - $goods_data[$key]['total_pay_price'] = round($value['w_price'] * $value['num'],2); + if ($value['p_id'] > 0) { + $goods_data[$key]['goods_price'] = $value['w_price']; + $goods_data[$key]['total_price'] = round($value['w_price'] * $value['num'], 2); + $goods_data[$key]['total_pay_price'] = round($value['w_price'] * $value['num'], 2); } } - if(isset($value['set'])){ + if (isset($value['set'])) { $goods_data[$key]['set_id'] = $value['set']; } - if(isset($value['w_price'])){ + if (isset($value['w_price'])) { $goods_data[$key]['w_price'] = $value['w_price']; } - if(isset($value['firend_invite_code'])){ + if (isset($value['firend_invite_code'])) { $goods_data[$key]['firend_invite_code'] = $value['firend_invite_code']; } $goods_data[$key]['order_id'] = $order_id; @@ -1235,8 +1249,8 @@ class OrderLogic extends Logic $item['discount_price'] = $orderDiscount - $sumDiscount; } $item['discount_price'] = round($item['total_pay_price'] / $sumPayPrice * $orderDiscount, 2); - $item['total_pay_price'] -= $item['discount_price']; - $sumDiscount .+ $item['discount_price']; + $item['total_pay_price'] -= $item['discount_price']; + $sumDiscount . +$item['discount_price']; } return $goodsData; @@ -1290,7 +1304,7 @@ class OrderLogic extends Logic */ public static function outGoods($goods_ids) { - try{ + try { $goods = Goods::where('id', 'in', $goods_ids) ->field('id, stock') ->select(); @@ -1302,11 +1316,11 @@ class OrderLogic extends Logic $need_handle_ids = []; foreach ($goods as $good) { if ($good['stock'] <= 0) { - $need_handle_ids[] = $good['id']; + $need_handle_ids[] = $good['id']; } } - if (empty($need_handle_ids)){ + if (empty($need_handle_ids)) { return true; } //下架订单商品中 商品总库存已为0的商品 @@ -1315,7 +1329,8 @@ class OrderLogic extends Logic // 下架或删除商品更新收藏状态 event('UpdateCollect', ['goods_id' => $need_handle_ids]); - } catch (\Exception $e) {} + } catch (\Exception $e) { + } } @@ -1400,17 +1415,17 @@ class OrderLogic extends Logic $where[] = ['order_status', '=', OrderEnum::ORDER_STATUS_DOWN]; break; } - $after_sale = AfterSale::where("user_id",$user_id)->where("status <> 2")->where("del",0)->select(); + $after_sale = AfterSale::where("user_id", $user_id)->where("status <> 2")->where("del", 0)->select(); $after_order_id = $after_order_id_array = ""; - foreach($after_sale as $key=>$value){ - if($key == 0){ + foreach ($after_sale as $key => $value) { + if ($key == 0) { $after_order_id = $value['order_id']; - }else{ - $after_order_id.=",".$value['order_id']; + } else { + $after_order_id .= "," . $value['order_id']; } } - if($after_order_id != ""){ + if ($after_order_id != "") { $after_order_id_array = "id not in ($after_order_id)"; } $count = $order->where(['del' => 0, 'user_id' => $user_id]) @@ -1427,9 +1442,11 @@ class OrderLogic extends Logic ->order('id desc') ->select(); - $lists->append(['goods_count', 'pay_btn', 'cancel_btn', 'delivery_btn', 'take_btn', 'del_btn', 'comment_btn', 'content_btn','order_cancel_time']); + $lists->append(['goods_count', 'pay_btn', 'cancel_btn', 'delivery_btn', 'take_btn', 'del_btn', 'comment_btn', 'content_btn', 'order_cancel_time']); + foreach ($lists as $k => $list) { + $list['order_cancel_time'] = 0; if ($list['order_type'] == OrderEnum::SECKILL_ORDER) {//如果是秒杀 foreach ($list['order_goods'] as $item) { $seckill_price = GoodsItem::isSeckill($item['item_id']); @@ -1439,7 +1456,7 @@ class OrderLogic extends Logic $item['p_id'] = $list['p_id']; $item['w_price'] = $list['w_price']; } - }else{ + } else { foreach ($list['order_goods'] as $item) { $item['p_id'] = $list['p_id']; // if($list['p_id']!=0){ @@ -1522,7 +1539,7 @@ class OrderLogic extends Logic $order = Order::with(['order_goods', 'shop'])->where(['del' => 0, 'id' => $order_id])->find(); if ($order) { - $order->append(['delivery_address', 'pay_btn', 'cancel_btn', 'delivery_btn', 'take_btn', 'del_btn','view_invoice_btn','save_invoice_btn', 'order_cancel_time']) + $order->append(['delivery_address', 'pay_btn', 'cancel_btn', 'delivery_btn', 'take_btn', 'del_btn', 'view_invoice_btn', 'save_invoice_btn', 'order_cancel_time']) ->hidden(['user_id', 'order_source', 'city', 'district', 'address', 'shipping_status', 'shipping_code', 'pay_status', 'transaction_id', 'del', 'province']); @@ -1530,10 +1547,10 @@ class OrderLogic extends Logic $refund_days = ConfigServer::get('after_sale', 'refund_days', 7 * 86400, 0) * 86400; foreach ($order->order_goods as $order_good) { - $after_sale = AfterSale::where("order_id",$order_id)->where("status",0)->where("del",0)->where("goods_id",$order_good['goods_id'])->order("id desc")->limit(1)->find(); - if($after_sale != null){ + $after_sale = AfterSale::where("order_id", $order_id)->where("status", 0)->where("del", 0)->where("goods_id", $order_good['goods_id'])->order("id desc")->limit(1)->find(); + if ($after_sale != null) { $order_good['after_sale_id'] = $after_sale['id']; - }else{ + } else { $order_good['after_sale_id'] = 0; } if ($order['order_type'] == OrderEnum::SECKILL_ORDER) { // 是秒杀商品 @@ -1541,7 +1558,8 @@ class OrderLogic extends Logic if ($seckill_price != 0) { $order_good['goods_price'] = $seckill_price; } - }$order_good['sum_price'] = $order_good['goods_price'] * $order_good['goods_num']; + } + $order_good['sum_price'] = $order_good['goods_price'] * $order_good['goods_num']; $order_good['comment_btn'] = 0; if ($order['pay_status'] == PayEnum::ISPAID && $order['order_status'] == OrderEnum::ORDER_STATUS_COMPLETE && $order_good['is_comment'] == 0) { $order_good['comment_btn'] = 1; @@ -1588,8 +1606,7 @@ class OrderLogic extends Logic // 提货码 if ($order['order_status'] == OrderEnum::ORDER_STATUS_DELIVERY && $order['delivery_type'] == OrderEnum::DELIVERY_TYPE_SELF - && $order['pay_status'] == PayEnum::ISPAID) - { + && $order['pay_status'] == PayEnum::ISPAID) { $order['show_pickup_code'] = 1; } else { $order['show_pickup_code'] = 0; @@ -1642,6 +1659,11 @@ class OrderLogic extends Logic Db::startTrans(); try { + + if ($order['order_type'] == OrderEnum::GROUP_BUY) { + $order_goods = OrderGoods::where('order_id', $order['id'])->find(); + GroupbuyGoods::where(['item_id' => $order_goods['item_id']])->inc('stock', $order['total_num'])->update(); + } // 如果是拼团的订单 if ($order['order_type'] == OrderEnum::TEAM_ORDER) { @@ -1765,17 +1787,18 @@ class OrderLogic extends Logic return $total_fee; } - public static function billions($order_id){ + public static function billions($order_id) + { $order = Order::where(['del' => 0, 'id' => $order_id])->find(); - if($order['billions_type'] == 0){ + if ($order['billions_type'] == 0) { return false; } - if(isset($order['id'])){ + if (isset($order['id'])) { $check_order = Db::name("user_billions") - ->where("order_id",$order['id']) - ->where("type",$order['type']) + ->where("order_id", $order['id']) + ->where("type", $order['type']) ->find(); - if($check_order != null){ + if ($check_order != null) { return true; } } @@ -1788,13 +1811,13 @@ class OrderLogic extends Logic $first_leader = 5; //分销推广者补贴 $store_subsidy = 5; // 店铺推广者补贴 如没有补贴给店铺拥有者 $donglonghui = 5; //东龙汇服务费 - $other_leader = 3; //分公司收入 如没有则并入东龙汇 + $other_leader = 3; //分公司收入 如没有则并入东龙汇 // $performance = 1; // 总部运营人员 $shop_com = 60; // 商家获取收入 - $order_goods = Db::name("order_goods")->where('order_id',$order['id'])->select()->toArray(); - $user = Db::name("user")->where("id",$order['user_id'])->find(); - $is_d = Distribution::where('user_id', $user['first_leader'] )->where('is_distribution', 1 )->find(); - foreach($order_goods as $key=>$value){ + $order_goods = Db::name("order_goods")->where('order_id', $order['id'])->select()->toArray(); + $user = Db::name("user")->where("id", $order['user_id'])->find(); + $is_d = Distribution::where('user_id', $user['first_leader'])->where('is_distribution', 1)->find(); + foreach ($order_goods as $key => $value) { $data['order_price'] = $value['total_pay_price']; $data['user_id'] = $order['user_id']; $data['goods_id'] = $value['goods_id']; @@ -1802,28 +1825,28 @@ class OrderLogic extends Logic $data['goods_num'] = $value['goods_num']; $data['order_id'] = $order['id']; $data['dtime'] = date("Y-m-d H:i:s"); - $data['subsidy_price'] = round($value['total_pay_price']*$user_subsidy/100,8); + $data['subsidy_price'] = round($value['total_pay_price'] * $user_subsidy / 100, 8); $res = Db::name("user_billions")->save($data); - $billions_msg = Db::name("user_billions")->where("state",0)->select()->toArray(); - $subsidy = $value['total_pay_price']*$all_user_subsidy/100; - if($is_d != null){ - $ufl = round($subsidy*$user_first_leader/100,8); - $subsidy_ufl = round($subsidy - $ufl,8); - $first_billions_msg = Db::name("user_billions")->where("user_id",$user['first_leader'])->where("state",0)->select()->toArray(); - if(count($first_billions_msg) > 0){ - foreach($first_billions_msg as $k=>$v){ - if($ufl > 0){ - if($v['order_price'] <= $ufl+$v['subsidy_price']){ + $billions_msg = Db::name("user_billions")->where("state", 0)->select()->toArray(); + $subsidy = $value['total_pay_price'] * $all_user_subsidy / 100; + if ($is_d != null) { + $ufl = round($subsidy * $user_first_leader / 100, 8); + $subsidy_ufl = round($subsidy - $ufl, 8); + $first_billions_msg = Db::name("user_billions")->where("user_id", $user['first_leader'])->where("state", 0)->select()->toArray(); + if (count($first_billions_msg) > 0) { + foreach ($first_billions_msg as $k => $v) { + if ($ufl > 0) { + if ($v['order_price'] <= $ufl + $v['subsidy_price']) { // 查询用户总余额账户 - $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->find(); - if($first_user_all_account != null){ + $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->find(); + if ($first_user_all_account != null) { // 判断账户是否可用 - if($first_user_all_account['state'] == 0 || $first_user_all_account['state'] == 2){ + if ($first_user_all_account['state'] == 0 || $first_user_all_account['state'] == 2) { return -2; } // 更新主表 - $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->inc("total_amount",$v['order_price'])->update(); - if(!$first_update_subsidy_withdrawal){ + $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->inc("total_amount", $v['order_price'])->update(); + if (!$first_update_subsidy_withdrawal) { return -4; } $dat['subsidy_withdrawal_id'] = $first_user_all_account['id']; @@ -1842,14 +1865,14 @@ class OrderLogic extends Logic sendBillionsSubsidySMS($send); } - if(!$first_save_record){ + if (!$first_save_record) { return -5; } - }else{ + } else { $d['user_id'] = $v['user_id']; $d['total_amount'] = $v['order_price']; $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); - if(!$first_update_subsidy_withdrawal){ + if (!$first_update_subsidy_withdrawal) { return -4; } $dat['subsidy_withdrawal_id'] = $first_update_subsidy_withdrawal; @@ -1868,32 +1891,32 @@ class OrderLogic extends Logic sendBillionsSubsidySMS($send); } - if(!$first_save_record){ + if (!$first_save_record) { return -5; } } // 更新排队状态 - $first_update_user_billions = Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$v['order_price'],"state"=>2]); - if(!$first_update_user_billions){ + $first_update_user_billions = Db::name("user_billions")->where("billions_id", $v['billions_id'])->update(['subsidy_price' => $v['order_price'], "state" => 2]); + if (!$first_update_user_billions) { return -3; } // 剩余金额 - $ufl = round($ufl+$v['subsidy_price']-$v['order_price'],8); - }else{ - Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$ufl)->update(); + $ufl = round($ufl + $v['subsidy_price'] - $v['order_price'], 8); + } else { + Db::name("user_billions")->where("billions_id", $v['billions_id'])->inc("subsidy_price", $ufl)->update(); $ufl = 0; } } } - $subsidy = round($subsidy_ufl + $ufl,8); + $subsidy = round($subsidy_ufl + $ufl, 8); } } // $first_msg = Db::name("user_billions")->where("user_id",$user['first_leader'])->where("state",0)->select()->toArray(); $count = count($billions_msg); $arr = $arr1 = array(); // 数量超出前几位补贴用户 - if($count > $user_start_num) { + if ($count > $user_start_num) { $start_subsidy = $subsidy * $user_start_subsidy / 100; $average = round($start_subsidy / $user_start_num, 8); $last = round($start_subsidy - $average * ($user_start_num - 1), 8); @@ -1905,19 +1928,19 @@ class OrderLogic extends Logic } } // 剩余人数补贴 - $end_average = round(($subsidy - $start_subsidy)/ ($count-$user_start_num), 8); - $end_last = round($subsidy - $start_subsidy - $end_average * ($count-$user_start_num - 1), 8); - for ($y = 0; $y < $count-$user_start_num; $y++) { - if ($y + 1 == $count-$user_start_num) { + $end_average = round(($subsidy - $start_subsidy) / ($count - $user_start_num), 8); + $end_last = round($subsidy - $start_subsidy - $end_average * ($count - $user_start_num - 1), 8); + for ($y = 0; $y < $count - $user_start_num; $y++) { + if ($y + 1 == $count - $user_start_num) { $arr1[$y] = $end_last; } else { $arr1[$y] = $end_average; } } - }else{ + } else { $user_start_num = $count; // 数量不超出前几位补贴用户,按全部金额计算 - $average = round($subsidy/$count, 8); + $average = round($subsidy / $count, 8); $last = round($subsidy - $average * ($count - 1), 8); for ($i = 0; $i < $count; $i++) { if ($i + 1 == $count) { @@ -1928,22 +1951,22 @@ class OrderLogic extends Logic } } $billion_arr = $billion_arr_id = ""; - foreach($billions_msg as $k=>$v){ - if($k+1 <= $user_start_num){ + foreach ($billions_msg as $k => $v) { + if ($k + 1 <= $user_start_num) { // var_dump($v['order_price']); // var_dump($arr[$k]); // var_dump($v['subsidy_price']); - if($v['order_price'] <= $arr[$k]+$v['subsidy_price']){ + if ($v['order_price'] <= $arr[$k] + $v['subsidy_price']) { // 查询用户总余额账户 - $user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->find(); - if($user_all_account != null){ + $user_all_account = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->find(); + if ($user_all_account != null) { // 判断账户是否可用 - if($user_all_account['state'] == 0 || $user_all_account['state'] == 2){ + if ($user_all_account['state'] == 0 || $user_all_account['state'] == 2) { return -2; } // 更新主表 - $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->inc("total_amount",$v['order_price'])->update(); - if(!$update_subsidy_withdrawal){ + $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->inc("total_amount", $v['order_price'])->update(); + if (!$update_subsidy_withdrawal) { return -4; } $dat['subsidy_withdrawal_id'] = $user_all_account['id']; @@ -1962,14 +1985,14 @@ class OrderLogic extends Logic sendBillionsSubsidySMS($send); } - if(!$save_record){ + if (!$save_record) { return -5; } - }else{ + } else { $d['user_id'] = $v['user_id']; $d['total_amount'] = $v['order_price']; $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); - if(!$update_subsidy_withdrawal){ + if (!$update_subsidy_withdrawal) { return -4; } $dat['subsidy_withdrawal_id'] = $update_subsidy_withdrawal; @@ -1988,36 +2011,36 @@ class OrderLogic extends Logic sendBillionsSubsidySMS($send); } - if(!$save_record){ + if (!$save_record) { return -5; } } // 更新排队状态 - $update_user_billions = Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$v['order_price'],"state"=>2]); - if(!$update_user_billions){ + $update_user_billions = Db::name("user_billions")->where("billions_id", $v['billions_id'])->update(['subsidy_price' => $v['order_price'], "state" => 2]); + if (!$update_user_billions) { return -3; } // 剩余数量 $residue_count = $user_start_num - $k - 1; - if($residue_count!=0){ + if ($residue_count != 0) { // 剩余金额 - $residue_price = round($arr[$k]+$v['subsidy_price']-$v['order_price'],8); - foreach($arr as $k1=>$v1){ - if($k1 > $k){ - $residue_price+=$arr[$k1]; + $residue_price = round($arr[$k] + $v['subsidy_price'] - $v['order_price'], 8); + foreach ($arr as $k1 => $v1) { + if ($k1 > $k) { + $residue_price += $arr[$k1]; } } - $average = round($residue_price/$residue_count,8); - $last = round($residue_price - $average*($residue_count-1),8); - foreach($arr as $k1=>$v1){ - if($k1+1 == $user_start_num){ + $average = round($residue_price / $residue_count, 8); + $last = round($residue_price - $average * ($residue_count - 1), 8); + foreach ($arr as $k1 => $v1) { + if ($k1 + 1 == $user_start_num) { $arr[$k1] = $last; - }else{ - if($k1 > $k){ + } else { + if ($k1 > $k) { $arr[$k1] = $average; } } @@ -2025,21 +2048,21 @@ class OrderLogic extends Logic } - }else{ + } else { // $subp = round($v['subsidy_price']+$arr[$k],8); // $billion_arr.=" when ".$v['billions_id']." then '".$subp."'"; // $billion_arr_id.=$v['billions_id'].","; - Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$arr[$k])->update(); + Db::name("user_billions")->where("billions_id", $v['billions_id'])->inc("subsidy_price", $arr[$k])->update(); } - }else{ - if($v['order_price'] <= $arr1[$k-$user_start_num]+$v['subsidy_price']){ + } else { + if ($v['order_price'] <= $arr1[$k - $user_start_num] + $v['subsidy_price']) { // 查询用户总余额账户 - $user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->find(); - if($user_all_account == null){ + $user_all_account = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->find(); + if ($user_all_account == null) { $d['user_id'] = $v['user_id']; $d['total_amount'] = $v['order_price']; $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); - if(!$update_subsidy_withdrawal){ + if (!$update_subsidy_withdrawal) { return -4; } $dat['subsidy_withdrawal_id'] = $update_subsidy_withdrawal; @@ -2058,18 +2081,18 @@ class OrderLogic extends Logic sendBillionsSubsidySMS($send); } - if(!$save_record){ + if (!$save_record) { return -5; } - }else{ + } else { // 判断账户是否可用 - if($user_all_account['state'] == 0 || $user_all_account['state'] == 2){ + if ($user_all_account['state'] == 0 || $user_all_account['state'] == 2) { return -2; } // 更新主表 - $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->inc("total_amount",$v['order_price'])->update(); - if(!$update_subsidy_withdrawal){ + $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->inc("total_amount", $v['order_price'])->update(); + if (!$update_subsidy_withdrawal) { return -4; } $dat['subsidy_withdrawal_id'] = $user_all_account['id']; @@ -2088,44 +2111,44 @@ class OrderLogic extends Logic sendBillionsSubsidySMS($send); } - if(!$save_record){ + if (!$save_record) { return -5; } } // 更新排队状态 - $update_user_billions = Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$v['order_price'],"state"=>2]); - if(!$update_user_billions){ + $update_user_billions = Db::name("user_billions")->where("billions_id", $v['billions_id'])->update(['subsidy_price' => $v['order_price'], "state" => 2]); + if (!$update_user_billions) { return -3; } // 剩余数量 - $residue_count = $count-$user_start_num - $k+$user_start_num - 1; - if($residue_count!=0){ + $residue_count = $count - $user_start_num - $k + $user_start_num - 1; + if ($residue_count != 0) { // 剩余金额 - $residue_price = round($arr1[$k-$user_start_num]+$v['subsidy_price']-$v['order_price'],8); - foreach($arr1 as $k1=>$v1){ - if($k1 > $k - $user_start_num){ - $residue_price+=$arr1[$k1]; + $residue_price = round($arr1[$k - $user_start_num] + $v['subsidy_price'] - $v['order_price'], 8); + foreach ($arr1 as $k1 => $v1) { + if ($k1 > $k - $user_start_num) { + $residue_price += $arr1[$k1]; } } - $average = round($residue_price/$residue_count,8); - $last = round($residue_price - $average*($residue_count-1),8); - foreach($arr1 as $k1=>$v1){ - if($k1+1 == $count-$user_start_num){ + $average = round($residue_price / $residue_count, 8); + $last = round($residue_price - $average * ($residue_count - 1), 8); + foreach ($arr1 as $k1 => $v1) { + if ($k1 + 1 == $count - $user_start_num) { $arr1[$k1] = $last; - }else{ - if($k1 > $k){ + } else { + if ($k1 > $k) { $arr[$k1] = $average; } } } } - }else{ + } else { // $subp = round($v['subsidy_price']+$arr1[$k-$user_start_num],8); // $billion_arr.=" when ".$v['billions_id']." then '".$subp."'"; // $billion_arr_id.=$v['billions_id'].","; - Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$arr1[$k-$user_start_num])->update(); + Db::name("user_billions")->where("billions_id", $v['billions_id'])->inc("subsidy_price", $arr1[$k - $user_start_num])->update(); } } } @@ -2140,11 +2163,11 @@ class OrderLogic extends Logic // END // WHERE billions_id IN ($billion_arr_id)"; // $query = Db::query($sql); - if($is_d!=null){ - if($user['first_leader']>0){ - $first_leader_percent = round($value['total_pay_price']*$first_leader / 100, 8); + if ($is_d != null) { + if ($user['first_leader'] > 0) { + $first_leader_percent = round($value['total_pay_price'] * $first_leader / 100, 8); Order::where('id', $order['id']) - ->inc('distribution_money',$first_leader_percent)->update(); + ->inc('distribution_money', $first_leader_percent)->update(); UserDistribution::where('user_id', $user['first_leader']) ->inc('order_amount', $first_leader_percent)->update(); UserDistribution::where('user_id', $user['first_leader']) @@ -2179,18 +2202,18 @@ class OrderLogic extends Logic ]); } // 店铺推广收益 - $shop_user_msg = Shop::where('id', $value['shop_id'] )->find(); - if($shop_user_msg['reference_user_id'] == 0){ + $shop_user_msg = Shop::where('id', $value['shop_id'])->find(); + if ($shop_user_msg['reference_user_id'] == 0) { $shop_user_msg['reference_user_id'] = $order['user_id']; } - $shop_u = Distribution::where('user_id', $shop_user_msg['reference_user_id'])->where('is_distribution', 1 )->find(); - if($shop_u!=null){ + $shop_u = Distribution::where('user_id', $shop_user_msg['reference_user_id'])->where('is_distribution', 1)->find(); + if ($shop_u != null) { $shop_percent = round($value['total_pay_price'] * $store_subsidy / 100, 8); Order::where('id', $order['id']) - ->inc('distribution_money',$shop_percent)->update(); - $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) + ->inc('distribution_money', $shop_percent)->update(); + $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) ->find(); - if($shopDistribution_msg == null){ + if ($shopDistribution_msg == null) { UserShopDistribution::create([ 'shop_id' => $value['shop_id'], 'order_num' => 1, @@ -2198,7 +2221,7 @@ class OrderLogic extends Logic 'create_time' => time(), 'update_time' => time() ]); - }else{ + } else { UserShopDistribution::where('shop_id', $value['shop_id']) ->inc('order_amount', $shop_percent)->update(); UserShopDistribution::where('shop_id', $value['shop_id']) @@ -2234,14 +2257,14 @@ class OrderLogic extends Logic ]); } // 1%给运营人员 - $divide_second_user_msg = Db::name("user")->where("id",$user['divide_second_user_id'])->find(); + $divide_second_user_msg = Db::name("user")->where("id", $user['divide_second_user_id'])->find(); $regional_state = 0; - if($divide_second_user_msg != null){ + if ($divide_second_user_msg != null) { $regional_state = $divide_second_user_msg['regional_state']; } $performance_person = 0; $performance = 0; - if($regional_state == 1){ + if ($regional_state == 1) { $performance = $user['regional_percent']; $performance_person = round($value['total_pay_price'] * $performance / 100, 8); // Order::where('id', $order['id']) @@ -2279,13 +2302,13 @@ class OrderLogic extends Logic } // 3%对公司 - $role_user_msg = Db::name("user")->where("id",$user['divide_role_user_id'])->find(); + $role_user_msg = Db::name("user")->where("id", $user['divide_role_user_id'])->find(); $state = 0; - if($role_user_msg != null){ + if ($role_user_msg != null) { $state = $role_user_msg['divide_state']; } - if($user['divide_role_user_id'] > 0&&$state>0 ){ - $divide_percent = round($value['total_pay_price'] * ($other_leader-$performance) / 100, 8); + if ($user['divide_role_user_id'] > 0 && $state > 0) { + $divide_percent = round($value['total_pay_price'] * ($other_leader - $performance) / 100, 8); // Order::where('id', $order['id']) // ->inc('distribution_money',$divide_percent)->update(); // $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) @@ -2308,7 +2331,7 @@ class OrderLogic extends Logic DistributionOrderGoods::create([ 'sn' => $sn, 'user_id' => $user['divide_role_user_id'], - 'ratio' => $other_leader-$performance, + 'ratio' => $other_leader - $performance, 'order_id' => $order['id'], 'order_goods_id' => $value['id'], 'goods_num' => $value['goods_num'], @@ -2323,6 +2346,7 @@ class OrderLogic extends Logic } } + /** * @notes 确认订单 * @param $order_id @@ -2356,85 +2380,85 @@ class OrderLogic extends Logic $user_id, OrderLogEnum::USER_CONFIRM_ORDER ); - if($order['billions_type'] == 1){ + if ($order['billions_type'] == 1) { return JsonServer::success('确认成功'); } - if($order['pay_way'] != 3){ + if ($order['pay_way'] != 3) { return JsonServer::success('确认成功'); } // 添加信用额度 - $xy_set = Db::name("procurement_xy_set")->where("s_id",1)->find(); - $is_p_user = Mprocurement::where("user_id",$user_id)->where("u_state",1)->find(); + $xy_set = Db::name("procurement_xy_set")->where("s_id", 1)->find(); + $is_p_user = Mprocurement::where("user_id", $user_id)->where("u_state", 1)->find(); $p_user_id = ""; - if($is_p_user != null){ + if ($is_p_user != null) { $p_user_id = $is_p_user['u_id']; } Procurementxypencil::create([ 'user_id' => $user_id, 'u_id' => $p_user_id, - 'pencil_price' => round($order['total_amount']*$xy_set['s_content'],2), + 'pencil_price' => round($order['total_amount'] * $xy_set['s_content'], 2), 'order_id' => $order_id, 'create_time' => date("Y-m-d") ]); - $user_msg = User::where(['id' => $user_id])->find(); + $user_msg = User::where(['id' => $user_id])->find(); $orderGoods = (new OrderGoods())->alias('a') ->field(['a.w_price,a.set_id,a.p_id,d.trade_service_fee,d.city_id,d.province_id,a.firend_invite_code,a.id,a.shop_id,a.goods_id,a.goods_num,a.goods_price,a.total_price,a.total_pay_price,b.user_price_percent,b.user_shop_percent,b.third_percent,b.wholesale_percent,b.purchase_percent,b.issuing_percent,b.two_percent,b.city_shop_percent,b.pro_shop_percent,city_jicai_percent,pro_jicai_percent,c_ordinary_shop_percent,p_ordinary_shop_percent,caiji_percent']) ->where(['order_id' => $order_id]) ->join('goods b', 'b.id=a.goods_id') ->join('shop d', 'd.id=a.shop_id') ->select(); - foreach($orderGoods as $key=>$value){ - $is_d = Distribution::where('user_id', $user_msg['first_leader'] )->where('is_distribution', 1 )->find(); + foreach ($orderGoods as $key => $value) { + $is_d = Distribution::where('user_id', $user_msg['first_leader'])->where('is_distribution', 1)->find(); // 判断是否是集采会员 - if($value['p_id']>0){ - if($value['set_id']>0){ - $piw_price = $piw_price1=$percent = 0; - $p_user = Mprocurement::where("u_id",$value['p_id'])->where("u_state",1)->find(); - if($p_user!=null){ + if ($value['p_id'] > 0) { + if ($value['set_id'] > 0) { + $piw_price = $piw_price1 = $percent = 0; + $p_user = Mprocurement::where("u_id", $value['p_id'])->where("u_state", 1)->find(); + if ($p_user != null) { Procurementxypencil::create([ 'user_id' => $p_user['user_id'], 'u_id' => $value['p_id'], - 'pencil_price' => round($value['w_price']*$xy_set['s_content'],2), + 'pencil_price' => round($value['w_price'] * $xy_set['s_content'], 2), 'order_id' => $order_id, 'create_time' => date("Y-m-d") ]); - $set = Procurementset::where("set_id",$value['set_id'])->where("set_state",1)->find(); + $set = Procurementset::where("set_id", $value['set_id'])->where("set_state", 1)->find(); if ($set['set_pro'] != 0) { $percent = $value['purchase_percent']; if ($set['set_pro_type'] == 1) { - $piw_price1 = round($value['w_price']/(100+ $set['set_pro'])*100, 2); - $piw_price = round($piw_price1*$set['set_pro']/100,2); + $piw_price1 = round($value['w_price'] / (100 + $set['set_pro']) * 100, 2); + $piw_price = round($piw_price1 * $set['set_pro'] / 100, 2); } if ($set['set_pro_type'] == 3) { - $piw_price1 = round($value['w_price']-$set['set_pro'], 2); + $piw_price1 = round($value['w_price'] - $set['set_pro'], 2); $piw_price = round($set['set_pro'], 2); } } if ($set['set_issued'] != 0) { $percent = $value['issuing_percent']; if ($set['set_issued_type'] == 1) { - $piw_price1 = round($value['w_price']/(100+ $set['set_issued'])*100, 2); - $piw_price = round($piw_price1*$set['set_issued']/100,2); + $piw_price1 = round($value['w_price'] / (100 + $set['set_issued']) * 100, 2); + $piw_price = round($piw_price1 * $set['set_issued'] / 100, 2); } if ($set['set_issued_type'] == 3) { - $piw_price1 = round($value['w_price']-$set['set_issued'], 2); - $piw_price = round( $set['set_issued'], 2); + $piw_price1 = round($value['w_price'] - $set['set_issued'], 2); + $piw_price = round($set['set_issued'], 2); } } if ($set['set_wholesale'] != 0) { $percent = $value['wholesale_percent']; if ($set['set_wholesale_type'] == 1) { - $piw_price1 = round($value['w_price']/(100+ $set['set_wholesale'])*100, 2); - $piw_price = round($piw_price1*$set['set_wholesale']/100,2); + $piw_price1 = round($value['w_price'] / (100 + $set['set_wholesale']) * 100, 2); + $piw_price = round($piw_price1 * $set['set_wholesale'] / 100, 2); } if ($set['set_wholesale_type'] == 3) { - $piw_price1 = round($value['w_price']-$set['set_wholesale'], 2); + $piw_price1 = round($value['w_price'] - $set['set_wholesale'], 2); $piw_price = round($set['set_wholesale'], 2); } } // 集采收益 - if($piw_price > 0){ + if ($piw_price > 0) { // $earnings_buy = AccountLog::where('user_id', $p_user['user_id'])->order("create_time desc")->limit(1)->value('left_amount'); // $sn = createSn('account_log', 'log_sn', '', 4); // AccountLog::create([ @@ -2450,7 +2474,7 @@ class OrderLogic extends Logic // ]); // User::where("id",$p_user['user_id'])->inc("user_money",$piw_price)->update(); Order::where('id', $order_id) - ->inc('distribution_money',$piw_price)->update(); + ->inc('distribution_money', $piw_price)->update(); User::where('id', $p_user['user_id']) ->inc('earnings', $piw_price)->update(); $earnings_buy = AccountLog::where('user_id', $p_user['user_id'])->order("create_time desc")->limit(1)->value('left_amount'); @@ -2481,13 +2505,13 @@ class OrderLogic extends Logic ]); } // 上级推广者分佣抽成 - $user_first_msg = User::where('id', $p_user['user_id'] )->where('disable', 0 )->where('del', 0 )->find(); - if($user_first_msg!=null){ - $is_first_d = Distribution::where('user_id', $user_first_msg['first_leader'] )->where('is_distribution', 1 )->find(); - if($is_first_d!=null){ - $jicai = round($piw_price1 * $percent/100 * $value['caiji_percent'] / 100, 2); + $user_first_msg = User::where('id', $p_user['user_id'])->where('disable', 0)->where('del', 0)->find(); + if ($user_first_msg != null) { + $is_first_d = Distribution::where('user_id', $user_first_msg['first_leader'])->where('is_distribution', 1)->find(); + if ($is_first_d != null) { + $jicai = round($piw_price1 * $percent / 100 * $value['caiji_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$jicai)->update(); + ->inc('distribution_money', $jicai)->update(); // UserDistribution::where('user_id', $user_id) // ->inc('order_amount', $jicai)->update(); // UserDistribution::where('user_id', $user_id) @@ -2524,16 +2548,16 @@ class OrderLogic extends Logic } } // 推广者店铺收益 - $shop_user_msg = Shop::where('id', $value['shop_id'] )->find(); - if($shop_user_msg['reference_user_id'] != 0){ - $shop_u = Distribution::where('user_id', $shop_user_msg['reference_user_id'])->where('is_distribution', 1 )->find(); - if($shop_u!=null){ - $shop_percent = round($piw_price1 * $percent/100 * $value['third_percent'] / 100, 2); + $shop_user_msg = Shop::where('id', $value['shop_id'])->find(); + if ($shop_user_msg['reference_user_id'] != 0) { + $shop_u = Distribution::where('user_id', $shop_user_msg['reference_user_id'])->where('is_distribution', 1)->find(); + if ($shop_u != null) { + $shop_percent = round($piw_price1 * $percent / 100 * $value['third_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); - $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) + ->inc('distribution_money', $shop_percent)->update(); + $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) ->find(); - if($shopDistribution_msg == null){ + if ($shopDistribution_msg == null) { UserShopDistribution::create([ 'shop_id' => $value['shop_id'], 'order_num' => 1, @@ -2541,7 +2565,7 @@ class OrderLogic extends Logic 'create_time' => time(), 'update_time' => time() ]); - }else{ + } else { UserShopDistribution::where('shop_id', $value['shop_id']) ->inc('order_amount', $shop_percent)->update(); UserShopDistribution::where('shop_id', $value['shop_id']) @@ -2579,11 +2603,11 @@ class OrderLogic extends Logic } } // 推广者b端店铺收益 - $city_user_msg = Distributioncity::where('city_id', $value['city_id'] )->where("d_state",1)->find(); - if($city_user_msg != null){ - $shop_percent = round($piw_price1 * $percent/100 * $value['city_shop_percent'] / 100, 2); + $city_user_msg = Distributioncity::where('city_id', $value['city_id'])->where("d_state", 1)->find(); + if ($city_user_msg != null) { + $shop_percent = round($piw_price1 * $percent / 100 * $value['city_shop_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $city_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $city_user_msg['user_id']) @@ -2619,11 +2643,11 @@ class OrderLogic extends Logic } // 城市推广人 - $city_user_msg = Distributioncity::where('city_id', $value['city_id'] )->where("d_state",1)->where("d_type",2)->find(); - if($city_user_msg != null){ - $shop_percent = round($piw_price1 * $percent/100 * $value['city_shop_percent'] / 100, 2); + $city_user_msg = Distributioncity::where('city_id', $value['city_id'])->where("d_state", 1)->where("d_type", 2)->find(); + if ($city_user_msg != null) { + $shop_percent = round($piw_price1 * $percent / 100 * $value['city_shop_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $city_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $city_user_msg['user_id']) @@ -2659,11 +2683,11 @@ class OrderLogic extends Logic } // 城市推广b端商户 - $city_procurement_user_msg = Distributioncity::where('city_id', $p_user['city_id'] )->where("d_state",1)->where("d_type",2)->find(); - if($city_procurement_user_msg != null){ - $shop_percent = round($piw_price1 * $percent/100 * $value['city_jicai_percent'] / 100, 2); + $city_procurement_user_msg = Distributioncity::where('city_id', $p_user['city_id'])->where("d_state", 1)->where("d_type", 2)->find(); + if ($city_procurement_user_msg != null) { + $shop_percent = round($piw_price1 * $percent / 100 * $value['city_jicai_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $city_procurement_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $city_procurement_user_msg['user_id']) @@ -2699,11 +2723,11 @@ class OrderLogic extends Logic } // 省级推广人 - $province_user_msg = Distributioncity::where('province_id', $value['province_id'] )->where("d_state",1)->where("d_type",1)->find(); - if($province_user_msg != null){ - $shop_percent = round($piw_price1 * $percent/100* $value['pro_shop_percent'] / 100, 2); + $province_user_msg = Distributioncity::where('province_id', $value['province_id'])->where("d_state", 1)->where("d_type", 1)->find(); + if ($province_user_msg != null) { + $shop_percent = round($piw_price1 * $percent / 100 * $value['pro_shop_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $province_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $province_user_msg['user_id']) @@ -2739,11 +2763,11 @@ class OrderLogic extends Logic } // 省级推广b端商户 - $province_procurement_user_msg = Distributioncity::where('province_id', $p_user['province_id'] )->where("d_state",1)->where("d_type",1)->find(); - if($province_procurement_user_msg != null){ - $shop_percent = round($piw_price1 * $percent/100* $value['pro_jicai_percent'] / 100, 2); + $province_procurement_user_msg = Distributioncity::where('province_id', $p_user['province_id'])->where("d_state", 1)->where("d_type", 1)->find(); + if ($province_procurement_user_msg != null) { + $shop_percent = round($piw_price1 * $percent / 100 * $value['pro_jicai_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $province_procurement_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $province_procurement_user_msg['user_id']) @@ -2780,14 +2804,14 @@ class OrderLogic extends Logic } } - }else{ - trace('cheshi', $user_id.'-'.$user_msg['first_leader']); + } else { + trace('cheshi', $user_id . '-' . $user_msg['first_leader']); - if($is_d != null){ + if ($is_d != null) { // 推广收益 $first_leader_percent = round($value['total_pay_price'] * $value['user_price_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$first_leader_percent)->update(); + ->inc('distribution_money', $first_leader_percent)->update(); UserDistribution::where('user_id', $user_id) ->inc('order_amount', $first_leader_percent)->update(); UserDistribution::where('user_id', $user_id) @@ -2822,16 +2846,16 @@ class OrderLogic extends Logic ]); } // 推广者店铺收益 - $shop_user_msg = Shop::where('id', $value['shop_id'] )->find(); - if($shop_user_msg['reference_user_id'] != 0){ - $shop_u = Distribution::where('user_id', $shop_user_msg['reference_user_id'])->where('is_distribution', 1 )->find(); - if($shop_u!=null){ + $shop_user_msg = Shop::where('id', $value['shop_id'])->find(); + if ($shop_user_msg['reference_user_id'] != 0) { + $shop_u = Distribution::where('user_id', $shop_user_msg['reference_user_id'])->where('is_distribution', 1)->find(); + if ($shop_u != null) { $shop_percent = round($value['total_pay_price'] * $value['user_shop_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); - $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) + ->inc('distribution_money', $shop_percent)->update(); + $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) ->find(); - if($shopDistribution_msg == null){ + if ($shopDistribution_msg == null) { UserShopDistribution::create([ 'shop_id' => $value['shop_id'], 'order_num' => 1, @@ -2839,7 +2863,7 @@ class OrderLogic extends Logic 'create_time' => time(), 'update_time' => time() ]); - }else{ + } else { UserShopDistribution::where('shop_id', $value['shop_id']) ->inc('order_amount', $shop_percent)->update(); UserShopDistribution::where('shop_id', $value['shop_id']) @@ -2876,11 +2900,11 @@ class OrderLogic extends Logic } } // 城市推广人 - $city_user_msg = Distributioncity::where('city_id', $value['city_id'] )->where("d_type",2)->where("d_state",1)->find(); - if($city_user_msg != null){ + $city_user_msg = Distributioncity::where('city_id', $value['city_id'])->where("d_type", 2)->where("d_state", 1)->find(); + if ($city_user_msg != null) { $shop_percent = round($value['total_pay_price'] * $value['c_ordinary_shop_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $city_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $city_user_msg['user_id']) @@ -2916,11 +2940,11 @@ class OrderLogic extends Logic } // 省级推广人 - $province_user_msg = Distributioncity::where('province_id', $value['province_id'] )->where("d_type",1)->where("d_state",1)->find(); - if($province_user_msg != null){ + $province_user_msg = Distributioncity::where('province_id', $value['province_id'])->where("d_type", 1)->where("d_state", 1)->find(); + if ($province_user_msg != null) { $shop_percent = round($value['total_pay_price'] * $value['p_ordinary_shop_percent'] / 100, 2); Order::where('id', $order_id) - ->inc('distribution_money',$shop_percent)->update(); + ->inc('distribution_money', $shop_percent)->update(); UserDistribution::where('user_id', $province_user_msg['user_id']) ->inc('order_amount', $shop_percent)->update(); UserDistribution::where('user_id', $province_user_msg['user_id']) @@ -2986,9 +3010,16 @@ class OrderLogic extends Logic return JsonServer::error('订单无法删除'); } + if ($order['order_type'] == OrderEnum::GROUP_BUY && $order['order_status'] == OrderEnum::ORDER_STATUS_NO_PAID) { + $order_goods = OrderGoods::where('order_id', $order['id'])->find(); + GroupbuyGoods::where(['item_id' => $order_goods['item_id']])->inc('stock', $order['total_num'])->update(); + } + // $res = $order->save(['del' => 1, 'update_time' => time()]); $data = ['del' => 1, 'update_time' => time(), 'pat_status' => OrderEnum::ORDER_STATUS_DOWN]; $res = Order::update($data, ['id' => $order['id']]); + + OrderLogLogic::record( OrderLogEnum::TYPE_USER, OrderLogEnum::USER_DEL_ORDER, @@ -3006,27 +3037,27 @@ class OrderLogic extends Logic * @author suny * @date 2021/7/13 6:23 下午 */ - public static function pay_result($id,$from) + public static function pay_result($id, $from) { $total_a = 0; switch ($from) { case 'trade' : //如果是父订单类型下单,$id为父订单id $result = OrderTrade::alias('ot') - ->where(['ot.id' => $id,'o.pay_status' => 1]) - ->join('order o','o.trade_id = ot.id') - ->field(['ot.id', 'ot.t_sn as order_sn','o.goods_price','o.total_num','o.user_id', 'o.pay_time', 'o.pay_way', 'ot.total_amount']) + ->where(['ot.id' => $id, 'o.pay_status' => 1]) + ->join('order o', 'o.trade_id = ot.id') + ->field(['ot.id', 'ot.t_sn as order_sn', 'o.goods_price', 'o.total_num', 'o.user_id', 'o.pay_time', 'o.pay_way', 'ot.total_amount']) ->findOrEmpty() ->toArray(); $total_a = $result['total_amount']; $result['total_amount'] = '¥' . $result['total_amount']; $oid = ""; - $ord = Order::where("trade_id",$id)->select(); + $ord = Order::where("trade_id", $id)->select(); $id = $ord[0]['id']; break; case 'order' : //如果是子订单类型下单,$id为子订单id $result = Order::where(['id' => $id]) - ->field(['id', 'order_sn', 'pay_time','goods_price','total_num','p_id','user_id', 'pay_way', 'total_amount']) + ->field(['id', 'order_sn', 'pay_time', 'goods_price', 'total_num', 'p_id', 'user_id', 'pay_way', 'total_amount']) ->findOrEmpty() ->toArray(); $total_a = $result['total_amount']; @@ -3036,7 +3067,7 @@ class OrderLogic extends Logic case 'integral': $result = IntegralOrder::where(['id' => $id]) - ->field(['id', 'order_sn', 'pay_time','goods_price','total_num','p_id','user_id', 'pay_way', 'order_amount', 'order_integral', 'exchange_way']) + ->field(['id', 'order_sn', 'pay_time', 'goods_price', 'total_num', 'p_id', 'user_id', 'pay_way', 'order_amount', 'order_integral', 'exchange_way']) ->findOrEmpty()->toArray(); $oid = $result['id']; $total_a = $result['total_amount']; @@ -3053,15 +3084,15 @@ class OrderLogic extends Logic $r = $order ->with(['user', 'order_goods', 'invoice']) ->where('id', $id) - ->append(['delivery_address','goods_id', 'order_id','user_id']) + ->append(['delivery_address', 'goods_id', 'order_id', 'user_id']) ->find(); - $user_msg = UserAddress::where("user_id",$r['user_id'])->where("is_default",1)->find(); - $goods_msg = OrderGoods::where("order_id",$id)->select(); - foreach($goods_msg as $key=>$value){ - $goods_user = Goodscontact::where("goods_id",$value['goods_id'])->where("gzhuser_state",1)->select(); + $user_msg = UserAddress::where("user_id", $r['user_id'])->where("is_default", 1)->find(); + $goods_msg = OrderGoods::where("order_id", $id)->select(); + foreach ($goods_msg as $key => $value) { + $goods_user = Goodscontact::where("goods_id", $value['goods_id'])->where("gzhuser_state", 1)->select(); $goods_msg[$key]['goodscontact'] = $goods_user; } - $getToken->getToken($r['delivery_address'],$user_msg,$goods_msg); + $getToken->getToken($r['delivery_address'], $user_msg, $goods_msg); $result['pay_time'] = date('Y-m-d H:i:s', $result['pay_time']); $result['pay_way'] = PayEnum::getPayWay($result['pay_way']); return $result; @@ -3110,7 +3141,7 @@ class OrderLogic extends Logic $user_money = Db::name('user')->where(['id' => $user_id])->value('user_money'); $item['extra'] = '可用余额:' . $user_money; $item['pay_way'] = PayEnum::BALANCE_PAY; - if($params['from'] == 'recharge' || $order->billions_type == 1) { + if ($params['from'] == 'recharge' || $order->billions_type == 1) { unset($payway[$k]); } @@ -3128,12 +3159,12 @@ class OrderLogic extends Logic } } if ($item['code'] == 'xiny') { - $xy_price = Procurementxy::where("user_id",$user_id)->where('xy_state',1)->find(); - if($xy_price == null){ + $xy_price = Procurementxy::where("user_id", $user_id)->where('xy_state', 1)->find(); + if ($xy_price == null) { $item['extra'] = '暂无额度,无法使用'; - }elseif($xy_price['xy_y_state']==0){ + } elseif ($xy_price['xy_y_state'] == 0) { $item['extra'] = '可用信用额度:' . $xy_price['xy_price']; - }else{ + } else { $item['extra'] = '已使用额度,请先归回在使用'; unset($payway[$k]); } @@ -3141,17 +3172,17 @@ class OrderLogic extends Logic } } - if($params['from'] == 'order') { + if ($params['from'] == 'order') { $order = Order::findOrEmpty($params['order_id']); - } else if($params['from'] == 'trade') { + } else if ($params['from'] == 'trade') { $order = OrderTrade::findOrEmpty($params['order_id']); - } else if($params['from'] == 'integral') { + } else if ($params['from'] == 'integral') { $order = IntegralOrder::findOrEmpty($params['order_id']); } else { $order = RechargeOrder::findOrEmpty($params['order_id']); } $cancelTime = ConfigServer::get('transaction', 'unpaid_order_cancel_time', 60); - if(empty($cancelTime) || $params['from'] == 'integral') { + if (empty($cancelTime) || $params['from'] == 'integral') { $cancelTime = 0; } else { $cancelTime = strtotime($order['create_time']) + intval($cancelTime) * 60; @@ -3229,8 +3260,8 @@ class OrderLogic extends Logic $shipping_code = Db::name('express')->where(['id' => $order_delivery['shipping_id']])->value($shipping_field); //获取物流轨迹 if ($shipping_code === 'SF' && $express === 'kdniao') { - $expressage->logistics($shipping_code, $order_delivery['invoice_no'], substr($order_delivery['mobile'],-4)); - }else { + $expressage->logistics($shipping_code, $order_delivery['invoice_no'], substr($order_delivery['mobile'], -4)); + } else { $phone = ''; if ($shipping_code === 'shunfeng') { $phone = $order['mobile']; @@ -3243,13 +3274,13 @@ class OrderLogic extends Logic //获取不到物流轨迹时 if ($traces == false) { $error = $expressage->getError(); - $error = json_decode($error,true); + $error = json_decode($error, true); if ($express === 'kdniao') { - if($error['Success'] == false){ + if ($error['Success'] == false) { $traces[] = [$error['Reason']]; } } else { - if($error['result'] == false){ + if ($error['result'] == false) { $traces[] = [$error['message']]; } } @@ -3402,23 +3433,23 @@ class OrderLogic extends Logic } } - public static function getPayStatus($id,$from) + public static function getPayStatus($id, $from) { - switch ($from){ + switch ($from) { case 'trade' : //如果是父订单类型下单,$id为父订单id $order_trade = OrderTrade::alias('ot') ->where(['ot.id' => $id]) - ->join('order o','o.trade_id = ot.id') - ->field(['ot.id','o.id as order_id', 'ot.t_sn as order_sn', 'o.pay_time', 'o.pay_way', 'ot.total_amount','o.pay_status','o.order_status']) + ->join('order o', 'o.trade_id = ot.id') + ->field(['ot.id', 'o.id as order_id', 'ot.t_sn as order_sn', 'o.pay_time', 'o.pay_way', 'ot.total_amount', 'o.pay_status', 'o.order_status']) ->select() ->toArray(); foreach ($order_trade as $item) { - if($item['pay_time']){ + if ($item['pay_time']) { $item['pay_time'] = date('Y-m-d H:i:s', $item['pay_time']); } $create_time = Db::name('order')->where(['id' => $item['order_id']])->value('create_time'); - $unpaid_order_cancel_time = ConfigServer::get('transaction','unpaid_order_cancel_time',60); + $unpaid_order_cancel_time = ConfigServer::get('transaction', 'unpaid_order_cancel_time', 60); $cancel_time = $create_time + $unpaid_order_cancel_time * 60; $item['pay_status_text'] = PayEnum::getPayStatus($item['pay_status']); $result = $item; @@ -3453,12 +3484,12 @@ class OrderLogic extends Logic case 'order' : //如果是子订单类型下单,$id为子订单id $result = Order::where(['id' => $id]) - ->field(['id', 'order_sn', 'pay_time', 'pay_way', 'total_amount','consignee','mobile','province','city','district','address','pay_status','order_status']) + ->field(['id', 'order_sn', 'pay_time', 'pay_way', 'total_amount', 'consignee', 'mobile', 'province', 'city', 'district', 'address', 'pay_status', 'order_status']) ->findOrEmpty() ->append(['pc_address']) ->toArray(); $create_time = Db::name('order')->where(['id' => $id])->value('create_time'); - $unpaid_order_cancel_time = ConfigServer::get('transaction','unpaid_order_cancel_time',60); + $unpaid_order_cancel_time = ConfigServer::get('transaction', 'unpaid_order_cancel_time', 60); $cancel_time = $create_time + $unpaid_order_cancel_time * 60; $order_goods = Db::name('order_goods') ->where(['order_id' => $result['id']]) @@ -3476,7 +3507,7 @@ class OrderLogic extends Logic $result['order_goods'] = $order_goods; $result['address'] = $address; $result['cancel_time'] = $cancel_time; - if($result['pay_time']){ + if ($result['pay_time']) { $result['pay_time'] = date('Y-m-d H:i:s', $result['pay_time']); } break; @@ -3537,8 +3568,8 @@ class OrderLogic extends Logic $shipping_code = Db::name('express')->where(['id' => $order_delivery['shipping_id']])->value($shipping_field); //获取物流轨迹 if ($shipping_code === 'SF' && $express === 'kdniao') { - $expressage->logistics($shipping_code, $order_delivery['invoice_no'], substr($order_delivery['mobile'],-4)); - }else { + $expressage->logistics($shipping_code, $order_delivery['invoice_no'], substr($order_delivery['mobile'], -4)); + } else { $phone = ''; if ($shipping_code === 'shunfeng') { $phone = $order['mobile']; @@ -3551,13 +3582,13 @@ class OrderLogic extends Logic //获取不到物流轨迹时 if ($traces == false) { $error = $expressage->getError(); - $error = json_decode($error,true); + $error = json_decode($error, true); if ($express === 'kdniao') { - if($error['Success'] == false){ + if ($error['Success'] == false) { $traces[] = [$error['Reason']]; } } else { - if($error['result'] == false){ + if ($error['result'] == false) { $traces[] = [$error['message']]; } }