diff --git a/app/admin/controller/store_branch_product/StoreBranchProductController.php b/app/admin/controller/store_branch_product/StoreBranchProductController.php index 8b97950eb..396b512ce 100644 --- a/app/admin/controller/store_branch_product/StoreBranchProductController.php +++ b/app/admin/controller/store_branch_product/StoreBranchProductController.php @@ -114,7 +114,7 @@ class StoreBranchProductController extends BaseAdminController public function delete() { $params = (new StoreProductValidate())->post()->goCheck('delete'); - StoreProductLogic::delete($params); + StoreBranchProductLogic::delete($params); return $this->success('删除成功', [], 1, 1); } diff --git a/app/admin/lists/user/UserLists.php b/app/admin/lists/user/UserLists.php index 7976c871f..19b3d6332 100644 --- a/app/admin/lists/user/UserLists.php +++ b/app/admin/lists/user/UserLists.php @@ -12,8 +12,9 @@ use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\vip_flow\VipFlow; use support\Db; +use app\common\lists\ListsSearchInterface; -class UserLists extends BaseAdminDataLists implements ListsExcelInterface +class UserLists extends BaseAdminDataLists implements ListsExcelInterface,ListsSearchInterface { /** * @notes 搜索条件 @@ -23,8 +24,11 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function setSearch(): array { - $allowSearch = ['keyword', 'channel', 'create_time_start', 'create_time_end']; - return array_intersect(array_keys($this->params), $allowSearch); + return [ + '=' => ['store_id','user_ship','is_disable'], + '%like%' => ['account','mobile'], + '%pipe_like%' => ['nickname'=>'nickname|real_name'], + ]; } @@ -39,28 +43,15 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function lists(): array { - $params = $this->params; - $where = []; - if(isset($params['nickname']) && $params['nickname'] != ''){ - $where[] = ['real_name|nickname','like','%'.$params['nickname'].'%']; - } - if(isset($params['account']) && $params['account'] != ''){ - $where[] = ['account','like','%'.$params['account'].'%']; - } - if(isset($params['mobile']) && $params['mobile'] != ''){ - $where[] = ['mobile','like','%'.$params['mobile'].'%']; - } - if(isset($params['is_disable']) && $params['is_disable'] != ''){ - $where[] = ['is_disable','=', $params['is_disable']]; - } $field = "id,nickname,real_name,sex,avatar,account,mobile,channel,create_time,purchase_funds,user_ship, label_id,integral,now_money,total_recharge_amount"; - $lists = User::withSearch($this->setSearch(), $this->params)->where($where) + $lists = User::where($this->searchWhere) ->with(['user_ship','user_label']) ->limit($this->limitOffset, $this->limitLength) ->field($field) ->order('id desc') - ->select()->each(function($data){ + ->select() + ->each(function($data){ $data['sex_text'] = $data->sex_text; })->toArray(); foreach ($lists as &$item) { @@ -115,21 +106,8 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function count(): int { - $params = $this->params; - $where = []; - if(isset($params['nickname']) && $params['nickname'] != ''){ - $where[] = ['nickname','like','%'.$params['nickname'].'%']; - } - if(isset($params['account']) && $params['account'] != ''){ - $where[] = ['account','like','%'.$params['account'].'%']; - } - if(isset($params['mobile']) && $params['mobile'] != ''){ - $where[] = ['mobile','like','%'.$params['mobile'].'%']; - } - if(isset($params['is_disable']) && $params['is_disable'] != ''){ - $where[] = ['is_disable','=', $params['is_disable']]; - } - return User::withSearch($this->setSearch(), $this->params)->where($where)->count(); + + return User::where($this->searchWhere)->count(); } diff --git a/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php b/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php index 38d5fb657..a8a1b4c24 100644 --- a/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php +++ b/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php @@ -55,6 +55,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic try { StoreCashFinanceFlow::where('id', $params['id'])->update([ 'file' => $params['file'], + 'receipts' => $params['receipts']??0, 'status'=>1, 'admin_id'=>$params['admin_id'], ]); diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 986de0b54..b3c777f01 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -5,10 +5,14 @@ namespace app\api\controller; use app\admin\logic\store_product\StoreProductLogic; use app\admin\validate\tools\GenerateTableValidate; use app\admin\logic\tools\GeneratorLogic; +use app\api\logic\order\OrderLogic as OrderOrderLogic; +use app\common\logic\PayNotifyLogic; use app\common\logic\store_order\StoreOrderLogic; use app\common\model\Config as ModelConfig; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_order\StoreOrder; use app\common\model\system_store\SystemStore; +use app\common\model\user\User; use app\common\service\pay\PayService; use app\common\service\PushService; use app\common\service\wechat\WechatTemplate; @@ -179,10 +183,10 @@ return json($a); public function push() { - $name=$this->request->get('name');//用户名 - $uid=$this->request->get('uid');//用户id - $type=$this->request->get('type','INDUSTRYMEMBERS');//类型 - $a= PushService::push($name, $uid, ['type'=>$type,'msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>5]]); - return $this->success('ok',['data'=> $a]); + $name = $this->request->get('name'); //用户名 + $uid = $this->request->get('uid'); //用户id + $type = $this->request->get('type', 'INDUSTRYMEMBERS'); //类型 + $a = PushService::push($name, $uid, ['type' => $type, 'msg' => '支付超时,订单已被取消,请重新提交订单', 'data' => ['id' => 5]]); + return $this->success('ok', ['data' => $a]); } } diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index def9aa0ce..f4bd5270f 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -65,20 +65,23 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists ->toArray(); $off_activity = Config::where('name', 'off_activity')->value('value'); $user_ship = User::where('id', $userId)->value('user_ship'); - if (in_array($user_ship, [4, 5, 6, 7])) { - $off_activity=1; + $field = 'product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id'; + if (in_array($user_ship, [4, 6, 7])) { + $field = 'product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id'; } - $this->user_ship=$user_ship; - $this->off_activity=$off_activity; + $this->user_ship = $user_ship; + $this->off_activity = $off_activity; 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') + ->field($field) ->withTrashed() ->find(); - if ($find) { - if($off_activity==1){ - $this->activity_price = bcadd(bcmul($find['cost'],$item['cart_num'], 2), $this->activity_price, 2); + if ($off_activity == 1) { + $this->activity_price = bcadd(bcmul($find['cost'], $item['cart_num'], 2), $this->activity_price, 2); + } + if ($off_activity == 0 && $user_ship == 5 && $find['top_cate_id'] == 15189) { + $find['price'] = $find['cost']; } $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); @@ -111,24 +114,28 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists public function extend() { - $data= [ + $data = [ 'off_activity' => $this->off_activity, 'total_price' => $this->total_price, 'msg' => '', 'pay_price' => $this->total_price ]; - if($this->user_ship==0){ - $data['msg']='您已选购满500元,支付成功后即可获得'.bcmul($this->total_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。'; + if ($this->user_ship == 0) { + if ($data['pay_price'] < 500) { + $data['msg'] = '还差' . bcsub(500, $data['pay_price'], 2) . '即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。'; + } else { + $data['msg'] = '您已选购满500元,支付成功后即可获得' . bcmul($data['pay_price'], 0.1, 2) . '元品牌礼品兑换券,可到线下门店兑换礼品。'; + } } - if($this->off_activity==1){//1 - $data['pay_price']=$this->activity_price; - if($this->activity_price<500){ - if($this->user_ship==0){ - $data['msg']='还差'.bcsub(500,$this->activity_price,2).'即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。'; + if ($this->off_activity == 1) { //1 + $data['pay_price'] = $this->activity_price; + if ($data['pay_price'] < 500) { + if ($this->user_ship == 0) { + $data['msg'] = '还差' . bcsub(500, $this->activity_price, 2) . '即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。'; } - }else{ - if($this->user_ship==0){ - $data['msg']= '您已选购满500元,支付成功后即可获得'.bcmul($this->activity_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。'; + } else { + if ($this->user_ship == 0) { + $data['msg'] = '您已选购满500元,支付成功后即可获得' . bcmul($this->activity_price, 0.1, 2) . '元品牌礼品兑换券,可到线下门店兑换礼品。'; } } } diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index f30f4e1f8..3a3da76ff 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -10,6 +10,7 @@ use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use Picqer\Barcode\BarcodeGeneratorPNG; /** * 零售订单列表 @@ -80,6 +81,11 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface if($item['verify_img']){ $item['verify_img'] = 'https://'.$this->request->host(true).$item['verify_img']; } + if($item['is_writeoff']==0){ + $generator = new BarcodeGeneratorPNG(); + $tmpFilename = $generator->getBarcode($item['verify_code'], $generator::TYPE_CODE_128); + $item['verify_base64'] ='data:image/png;base64,'.base64_encode($tmpFilename); + } }) ->toArray(); diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index f1a8e3126..d15d822f2 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -79,23 +79,24 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis } 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'; + $fields = 'id,product_id,top_cate_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'; $off_activity = Config::where('name', 'off_activity')->value('value'); - if($off_activity==1){ - $tag='赠10%品牌礼品券'; - }else{ - $tag=''; + if ($off_activity == 1) { + $tag = '赠10%品牌礼品券'; + } else { + $tag = ''; } - $uid=0; - if($this->request->get('uid',0)>0){ - $uid=$this->request->get('uid',0); - }elseif( $this->userId > 0){ - $uid=$this->userId; + $uid = 0; + if ($this->request->get('uid', 0) > 0) { + $uid = $this->request->get('uid', 0); + } elseif ($this->userId > 0) { + $uid = $this->userId; } - if ($uid>0) { + $user_ship=-1; + if ($uid > 0) { $user_ship = User::where('id', $uid)->value('user_ship'); - if (in_array($user_ship, [4, 5, 6, 7])) { - $off_activity = 1; + if (in_array($user_ship, [4, 6, 7])) { + $fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; } } $this->off_activity = $off_activity; @@ -106,9 +107,11 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) ->order($order) - // ->page($this->limitOffset +1,$this->limitLength) - ->select()->each(function ($item) use($tag){ - $item['tag']=$tag; + ->select()->each(function ($item) use ($tag, $off_activity, $user_ship) { + if ($off_activity == 0 && $user_ship == 5 && $item['top_cate_id'] == 15189) { + $item['price'] = $item['cost']; + } + $item['tag'] = $tag; return $item; }) ->toArray(); diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index ad7de5414..ffcf7aa16 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -71,7 +71,7 @@ class OrderLogic extends BaseLogic self::setError('购物车为空'); return false; } - try { + // try { self::$total_price = 0; self::$pay_price = 0; self::$cost = 0; //成本由采购价替代原成本为门店零售价 @@ -84,13 +84,13 @@ class OrderLogic extends BaseLogic self::$fresh_price = 0; //生鲜金额 /** 计算价格 */ $off_activity = Config::where('name', 'off_activity')->value('value'); - $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id'; + $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id,store_info'; foreach ($cart_select as $k => $v) { $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find(); if (!$find) { // unset($cart_select[$k]); // continue; - $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id,cate_id'; + $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id,cate_id,store_info'; $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); if ($find) { $cate_id = StoreCategory::where('id', $find['cate_id'])->value('pid'); @@ -108,11 +108,14 @@ class OrderLogic extends BaseLogic } unset($cart_select[$k]['id']); $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 - if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 5, 6, 7]))) { + if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { $price = $find['cost']; } else { $price = $find['price']; } + if($off_activity==0 && $user['user_ship']==5 && $find['top_cate_id']==15189){ + $price=$find['cost']; + } $cart_select[$k]['price'] = $price; $cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['vip'] = 0; @@ -133,16 +136,17 @@ class OrderLogic extends BaseLogic $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]['store_info'] = $find['store_info']; //会员待返回金额 - 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 { - //其他会员 - $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['vip_price'], 2); - } - } + // 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 { + // //其他会员 + // $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'] ); $cartInfo = $cart_select[$k]; $cartInfo['name'] = $find['store_name']; @@ -159,7 +163,7 @@ class OrderLogic extends BaseLogic 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::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额 //计算生鲜 if ($createOrder == 1 && $find['top_cate_id'] == 15201) { self::$fresh_price = bcadd(self::$fresh_price, $cart_select[$k]['pay_price'], 2); @@ -245,10 +249,10 @@ class OrderLogic extends BaseLogic } } } - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; - } + // } catch (\Exception $e) { + // self::setError($e->getMessage()); + // return false; + // } return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store']]; } @@ -276,15 +280,15 @@ class OrderLogic extends BaseLogic $_order['uid'] = $uid; $_order['spread_uid'] = $params['spread_uid'] ?? 0; $_order['real_name'] = $user['real_name'] ?? ''; - $_order['mobile'] = $user['mobile'] ?? ''; + $_order['user_phone'] = $user['mobile'] ?? ''; $_order['pay_type'] = $orderInfo['order']['pay_type']; $_order['verify_code'] = $verify_code; $_order['reservation_time'] = null; - $_order['reservation'] = $params['reservation'] ?? 0; //是否需要预约 - if (isset($params['reservation_time']) && $params['reservation_time']) { - $_order['reservation_time'] = $params['reservation_time']; - $_order['reservation'] = YesNoEnum::YES; - } + $_order['reservation'] = 0;$params['reservation'] ?? 0; //是否需要预约 + // if (isset($params['reservation_time']) && $params['reservation_time']) { + // $_order['reservation_time'] = $params['reservation_time']; + // $_order['reservation'] = YesNoEnum::YES; + // } if ($addressId > 0 && $uid > 0) { $address = UserAddress::where(['id' => $addressId, 'uid' => $uid])->find(); if ($address) { @@ -502,6 +506,11 @@ class OrderLogic extends BaseLogic if ($find['verify_img']) { $find['verify_img'] = $url . $find['verify_img']; } + if($find['is_writeoff']==0){ + $generator = new BarcodeGeneratorPNG(); + $tmpFilename = $generator->getBarcode($find['verify_code'], $generator::TYPE_CODE_128); + $find['verify_base64'] = 'data:image/png;base64,'.base64_encode($tmpFilename); + } //处理返回最近的店铺 if ($param['lat'] && $param['long']) { $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 2e14a6e82..e65ce0f15 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -148,7 +148,7 @@ class CapitalFlowLogic extends BaseLogic { switch ($category) { case 'user_balance_recharge': - return "用户充值{$amount}元"; + return "用户增加{$amount}元"; case 'user_order_purchase_pay': return "用户采购款支付{$amount}元"; case 'store_margin': @@ -172,7 +172,7 @@ class CapitalFlowLogic extends BaseLogic case 'system_balance_reduce': return "系统减少余额{$amount}元"; case 'user_balance_recharge_refund': - return "用户充值退还{$amount}元"; + return "用户减少{$amount}元"; default: return "订单支付{$amount}元"; } diff --git a/app/common/logic/CommissionLogic.php b/app/common/logic/CommissionLogic.php index c95453d10..4334d5029 100644 --- a/app/common/logic/CommissionLogic.php +++ b/app/common/logic/CommissionLogic.php @@ -169,29 +169,29 @@ class CommissionLogic extends BaseLogic $fees = bcmul($pay_price, $userRate, 2); if ($fees > 0) { //记录用户余额收入 - if ($uid) { - if(in_array($enum,[14,15])&&$userRate==0.05){ - $purchase_funds=User::where('id', $uid)->value('purchase_funds'); - if($purchase_funds>0){ - $fees_two = bcmul($purchase_funds, $userRate, 2); - if($fees_two<$fees){ - $fees=$fees_two; - } - } - } - if($enum==12&&$userRate==0.07){ - $purchase_funds=User::where('id', $uid)->value('purchase_funds'); - if($purchase_funds>0){ - $fees_two = bcmul($purchase_funds, $userRate, 2); - if($fees_two<$fees){ - $fees=$fees_two; - } - } - } - $GiveUser = User::where('id', $order['uid'])->find(); - $capitalFlowDao = new CapitalFlowLogic($GiveUser); - $capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees); - } + // if ($uid) { + // if(in_array($enum,[14,15])&&$userRate==0.05){ + // $purchase_funds=User::where('id', $uid)->value('purchase_funds'); + // if($purchase_funds>0){ + // $fees_two = bcmul($purchase_funds, $userRate, 2); + // if($fees_two<$fees){ + // $fees=$fees_two; + // } + // } + // } + // if($enum==12&&$userRate==0.07){ + // $purchase_funds=User::where('id', $uid)->value('purchase_funds'); + // if($purchase_funds>0){ + // $fees_two = bcmul($purchase_funds, $userRate, 2); + // if($fees_two<$fees){ + // $fees=$fees_two; + // } + // } + // } + // $GiveUser = User::where('id', $order['uid'])->find(); + // $capitalFlowDao = new CapitalFlowLogic($GiveUser); + // $capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees); + // } $financeLogic->user['uid'] = $order['uid']; $financeLogic->other_arr['vip_uid'] = $uid; $financeLogic->order = $order; diff --git a/app/common/logic/PayNotifyLogic copy.php b/app/common/logic/PayNotifyLogic copy.php deleted file mode 100644 index 015e4ec93..000000000 --- a/app/common/logic/PayNotifyLogic copy.php +++ /dev/null @@ -1,1000 +0,0 @@ -getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); - throw new \Exception($e->getMessage()); - } - } - - /** - * 余额支付 - * @param $orderSn - * @param $extra - * @return bool - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function balancePay($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - $user = User::where('id', $order['uid'])->find(); - if ($user['now_money'] < $order['pay_price']) { - throw new \Exception('余额不足'); - } - $order->money = $order['pay_price']; - $order->paid = 1; - $order->pay_time = time(); - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - if($order['is_storage']==1){ - $order->status=2; - UserProductStorageLogic::add($order); - } - // 减去余额 - $user->now_money = bcsub($user['now_money'], $order['pay_price'], 2); - $user->save(); - - if ($order['spread_uid'] > 0 && $user['user_ship'] == 1) { - $oldUser = User::where('id', $order['spread_uid'])->value('purchase_funds'); - if ($oldUser < $order['pay_price']) { - $order['pay_price'] = $oldUser; - } - } - // self::addUserSing($order); - $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); - self::dealProductLog($order); -// if ($order['shipping_type'] == 3) { -// self::descStock($order['id']); -// } - self::afterPay($order); - if ($extra && $extra['store_id']) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['staff_id'] - ]; - OrderLogic::writeOff($params); - } - // Redis::send('push-platform-print', ['id' => $order['id']], 60); - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - } - - /** - * 礼品券支付 - * @param $orderSn - * @param $extra - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - - public static function gift_pay($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - $user = User::where('id', $order['uid'])->find(); - if ($user['integral'] < $order['pay_price']) { - throw new \Exception('礼品券不足'); - } - $order->money = $order['pay_price']; - $order->paid = 1; - $order->pay_time = time(); - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - // 减去礼品券 - $user->integral = bcsub($user['integral'], $order['pay_price'], 2); - $user->save(); - //入礼品券表扣款记录 - $sing[] = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '订单扣除兑换券', - 'store_id' => $order['store_id'], - 'number' => $order['pay_price'], - 'financial_pm' => 0, - 'user_ship' => $user['user_ship'], - ]; - (new UserSign())->saveAll($sing); - - if ($extra && $extra['store_id']) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['staff_id'] - ]; - OrderLogic::lessWriteOff($params); - } - self::dealProductLog($order); - } - - - /** - * 采购款支付 - * @param $orderSn - * @param $extra - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function purchase_funds($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - $user = User::where('id', $order['uid'])->find(); - if ($user['purchase_funds'] < $order['pay_price']) { - throw new \Exception('采购款不足'); - } - $order->money = $order['pay_price']; - $order->paid = 1; - $order->pay_time = time(); - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - if($order['is_storage']==1){ - $order->status=2; - UserProductStorageLogic::add($order); - } - // 减去采购款 - $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); - - $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 1, $order['store_id']); - // if ($user['user_ship'] == 1) { - // self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); - // } - // self::addUserSing($order); - self::afterPay($order); - if ($extra && $extra['store_id']) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['staff_id'] - ]; - OrderLogic::writeOff($params); - } - self::dealProductLog($order); - // if($order['shipping_type'] == 3){ - // self::descStock($order['id']); - // } - - - // Redis::send('push-platform-print', ['id' => $order['id']], 60); - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - } - - /** - * @notes 微信通用回调 - * @param $orderSn - * @param array $extra - * @date 2023/2/27 15:28 - */ - public static function wechat_common($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - $order->status = 1; - $order->paid = 1; - $order->pay_time = time(); - if($order['is_storage']==1){ - $order->status=2; - UserProductStorageLogic::add($order); - } - if ($order->pay_type != 10) { - $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2); - } else { - $extra['transaction_id'] = time(); - } - $user = User::where('id', $order['uid'])->find(); - if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付 - $order->status = 2; - } else { - $capitalFlowDao = new CapitalFlowLogic($user); - //微信支付和用户余额无关 - $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']); - } - $order->save(); - self::afterPay($order, $extra['transaction_id']); - // self::addUserSing($order); - self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { - Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4); - } - return true; - } - - //退款 - public static function refund($orderSn, $extra = []) - { - //更新状态 - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { - //充值 - $orderRe = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); - if ($orderRe->isEmpty() || $orderRe->status == -1) { - return true; - } - $orderRe->status = -1; - $orderRe->refund_price = $orderRe->price; - $orderRe->refund_time = time(); - $orderRe->remarks = ''; - $orderRe->save(); - - return true; - } - $order->status = OrderEnum::REFUND_PAY; - $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; - $order->refund_price = bcdiv($extra['amount']['refund'], 100, 2); - $order->refund_reason_time = time(); - $order->refund_num += 1; - $order->save(); - //日志记录 - //加用户余额,采购款, 日志记录 加数量 - $user = User::where('id', $order['uid'])->findOrEmpty(); - $capitalFlowDao = new CapitalFlowLogic($user); - $deal_money = bcdiv($extra['amount']['refund'], 100, 2); - $check_user_sing = UserSign::where('order_id',$order['order_id'])->count(); - if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { - if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 - $user->now_money = bcadd($user->now_money, $deal_money, 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); - } - if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款 - $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); - } - if($check_user_sing){ - self::descUserSing($order); - } - return true; - } - //积分 - if($check_user_sing){ - self::descUserSing($order); - } - //微信日志 user_order_refund - $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); - //处理财务流水退还 - self::store_finance_back($orderSn); - self::addStock($order['id']); //微信 - return true; - // self::afterPay($order,$extra['transaction_id']); - } - - //退积分 - public static function descUserSing($order) - { - $user_sing = new UserSign(); - if ($order['uid'] > 0 ) { - $user_number = bcmul($order['refund_price'], '0.10', 2); - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '退款扣除兑换券', - 'financial_pm' => 0, - 'store_id' => $order['store_id'], - 'number' => $user_number, - ]; - $user_sing->save($sing); - $now_int = User::where('id',$order['uid'])->find(); - if($now_int){ - if($now_int['integral'] > $user_number){ - User::where('id',$order['uid'])->dec('integral',$user_number)->update(); - }else{ - User::where('id',$order['uid'])->dec('integral',$now_int['integral'])->update(); - } - - } - } - return true; - - } - - - - /** - * 财务退还金额相关 - * @param $orderSn - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function store_finance_back($orderSn) - { - $data = StoreFinanceFlow::where('order_sn', $orderSn) - ->where(['financial_pm' => 1]) - ->select()->toArray(); - foreach ($data as &$value) { - unset($value['id']); - $value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn(); - $value['financial_pm'] = 0; - $value['financial_type'] = OrderEnum::PAY_BACK; - $value['create_time'] = time(); - } - (new StoreFinanceFlow)->saveAll($data); - } - - /** - * 现金退款相关 - * @param $orderSn - * @param $extra - * @return true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function cash_refund($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { - return true; - } - $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; - $order->refund_price = $order->pay_price; - $order->refund_reason_time = time(); - $order->refund_num += 1; - $order->save(); - //日志记录 - $model = new StoreCashFinanceFlow(); - $model->store_id = $order['store_id'] ?? 0; - $model->cash_price = $order->pay_price; - $model->receivable = $order->pay_price; - $model->remark = '退款'; - $model->type = 1; - $model->status = YesNoEnum::YES; - $model->save(); - //增加数量 - self::addStock($order['id']); - return true; - } - - /** - * 充值现金退款相关 - * @param $orderId - * @param $extra - * @return true - */ - public static function recharge_cash_refund($orderId, $extra = []) - { - $order = UserRecharge::where('id', $orderId)->findOrEmpty(); - if ($order->isEmpty() || $order->status == -1) { - return true; - } - $order->status = -1; - $order->refund_price = $order->price; - $order->refund_time = time(); - $order->remarks = ''; - $order->save(); - return true; - } - - //入冻结礼品券 - public static function addUserSing($order) - { - $user_sing = new UserSign(); - if ($order['uid'] > 0 && $order['total_price'] >= 500) { - $user_number = bcmul($order['pay_price'], '0.10', 2); - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '购买商品获得兑换券', - 'financial_pm' => 1, - 'store_id' => $order['store_id'], - 'number' => $user_number, - ]; - $user_sing->save($sing); - } - return true; - } - - - /** - * 充值 - */ - public static function recharge($orderSn, $extra = [], $type = 'wechat') - { - $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - if ($type == 'wechat') { - $price = bcdiv($extra['amount']['payer_total'], 100, 2); - } else { - $price = $extra['buyer_pay_amount']; - } - $order->price = $price; - $order->paid = 1; - $order->pay_time = time(); - $order->save(); - $uid = $order->uid; - $user = User::where('id', $uid)->findOrEmpty(); - //用户的财务add - $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price); - - if ($user->isEmpty()) { - return true; - } - bcscale(2); - // $user->now_money = bcadd($user->now_money, $price, 2);//v.1 - //更新等级 - if ($price >= Config::where('name','recharge')->value('value')) { - $user->user_ship = 1; //v.1 - } - $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); - $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); - $user->save(); - if($order['other_uid']>0){ - $uid=$order['other_uid']; - } - PushService::push('wechat_mmp_' . $uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); - PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); - if (!empty($extra['payer']['openid'])) { - Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); - } - return true; - } - - /** - * 现金支付 - */ - public static function cash_pay($orderSn) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - $order->paid = 1; - $order->pay_time = time(); - $order->status = 2; - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - self::afterPay($order); - $cashFlowLogic = new CashFlowLogic(); - $cashFlowLogic->insert($order['store_id'], $order['pay_price']); - self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - // Redis::send('push-platform-print', ['id' => $order['id']]); - return true; - } - - /** - * @notes 阿里回调 - * @param $orderSn - * @param array $extra - * @author 段誉 - * @date 2023/2/27 15:28 - */ - public static function alipay_cashier($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - if ($order->pay_type != 10) { - $order->money = $extra['buyer_pay_amount']; - $order->paid = 1; - $order->pay_time = time(); - $order->status = 1; - $order->save(); - } else { - $extra['transaction_id'] = time(); - } - if ($order->pay_type == 9) { - $order->status = 2; - self::afterPay($order); - } - self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - - // if ($order->pay_type == 9) { - // $extra['create_time'] = $order['create_time']; - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); - // Redis::send('push-platform-print', ['id' => $order['id']]); - // } - // else { - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - // } - return true; - } - - /** - * 支付后逻辑 - * @param $order - * @return void - */ - public static function afterPay($order, $transaction_id = 0) - { - $financeLogic = new StoreFinanceFlowLogic(); - $user_sing = new UserSign(); - $off_activity = Config::where('name', 'off_activity')->value('value'); - if ($off_activity == 1) { - //-----活动价结算更改 - $financeLogic->order = $order; - $financeLogic->user = ['uid' => $order['uid']]; - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - if ($order['uid'] > 0 && $order['total_price'] > 500 && $order['pay_type'] !=18 - && $order['pay_type'] !=3) { - $user_number = bcmul($order['pay_price'], '0.10', 2); - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '购买商品获得兑换券', - 'financial_pm' => 1, - 'store_id' => $order['store_id'], - 'number' => $user_number, - ]; - $user_sing->save($sing); - } - $financeLogic->save(); - return false; - } - $vipFen = 0; - if ($order['uid'] > 0) { - // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 - //用户下单该用户等级为1得时候才处理冻结金额 - $user = User::where('id', $order['uid'])->find(); - //纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额) - if ($order['spread_uid'] > 0) { - $oldUser = User::where('id', $order['spread_uid'])->field('purchase_funds,user_ship')->find(); - if ($oldUser && $oldUser['user_ship'] == 1) { - if ($oldUser['purchase_funds'] < $order['pay_price']) { - $vipFen = $oldUser['purchase_funds']; - } - } - } elseif ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) { - $vipFrozenAmount = self::dealFrozenPrice($order['id']); - //为1的时候要去减活动价 - // $final_price = bcsub($order['pay_price'],$order['deduction_price'],2); - // d($final_price,$vipFrozenAmount); - $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); - self::dealVipAmount($order, $order['pay_type']); - } - if($order['total_price'] > 500 && $order['pay_type'] !=18 - && $order['pay_type'] !=3){ - $user_number = bcmul($order['pay_price'], '0.10', 2); - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '购买商品获得兑换券', - 'financial_pm' => 1, - 'store_id' => $order['store_id'], - 'number' => $user_number, - 'status' => 0, - ]; - $user_sing->save($sing); - } - - // User::where('id', $order['uid'])->inc('integral', $user_number)->update(); - } - - - $financeLogic->order = $order; - $financeLogic->user = ['uid' => $order['uid']]; - // if ($order->pay_type != 9 || $order->pay_type != 10) { - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 - $count_frees = 0; - - //平台手续费 - $fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); - $count_frees = bcadd($count_frees, $fees, 2); - if ($fees > 0) { - $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 - } - // $frozen = bcsub($order->profit, $fees, 2); - //缴纳齐全了就加商户没有就加到平台 - $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); - $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 - $store_profit = bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2); - $count_frees = bcadd($count_frees, $store_profit, 2); - if ($deposit > 0) { - if ($deposit > $store_profit) { - if ($store_profit > 0) { - SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update(); - $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - } - } else { - $money = bcsub($store_profit, $deposit, 2); - if ($deposit > 0) { - SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update(); - $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - if ($money) { - SystemStore::where('id', $order['store_id'])->inc('store_money', $money)->update(); - $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - } - } - } else { - if ($store_profit > 0) { - SystemStore::where('id', $order['store_id'])->inc('store_money', $store_profit)->update(); - $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - } - } - // if ($order['is_vip'] >= 1) { - if ($order['spread_uid'] > 0) { - $financeLogic->other_arr['vip_uid'] = $order['spread_uid']; - if ($vipFen) { - $fees = bcdiv(bcmul($vipFen, '0.08', 2), 1, 2); - } else { - $fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2); - } - $count_frees = bcadd($count_frees, $fees, 2); - if ($fees > 0) { - User::where('id', $order['spread_uid'])->inc('now_money', $fees)->update(); - //记录用户余额收入 - $GiveUser = User::where('id', $order['spread_uid'])->find(); - $capitalFlowDao = new CapitalFlowLogic($GiveUser); - $capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees); - - $financeLogic->in($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //vip订单获得 - $financeLogic->out($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - } - $fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2); - $count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2); - $village_uid = 0; - $brigade_uid = 0; - //查询用户对应的村长和队长 - if ($order['uid'] > 0) { - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); - if ($uid) { - User::where('id', $uid)->inc('integral', $fees)->update(); - $village_uid = $uid; - } - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); - if ($uid) { - User::where('id', $uid)->inc('integral', $fees)->update(); - $brigade_uid = $uid; - } - } - } - } - if ($fees > 0) { - //村长获得 - // $sing = []; - - // $sing[] = [ - // 'uid' => $village_uid, - // 'order_id' => $order['order_id'], - // 'title' => '村长订单获得兑换券', - // 'store_id' => $order['store_id'], - // 'number' => $fees, - // 'financial_pm' => 1, - // 'user_ship' => 2, - // ]; - // $sing[] = [ - // 'uid' => $brigade_uid, - // 'order_id' => $order['order_id'], - // 'title' => '队长订单获得兑换券', - // 'store_id' => $order['store_id'], - // 'number' => $fees, - // 'financial_pm' => 1, - // 'user_ship' => 3, - // ]; - // $sing[] = [ - // 'uid' => $village_uid, - // 'order_id' => $order['order_id'], - // 'title' => '订单扣除兑换券', - // 'store_id' => $order['store_id'], - // 'number' => $fees, - // 'financial_pm' => 0, - // 'user_ship' => 2, - // ]; - // $sing[] = [ - // 'uid' => $brigade_uid, - // 'order_id' => $order['order_id'], - // 'title' => '订单扣除兑换券', - // 'store_id' => $order['store_id'], - // 'number' => $fees, - // 'financial_pm' => 0, - // 'user_ship' => 3, - // ]; - if ($village_uid > 0) { - SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update(); - $financeLogic->other_arr['vip_uid'] = $village_uid; - } - $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - //队长获得 - if ($brigade_uid > 0) { - SystemStore::where('id', $brigade_uid)->inc('store_money', $fees)->update(); - $financeLogic->other_arr['vip_uid'] = $brigade_uid; - } - $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - // $user_sing->saveAll($sing); - //其他获得 - $financeLogic->other_arr['vip_uid'] = 0; - $financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - // } - $fees = bcsub($order['pay_price'], $count_frees, 2); - //供应链订单获得 - if ($fees > 0) { - $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - // } - $financeLogic->save(); - // } - } - - /** - * 回调日志 - * @param $order - * @param $extra - * @return void - */ - public static function notifyLog($order, $extra) - { - $data = [ - 'pay_type' => 'wechat', - 'type' => OrderEnum::PAY, - 'amount' => $extra['amount']['payer_total'], //分 - 'order_sn' => $order, - 'out_trade_no' => $extra['transaction_id'], - 'attach' => $extra['attach'], - 'create_time' => date('Y-m-d H:i:s', time()), - ]; - PayNotify::create($data); - } - - /** - * 冻结金额 - * @param $oid - * @return int|mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - - public static function dealFrozenPrice($oid) - { - $detail = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - $total_vip = 0; - foreach ($detail as $value) { - $total_vip += $value['cart_info']['vip_frozen_price']; - } - return $total_vip; - } - - - /** - * 处理用户为vip1时得冻结资金 - * @param $order - * @param $pay_type - * @param $transaction_id - * @return true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function dealVipAmount($order, $pay_type = 1, $transaction_id = 0) - { - $total_vip = self::dealFrozenPrice($order['id']); - $data = [ - 'order_id' => $order['id'], - 'transaction_id' => $transaction_id ?? 0, - 'order_sn' => $order['order_id'], - 'user_id' => $order['uid'], - 'number' => $total_vip, - 'pay_type' => $pay_type ?? 1, - 'status' => 0, - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'], - 'create_time' => time() - ]; - Db::name('vip_flow')->insert($data); - return true; - } - - /** - * 商品统计逻辑 - * @param $order - * @return true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function dealProductLog($order) - { - $store_id = $order['store_id']; - $cart_id = $order['cart_id']; - $uid = $order['uid']; - if ($uid && $cart_id && $store_id) { - $cart_id = explode(',', $cart_id); - $productLog = StoreProductLog::where([ - 'uid' => $uid - ])->whereIn('cart_id', $cart_id) - ->select()->toArray(); - - foreach ($productLog as &$value) { - $value['pay_uid'] = $uid; - $value['oid'] = $order['id']; - $cart_info = StoreOrderCartInfo::where([ - 'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'store_id' => $store_id - ])->find(); - $value['order_num'] = $cart_info['cart_num'] ?? 1; - $value['pay_num'] = $cart_info['cart_num'] ?? 1; - $value['pay_price'] = $cart_info['price'] ?? 0; - $value['cost_price'] = $cart_info['cart_info']['cost'] ?? 0; - $value['update_time'] = time(); - unset($value['create_time'], $value['delete_time']); - } - - (new StoreProductLog())->saveAll($productLog); - } - return true; - } - - - public static function descSwap($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'swap' => $StoreBranchProduct['swap'] - $v['cart_num'], - 'sales' => ['inc', $v['cart_num']] - ]; - } - - (new StoreBranchProduct())->saveAll($updateData); - } - - - /** - * 扣库存 - * @param $oid - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function descStock($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - if ($StoreBranchProduct) { - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'stock' => $StoreBranchProduct['stock'] - $v['cart_num'], - 'sales' => ['inc', $v['cart_num']] - ]; - } - } - - (new StoreBranchProduct())->saveAll($updateData); - } - - /** - * 加库存 - * @param $oid - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function addStock($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - if ($StoreBranchProduct) { - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], - // 'sales' => ['inc', $v['cart_num']] - // 'sales' => ['inc', $v['cart_num']] - ]; - } - } - - (new StoreBranchProduct())->saveAll($updateData); - } -} diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index fc3b8c407..04bc3d2b4 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -95,9 +95,7 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - // self::descStock($order['id']); - } + self::afterPay($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { $checkArr = [ @@ -278,9 +276,7 @@ class PayNotifyLogic extends BaseLogic self::afterPay($order, $extra['transaction_id']); // self::addUserSing($order); self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } + if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4); } @@ -438,7 +434,7 @@ class PayNotifyLogic extends BaseLogic $uid = $order->uid; $user = User::where('id', $uid)->findOrEmpty(); //check store_id - if(empty($user->store_id)){ + if($user->store_id==0){ $user->store_id = $order['store_id']; } @@ -499,10 +495,6 @@ class PayNotifyLogic extends BaseLogic $cashFlowLogic->insert($order['store_id'], $order['pay_price']); self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - if ($order && $order['store_id'] && $order['reservation'] !=1) { $params = [ 'verify_code' => $order['verify_code'], @@ -546,9 +538,6 @@ class PayNotifyLogic extends BaseLogic UserProductStorageLogic::add($order); } self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } // if ($order->pay_type == 9) { // $extra['create_time'] = $order['create_time']; @@ -811,37 +800,6 @@ class PayNotifyLogic extends BaseLogic } - /** - * 扣库存 - * @param $oid - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function descStock($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - if ($StoreBranchProduct) { - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'stock' => $StoreBranchProduct['stock'] - $v['cart_num'], - 'sales' => ['inc', $v['cart_num']] - ]; - } - } - - (new StoreBranchProduct())->saveAll($updateData); - } - /** * 加库存 * @param $oid diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index ab6999160..a845c7ed1 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -134,7 +134,8 @@ class StoreFinanceFlowLogic extends BaseLogic */ public function updateStatusUser($id, $uid, $money, $order_id) { - StoreFinanceFlow::where('id', $id)->update(['status' => 1]); + $flow=StoreFinanceFlow::where('id', $id)->find(); + StoreFinanceFlow::where('order_id',$order_id)->where('financial_type',$flow['financial_type'])->update(['status'=>1]); $find = User::where('id', $uid)->find(); $capitalFlowDao = new CapitalFlowLogic($find); $capitalFlowDao->userIncome('system_balance_add', 'order', $order_id, $money); diff --git a/app/common/logic/UserSignLogic.php b/app/common/logic/UserSignLogic.php index b4f66ba65..47cfc609b 100644 --- a/app/common/logic/UserSignLogic.php +++ b/app/common/logic/UserSignLogic.php @@ -32,16 +32,16 @@ class UserSignLogic extends BaseLogic $list = DictData::where('type_value', 'recharge')->select(); foreach( $list as $k=>$v){ if($v['name']=='level_one'){ - $level_one = $v['value']; + $level_one = bcadd($v['value'],0,2); }elseif($v['name']=='level_two'){ - $level_two = $v['value']; + $level_two = bcadd($v['value'],0,2); }elseif($v['name']=='level_three' ){ - $level_three = $v['value']; + $level_three = bcadd($v['value'],0,2); }elseif($v['name']=='level_four'){ - $level_four = $v['value']; + $level_four = bcadd($v['value'],0,2); } } - $price=(int)$order['price']; + $price= bcadd($order['price'],0,2); switch ($price) { case $level_one: $total_vip = 249; @@ -62,7 +62,7 @@ class UserSignLogic extends BaseLogic return false; } $count = UserRecharge::where(['uid'=>$order->uid,'paid'=>YesNoEnum::YES])->count(); - if ($count ==1 && $user_ship>0) { + if ($count ==1 && in_array($user_ship,[1,2,3])) { //首充 $write = self::write($order, $total_vip, 0, 1, 9); self::write_log($write, $total_vip, 0, 7); diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 88adab808..53e5d26fd 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -12,6 +12,7 @@ use app\common\model\order\Cart; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\User; use app\common\service\pay\PayService; @@ -207,10 +208,15 @@ class StoreOrderLogic extends BaseLogic 'stock' => $stock-$v['cart_num'], 'sales' => ['inc', $v['cart_num']] ]; + $updateDataTwo[] = [ + 'id' => $v['product_id'], + 'sales' => ['inc', $v['cart_num']] + ]; } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; (new StoreBranchProduct())->saveAll($updateData); + (new StoreProduct())->saveAll($updateDataTwo); Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); Db::commit(); return $order; diff --git a/app/queue/redis/TaskRechargeQuerySend.php b/app/queue/redis/TaskRechargeQuerySend.php new file mode 100644 index 000000000..e42d4d6ef --- /dev/null +++ b/app/queue/redis/TaskRechargeQuerySend.php @@ -0,0 +1,44 @@ + $data['order_id'], + ]; + $res = $pay->wechat->query($order); + if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { + if(isset($data['pay_type']) && $data['pay_type']=='recharge'){ + PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); + } + } + } + // 消费失败时 + public function onConsumeFailure(\Throwable $exception, $package) + { + return $package; + } +} diff --git a/app/store/lists/system_store_storage/SystemStoreStorageLists.php b/app/store/lists/system_store_storage/SystemStoreStorageLists.php index efdd3ade0..681fe63f8 100644 --- a/app/store/lists/system_store_storage/SystemStoreStorageLists.php +++ b/app/store/lists/system_store_storage/SystemStoreStorageLists.php @@ -29,7 +29,7 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI public function setSearch(): array { return [ - '=' => ['admin_id', 'staff_id', 'status','type'], + '=' => ['admin_id', 'staff_id', 'status', 'type'], ]; } @@ -45,12 +45,12 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI */ public function lists(): array { - $this->searchWhere[] = ['store_id','=',$this->adminInfo['store_id']];//只显示当前门店的入库记录 - if($this->request->__get('status')==-1){ - $this->searchWhere[] = ['status','>=',0]; + $this->searchWhere[] = ['store_id', '=', $this->adminInfo['store_id']]; //只显示当前门店的入库记录 + if ($this->request->__get('status') == -1) { + $this->searchWhere[] = ['status', '>=', 0]; } return SystemStoreStorage::where($this->searchWhere) - ->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums','mark', 'status']) + ->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums', 'mark', 'status']) ->limit($this->limitOffset, $this->limitLength) ->order(['status' => 'aes']) ->select()->each(function ($item) { @@ -62,9 +62,15 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI } else { $item['staff_name'] = '无'; } - $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find(); - $item['store_name']=$find['store_name']; - $item['image']=$find['image']; + $find = StoreProduct::where('id', $item['product_id'])->field('store_name,image')->find(); + if ($find) { + $item['store_name'] = $find['store_name']; + $item['image'] = $find['image']; + } else { + $item['store_name'] = ''; + $item['image'] = ''; + } + return $item; }) ->toArray(); @@ -81,5 +87,4 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI { return SystemStoreStorage::where($this->searchWhere)->count(); } - } diff --git a/process/Task.php b/process/Task.php index fa0e66504..789c98e80 100644 --- a/process/Task.php +++ b/process/Task.php @@ -1,7 +1,13 @@ 0]; - $where[]=['create_time','<',time() - 600];// 10分钟前创建的订单 + // 每10分钟执行一次 + new Crontab('0 */10 * * * *', function () { + $where = ['paid' => 0]; + $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 // 删除10分钟未支付的订单 - StoreOrder::where($where)->update(['delete_time'=>time()]); // 删除时间设置为当前时间,即删除 + $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 + if ($oid) { + StoreOrder::where('id', 'in', $oid)->update(['delete_time' => time()]); + $arr = StoreOrderCartInfo::where('oid', 'in', $oid)->field('store_id,product_id,cart_num')->select(); + $updateData = []; + $updateDataTwo = []; + foreach ($arr as $v) { + $updateData[] = [ + 'id' => $v['branch_product_id'], + 'sales' => ['dec', $v['cart_num']] + ]; + $updateDataTwo[] = [ + 'id' => $v['product_id'], + 'sales' => ['dec', $v['cart_num']] + ]; + } + (new StoreBranchProduct())->saveAll($updateData); + (new StoreProduct())->saveAll($updateDataTwo); + } + + // 获取当前时间 + $now = time(); + // 计算一个小时前的时间戳 + $oneHourAgo = $now - 3600; + //删除未充值的订单 + 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]); + } + }); } -} \ No newline at end of file +}