diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index 74793c39..0191ffca 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -64,6 +64,10 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists ->toArray(); $off_activity = Config::where('name', 'off_activity')->value('value'); $this->off_activity=$off_activity; + $user_ship = User::where('id', $userId)->value('user_ship'); + if (in_array($user_ship, [4, 5, 6, 7])) { + $off_activity=1; + } foreach ($list as $key => &$item) { $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) ->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price') diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index a1e9531f..a6eb8483 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -3,7 +3,7 @@ namespace app\api\lists\product; -use app\admin\lists\BaseAdminDataLists; +use app\api\lists\BaseApiDataLists; use app\common\lists\ListsExtendInterface; use app\common\lists\ListsSortInterface; use app\common\model\dict\DictType; @@ -12,6 +12,7 @@ use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; use app\common\model\cate\Cate; use app\common\model\Config; +use app\common\model\user\User; //use app\common\model\goods\GoodsLabel; use think\facade\Db; @@ -20,7 +21,7 @@ use think\facade\Db; * Class goods * @package app\api\goods */ -class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface +class ProductLists extends BaseApiDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface { @@ -33,10 +34,9 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L public function setSearch(): array { return [ - '=' => ['store_id', 'cate_id','top_cate_id','two_cate_id'], + '=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'], ]; - } /** * @notes 设置支持排序字段 @@ -71,28 +71,17 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L */ public function lists(): array { -// $class_all = $this->request->get('class_all'); -// if ($class_all) { -// //查3级别的 -// $arr = Cate::where('pid', $class_all)->column('id'); -// if ($arr) { -// $arr2 = Cate::where('pid', 'in', $arr)->column('id'); -// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; -// } else { -// $this->searchWhere[] = ['cate_id', '=', $class_all]; -// } -// } - $order = $this->request->get('order',''); - $field = $this->request->get('field',''); - if(empty($order)||empty($field)){ + $order = $this->request->get('order', ''); + $field = $this->request->get('field', ''); + if (empty($order) || empty($field)) { $order = $this->sortOrder; - }else{ + } else { $order = [$field => $order]; } $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $this->searchWhere[] = ['status', '=', 1]; -// $this->searchWhere[] = ['stock', '>', 0]; + // $this->searchWhere[] = ['stock', '>', 0]; return StoreBranchProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) @@ -116,20 +105,26 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L } public function extend() { -// $off_activity = Config::where('name', 'off_activity')->value('value'); -// if($off_activity==1){ -// $data=[ -// 'off_activity' => $off_activity, -// 'price' => 'cost', -// 'op_price' => 'price', -// ]; -// }else{ - $data=[ - 'off_activity' => 0, - 'price' => 'price', - 'op_price' => 'price', - ]; -// } + $price = 'price'; + $op_price = 'price'; + $off_activity = 0; + if ($this->userId > 0) { + $user_ship = User::where('id', $this->userId)->value('user_ship'); + if (in_array($user_ship, [4, 5, 6, 7])) { + $price = 'cost'; + $op_price = 'price'; + } + } + $off_activity = Config::where('name', 'off_activity')->value('value'); + if ($off_activity == 1) { + $price = 'cost'; + $op_price = 'price'; + } + $data = [ + 'off_activity' => $off_activity, + 'price' => $price, + 'op_price' => $op_price, + ]; return $data; } } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 28015efd..73286c78 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -55,7 +55,7 @@ class OrderLogic extends BaseLogic public static $store_price; //门店零售价 public static $activity_price; public static $deduction_price; - public static $frozen_money;//返还金额 + public static $frozen_money; //返还金额 /** * @notes 获取购物车商品信息 @@ -77,8 +77,8 @@ class OrderLogic extends BaseLogic self::$profit = 0; //利润 self::$activity_price = 0; //活动减少 self::$store_price = 0; //商户价 - self::$deduction_price =0; - self::$frozen_money =0;//返还金额 + self::$deduction_price = 0; + self::$frozen_money = 0; //返还金额 $deduction_price = 0; //抵扣金额 /** 计算价格 */ $off_activity = Config::where('name', 'off_activity')->value('value'); @@ -86,23 +86,27 @@ class OrderLogic extends BaseLogic foreach ($cart_select as $k => $v) { $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->withTrashed()->find(); if (!$find) { -// unset($cart_select[$k]); -// continue; + // unset($cart_select[$k]); + // continue; $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id'; $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->withTrashed()->find(); - $cart_select[$k]['status'] = 1;//缺货标识 + $cart_select[$k]['status'] = 1; //缺货标识 } unset($cart_select[$k]['id']); $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 -// if ($off_activity == 1) { -// $price = $find['cost']; -// } else { - $price = $find['price']; -// } + if ($off_activity == 1) { + $price = $find['cost']; + } else { + if ($user && in_array($user['user_ship'], [4, 5, 6, 7])) { + $price = 'cost'; + } else { + $price = $find['price']; + } + } $cart_select[$k]['price'] = $price; $cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['vip'] = 0; - $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name')??''; //单位名称 + $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称 //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 @@ -110,23 +114,23 @@ class OrderLogic extends BaseLogic $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $price, 2); //订单支付金额 $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //商户价 $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2) ?? 0; //vip售价 - if($cart_select[$k]['total_price']>$cart_select[$k]['pay_price']){ - $deduction_price=bcsub($cart_select[$k]['total_price'],$cart_select[$k]['pay_price'],2); - $cart_select[$k]['deduction_price'] =$deduction_price;//抵扣金额 + if ($cart_select[$k]['total_price'] > $cart_select[$k]['pay_price']) { + $deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2); + $cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额 } $cart_select[$k]['product_id'] = $find['product_id']; $cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; - $cart_select[$k]['vip_frozen_price']=0; + $cart_select[$k]['vip_frozen_price'] = 0; //会员待返回金额 - if ($user && $off_activity==0){ - if($user['user_ship']==4){ + if ($user && $off_activity == 0) { + if ($user['user_ship'] == 4) { //商户 $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['store_price'], 2); - }else{ + } else { //其他会员 - $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'], 2); + $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['vip_price'], 2); } } // d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] ); @@ -144,8 +148,8 @@ class OrderLogic extends BaseLogic self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价 - self::$deduction_price=bcadd(self::$deduction_price,$deduction_price,2);//抵扣金额 - self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2);//返还金额 + self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额 + self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额 // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); } //加支付方式限制 @@ -153,7 +157,7 @@ class OrderLogic extends BaseLogic // if ($user && $user['user_ship'] == 1 && $pay_type != 17) { // $pay_price = self::$pay_price; // } else { - $pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 + $pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 // } //成本价 收益 $order = [ @@ -173,7 +177,7 @@ class OrderLogic extends BaseLogic 'activity_price' => self::$activity_price, 'activities' => self::$activity_price > 0 ? 1 : 0, 'deduction_price' => self::$deduction_price, - 'frozen_money' => self::$frozen_money,//返还金额(活动关闭得时候有) + 'frozen_money' => self::$frozen_money, //返还金额(活动关闭得时候有) 'source' => 0, 'is_storage' => $params['is_storage'] ?? 0, ]; @@ -186,18 +190,18 @@ class OrderLogic extends BaseLogic } //处理返回最近的店铺 $store_check = 0; - if(empty($user)){ + if (empty($user)) { $store_id = getenv('STORE_ID') ?? 1; - $store['near_store'] =SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find()??[]; - }else{ - $checkOrderStore = StoreOrder::where('uid',$user['id'])->field('id,store_id') - ->order('id','desc')->find(); - if($checkOrderStore){ - $store['near_store'] =SystemStore::where('id', $checkOrderStore['store_id'])->field('id,name,phone,address,detailed_address,latitude,longitude')->find()??[]; + $store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? []; + } else { + $checkOrderStore = StoreOrder::where('uid', $user['id'])->field('id,store_id') + ->order('id', 'desc')->find(); + if ($checkOrderStore) { + $store['near_store'] = SystemStore::where('id', $checkOrderStore['store_id'])->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? []; $store_check = 1; - }else{ + } else { $store_id = getenv('STORE_ID') ?? 1; - $store['near_store'] =SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find()??[]; + $store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? []; } } if (empty($store_check)) { @@ -212,7 +216,7 @@ class OrderLogic extends BaseLogic $nearestStore = $value; } } - $store['near_store'] =[]; + $store['near_store'] = []; if ($nearestStore) { $store['near_store'] = $nearestStore; } @@ -281,10 +285,10 @@ class OrderLogic extends BaseLogic $goods_list[$k]['uid'] = $uid; $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(); -// if ($StoreBranchProduct['stock'] - $v['cart_num'] <= 0) { -// Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]); -// } + // $StoreBranchProduct = StoreBranchProduct::where('id', $v['branch_product_id'])->withTrashed()->find(); + // if ($StoreBranchProduct['stock'] - $v['cart_num'] <= 0) { + // Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]); + // } } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; @@ -451,7 +455,7 @@ class OrderLogic extends BaseLogic $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { $find = StoreBranchProduct::where('product_id', $item['product_id'])->where('store_id', $find['store_id'])->find(); - if(empty($find)){ + if (empty($find)) { $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); } $item['store_name'] = $find['store_name']; @@ -534,7 +538,8 @@ class OrderLogic extends BaseLogic (new StoreProductLog())->update( [ 'store_id' => $params['store_id'] - ], ['oid' => $order['id']] + ], + ['oid' => $order['id']] ); (new StoreOrderCartInfo())->update([ 'verify_code' => $params['verify_code'] . '-1', @@ -563,7 +568,7 @@ class OrderLogic extends BaseLogic $money = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 2])->value('number') ?? 0; $financeFlowLogic->updateStatusStore($order['id'], $order['store_id'], $money, $deposit); //积分结算 - if($order['is_storage']==0&&$order['source']==0){ + if ($order['is_storage'] == 0 && $order['source'] == 0) { UserSignLogic::WriteOff($order); } Db::commit(); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 4315fcce..8e204b1f 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -588,7 +588,7 @@ class PayNotifyLogic extends BaseLogic } //积分写入 - if(in_array($order['pay_type'],[3,7,9,13,17])&&$order['uid']>0){ + if(isset($user) && $user['user_ship']==0){ UserSignLogic::OrderWrite($order); } if ($off_activity == 1) { @@ -644,10 +644,10 @@ class PayNotifyLogic extends BaseLogic } switch ($user_ship) { case 1: // 厨师 - case 4: // 商户 - case 5: // 种养殖 - case 6: // 酒店 - case 7: // 食堂 + //case 4: // 商户 + //case 5: // 种养殖 + // case 6: // 酒店 + // case 7: // 食堂 case 8: // 一条龙 CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id); break;