diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index b49a93c92..26cb5fdf1 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -36,15 +36,15 @@ class StoreProductLogic extends BaseLogic */ public static function add(array $params): bool { - $count=count($params['cate_arr']); - $top_cate_id=0; - $two_cate_id=0; - if($count==3){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][1]; - }elseif($count==2){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][0]; + $count = count($params['cate_arr']); + $top_cate_id = 0; + $two_cate_id = 0; + if ($count == 3) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][1]; + } elseif ($count == 2) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][0]; } Db::startTrans(); try { @@ -71,12 +71,15 @@ class StoreProductLogic extends BaseLogic 'product_type' => $params['product_type'] ?? 0, 'is_show' => $params['is_show'] ?? 0, ]; - // if ($params['rose'] > 0) { - // $rose_price = bcmul($params['cost'], $params['rose'], 2); - // $data['price'] = bcadd($params['cost'], $rose_price, 2); - // } else { - // $data['price'] = 0; - // } + $rose = 0; + //零售-供货 + $rose_price = bcsub($params['price'], $params['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $params['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $data['rose']=$rose; $res = StoreProduct::create($data); $arr=[]; foreach($params['product_arr'] as $k=>$v){ @@ -90,7 +93,7 @@ class StoreProductLogic extends BaseLogic } (new StoreProductAttrValue())->saveAll($arr); Db::commit(); - if($data['product_type']==5){ + if ($data['product_type'] == 5) { return true; } if ($params['is_store_all'] == 1) { @@ -116,7 +119,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - throw new BusinessException('添加商品失败'.$e->getMessage()); + throw new BusinessException('添加商品失败' . $e->getMessage()); } } @@ -185,15 +188,15 @@ class StoreProductLogic extends BaseLogic { Db::startTrans(); try { - $count=count($params['cate_arr']); - $top_cate_id=0; - $two_cate_id=0; - if($count==3){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][1]; - }elseif($count==2){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][0]; + $count = count($params['cate_arr']); + $top_cate_id = 0; + $two_cate_id = 0; + if ($count == 3) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][1]; + } elseif ($count == 2) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][0]; } $data = [ 'store_name' => $params['store_name'], @@ -207,7 +210,6 @@ class StoreProductLogic extends BaseLogic 'stock' => $params['stock'], 'cost' => $params['cost'], 'purchase' => $params['purchase'], - 'rose' => $params['rose'], 'is_return' => $params['is_return'], 'price' => $params['price'], 'vip_price' => $params['vip_price'], @@ -217,12 +219,20 @@ class StoreProductLogic extends BaseLogic 'swap' => $params['swap'] ?? 0, 'is_show' => $params['is_show'] ?? 0, ]; - - StoreProduct::update($data,['id'=>$params['id']]); + $rose = 0; + //零售-供货 + $rose_price = bcsub($params['price'], $params['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $params['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $data['rose']=$rose; + StoreProduct::update($data, ['id' => $params['id']]); // $dealCate = self::dealChangeCate($params['cate_id']); //修改 - StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id',[17,18])->update([ + StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id', [17, 18])->update([ 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'cost' => $params['cost'], @@ -237,7 +247,7 @@ class StoreProductLogic extends BaseLogic 'cate_id' => $params['cate_id'], 'bar_code' => $params['bar_code'], 'purchase' => $params['purchase'], - 'rose' => $params['rose'] ?? 0, + 'rose' => $rose, 'status' => $params['is_show'] ?? 0, 'image' => $params['image'], 'store_batch' => $params['store_batch'] ?? 1, @@ -248,8 +258,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - throw new BusinessException('编辑商品失败'.$e->getMessage()); - + throw new BusinessException('编辑商品失败' . $e->getMessage()); } } @@ -308,8 +317,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - throw new BusinessException('删除失败'.$e->getMessage()); - + throw new BusinessException('删除失败' . $e->getMessage()); } } @@ -317,8 +325,8 @@ class StoreProductLogic extends BaseLogic /**普通 */ public static function ordinary($product_arr, $store_id, $admin_id, $find) { - $res=StoreBranchProduct::where('store_id',$store_id)->where('product_id',$find['id'])->find(); - if($res){ + $res = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $find['id'])->find(); + if ($res) { return $res; } $dealCate = self::dealChangeCate($find['cate_id']); @@ -388,7 +396,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - throw new BusinessException('添加兑换商品失败'.$e->getMessage()); + throw new BusinessException('添加兑换商品失败' . $e->getMessage()); } } // else { diff --git a/app/common/logic/CommissionProductLogic22.php b/app/common/logic/CommissionProductLogic22.php new file mode 100644 index 000000000..46a95dca2 --- /dev/null +++ b/app/common/logic/CommissionProductLogic22.php @@ -0,0 +1,359 @@ +find(); + if ($product) { + //活动商品 + if ($product['product_type'] == 4) { + $this->c($find, $order, $product); + return true; + } else { + //种养殖用户判断 + if ($user_ship == 5) { + $top_cate_id = $product['top_cate_id']; + if ($top_cate_id == 15189) { + $this->b($find, $order, $product, $user_ship); + return true; + }else{ + $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + return true; + } + } elseif ($user_ship == 0||$user_ship == 4) { + //普通用户利润全部给门店 + $this->b($find, $order, $product, $user_ship); + return true; + } else { + //会员用户入口 + $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + return true; + } + } + } + return false; + } + + /** + * 零售价结算 + */ + public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) + { + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['price']; + + $platform_number = 0; //平台 + $attrition_number = 0; //损耗 + $store_number = 0; //门店 + $number1 = 0; //其他 + + + if ($product['rose'] >= 6) { + $platform_number = bcmul($total_price, 0.02, 2); //平台 + } + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + //会员 + $uid = 0; + if ($order['spread_uid'] > 0) { + $uid = $order['spread_uid']; + } + if ($order['uid'] > 0) { + $uid = $order['uid']; + } + $user = User::where('id', $uid)->find(); + + if ($user) { + if ($user['user_ship'] == 2) { + $village_number = bcmul($total_price, 0.04, 2); //村长利润 + $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.04); + $number1 = bcadd($number1, $village_number, 2); + if ($product['rose'] >= 12) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); + } + } elseif ($user['user_ship'] == 3) { + $brigade_number = bcmul($total_price, 0.04, 2); //队长利润 + $data[] = $this->brigade('零售队长', $order, $find, $brigade_uid, $price, $total_price, $brigade_number,0.04); + $number1 = bcadd($number1, $brigade_number, 2); + if ($product['rose'] >= 12 && $village_uid>0) { + $village_number = bcmul($total_price, 0.01, 2); //村长利润 + $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); + $number1 = bcadd($number1, $village_number, 2); + } + if ($product['rose'] >= 15) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); + } + } elseif ($user['user_ship'] == 1) { + $vip_number = bcmul($total_price, 0.06, 2); //会员利润 + $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); + $number1 = bcadd($number1, $vip_number, 2); + if ($product['rose'] >= 12 && $village_uid>0) { + $village_number = bcmul($total_price, 0.01, 2); //村长利润 + $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); + $number1 = bcadd($number1, $village_number, 2); + } + if ($product['rose'] >= 14 && $brigade_uid>0) { + $brigade_number = bcmul($total_price, 0.01, 2); //队长利润 + $data[] =$this->village('零售队长', $order, $find, $village_uid, $price, $total_price, $brigade_number,0.01); + $number1 = bcadd($number1, $brigade_number, 2); + } + if ($product['rose'] >= 15) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); + } + } + } + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $number2 = bcadd($platform_number, $attrition_number, 2); + $store_number = bcsub($number3, bcadd($number1, $number2,2), 2); + } + //门店 + $rate=0; + if($store_number>0){ + $rate=bcdiv($store_number,$total_price,2); + } + $data[] =$this->store('零售门店', $order, $find, $price, $total_price,$store_number,$rate); + //平台 + if ($product['rose'] >= 6) { + $data[] = $this->platform('零售平台', $order, $find, $price, $total_price,$platform_number); + } + + (new StoreFinanceFlowProduct())->saveAll($data); + } + + /** + * 商户价结算 + */ + public function b($find, $order, $product, $user_ship) + { + $total_price = bcmul($product['cost'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['cost']; + + $platform_number = 0; + $attrition_number = 0; + if ($product['rose'] >= 6) { + $platform_number = bcmul($total_price, 0.02, 2); //平台 + } + if ($product['rose'] >= 10) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + } + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, bcadd($platform_number, $attrition_number, 2), 2); + } + //门店 + $rate=0; + if($store_number>0){ + $rate=bcdiv($store_number,$total_price,2); + } + $data[] =$this->store('商户价门店',$order,$find,$price,$total_price,$store_number,$rate); + //平台 + if ($product['rose'] >= 6) { + $data[] =$this->platform('商户价平台',$order,$find,$price,$total_price,$platform_number); + } + if ($product['rose'] >= 12) { + $data[] = $this->attrition('商户价损耗',$order,$find,$price,$total_price,$attrition_number); + } + (new StoreFinanceFlowProduct())->saveAll($data); + } + + //活动商品结算 + public function c($find, $order,$product) + { + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['purchase']; + + $platform_number = 0; + $attrition_number = 0; + if ($product['rose'] >= 6) { + $platform_number = bcmul($total_price, 0.02, 2); //平台 + } + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, bcadd($platform_number, $attrition_number, 2), 2); + } + //门店 + $rate=0; + if($store_number>0){ + $rate=bcdiv($store_number,$total_price,2); + } + $data[] =$this->store('商户价门店',$order,$find,$price,$total_price,$store_number,$rate,1); + //平台 + if ($product['rose'] >= 6) { + $data[] =$this->platform('商户价平台',$order,$find,$price,$total_price,$platform_number,1); + } + (new StoreFinanceFlowProduct())->saveAll($data); + } + + /** + * 村长 + */ + public function village($name, $order, $find, $other_uid, $price, $total_price, $number, $rate = 0.01, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $other_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => 0, + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 队长 + */ + public function brigade($name, $order, $find, $other_uid, $price, $total_price, $number, $rate = 0.01, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $other_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 平台 + */ + public function platform($name, $order, $find, $price, $total_price, $number, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 门店 + */ + public function store($name, $order, $find, $price, $total_price, $number,$rate = 0.05, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 损耗 + */ + public function attrition($name, $order, $find, $price, $total_price, $number, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 6, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + + /** + * 会员 + */ + public function vip_user($name, $order, $find, $other_uid,$price, $total_price, $number,$rate = 0.06, $is_activity = 0){ + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $other_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => $is_activity, + ]; + return $data; + } +} diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index d3da5fd75..44b9ae9b1 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -10,56 +10,6 @@ use app\common\model\user\UserAddress; class CommissionnLogic extends BaseLogic { - /** - * 走村长分润 - */ - public static function setVillage($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) - { - self::user($order, 3, $transaction_id, $village_uid, 14); //村长 - self::user($order, 0, $transaction_id, 0, 12); //会员、厨师 - self::user($order, 5, $transaction_id, 0, 20); //个人店铺 - self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长 - - self::platform($order, 2, $transaction_id); //平台 - self::store($order, 1, $transaction_id, 0); //门店 - // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 - self::suppliter($order, $transaction_id); - } - /** - * 走队长分润 - */ - public static function setBrigade($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) - { - self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长 - self::user($order, 0, $transaction_id, 0, 12); ////会员、厨师 - self::user($order, 5, $transaction_id, 0, 20); ////会员、厨师 - self::user($order, 3, $transaction_id, $village_uid, 14); //村长 - - self::platform($order, 2, $transaction_id); //平台 - self::store($order, 1, $transaction_id, 0); //门店 - // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 - self::suppliter($order, $transaction_id); - } - /** - * 走厨师分润 - */ - public static function setCook($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) - { - if ($order['spread_uid'] <= 0) { - $uid = $order['uid']; - } else { - $uid = $order['spread_uid']; - } - self::user($order, 0, $transaction_id, $uid, 12); //会员、厨师 - self::user($order, 5, $transaction_id, $uid, 20); //会员、厨师 - self::user($order, 3, $transaction_id, $village_uid, 14); //村长 - self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长 - self::platform($order, 2, $transaction_id); //平台 - self::store($order, 1, $transaction_id, 0); //门店 - // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 - // $moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, 0, 2), 2); - self::suppliter($order, $transaction_id); - } /** * 零售分润 diff --git a/app/common/model/finance/CapitalFlow.php b/app/common/model/finance/CapitalFlow.php index 08d68441c..c21929d67 100644 --- a/app/common/model/finance/CapitalFlow.php +++ b/app/common/model/finance/CapitalFlow.php @@ -3,8 +3,11 @@ namespace app\common\model\finance; use app\common\model\BaseModel; +use think\model\concern\SoftDelete; class CapitalFlow extends BaseModel { + use SoftDelete; + protected $deleteTime = 'delete_time'; } diff --git a/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php b/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php index a1d1ff1a5..9681a66a6 100644 --- a/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php +++ b/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php @@ -45,7 +45,7 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc { $this->searchWhere[]=['store_id','=',$this->adminInfo['store_id']]; return StoreCashFinanceFlow::where($this->searchWhere) - ->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark', 'status']) + ->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file','create_time', 'remark', 'status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { diff --git a/process/Task.php b/process/Task.php index a25bda15f..198660c65 100644 --- a/process/Task.php +++ b/process/Task.php @@ -23,7 +23,7 @@ class Task new Crontab('0 */10 * * * *', function () { $where = ['paid' => 0]; $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 - $where[] = ['source', '<',2]; + $where[] = ['source', '<=',1]; // 删除10分钟未支付的订单 $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 if ($oid) { @@ -39,17 +39,6 @@ class Task //删除未充值的订单 UserRecharge::where('paid', 0)->where('status', 1)->where('create_time', '<', $oneHourAgo)->update(['delete_time' => time()]); }); - - new Crontab('0 */1 * * * *', function () { - $endTime = time(); - - // 计算10分钟前的时间戳 - $startTime = $endTime - 10 * 60; - $arr = UserRecharge::where('paid', 0)->where('status', 1)->whereBetweenTime('create_time', $startTime, $endTime)->column('order_id'); - foreach ($arr as $v) { - Redis::send('task-recharge-query', ['order_id' => $v]); - } - }); //每10秒执行一次 new Crontab('*/10 * * * * *', function () { $select=Db::name('wechat_micropay')->limit(100)->select();