diff --git a/app/admin/controller/LoginController.php b/app/admin/controller/LoginController.php index 89c51f54a..59f555ea2 100644 --- a/app/admin/controller/LoginController.php +++ b/app/admin/controller/LoginController.php @@ -37,8 +37,8 @@ class LoginController extends BaseAdminController */ public function account() { - $params = $this->request->post(); -// $params = (new LoginValidate())->post()->goCheck(); + // $params = $this->request->post(); + $params = (new LoginValidate())->post()->goCheck(); return $this->data((new LoginLogic())->login($params)); } diff --git a/app/admin/controller/user_ship/UserShipController.php b/app/admin/controller/user_ship/UserShipController.php new file mode 100644 index 000000000..123681b4f --- /dev/null +++ b/app/admin/controller/user_ship/UserShipController.php @@ -0,0 +1,93 @@ +dataLists(new UserShipLists()); + } + + + /** + * @notes 添加会员类型 + * @return \think\response\Json + * @author admin + * @date 2024/06/29 14:18 + */ + public function add() + { + $params = (new UserShipValidate())->post()->goCheck('add'); + $result = UserShipLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(UserShipLogic::getError()); + } + + + /** + * @notes 编辑会员类型 + * @return \think\response\Json + * @author admin + * @date 2024/06/29 14:18 + */ + public function edit() + { + $params = (new UserShipValidate())->post()->goCheck('edit'); + $result = UserShipLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(UserShipLogic::getError()); + } + + + /** + * @notes 删除会员类型 + * @return \think\response\Json + * @author admin + * @date 2024/06/29 14:18 + */ + public function delete() + { + $params = (new UserShipValidate())->post()->goCheck('delete'); + UserShipLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取会员类型详情 + * @return \think\response\Json + * @author admin + * @date 2024/06/29 14:18 + */ + public function detail() + { + $params = (new UserShipValidate())->goCheck('detail'); + $result = UserShipLogic::detail($params); + return $this->data($result); + } +} diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index c4ced3bf6..50b5906e7 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -32,6 +32,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI '=' => ['product_id', 'cate_id','store_id','status'], '%pipe_like%' => ['store_name_code'=>'store_name|bar_code'], '%like%' => ['store_name'], + '<='=> ['stock'], ]; } @@ -47,7 +48,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI */ public function lists(): array { - $status = $this->params['status'] ?? ''; $class_all=$this->request->get('class_all'); $where=[]; if($class_all){ @@ -69,17 +69,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); }) - ->when(!empty($status), function ($query) use ($status) { - if ($status == 1) { - $query->where('status', $status); - } elseif ($status == 2) { - $query->where('status', 0); - } elseif ($status == 3) { - $query->where('stock', '<=', 0); - } elseif ($status == 4) { - $query->where('stock', '<', 10)->where('stock', '>', 0); - } - }) ->limit($this->limitOffset, $this->limitLength) ->order(['sort' => 'desc','stock'=>'desc','id' => 'desc']) ->select() @@ -101,22 +90,10 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI */ public function count(): int { - $status = $this->params['status'] ?? ''; return StoreBranchProduct::where($this->searchWhere) ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); }) - ->when(!empty($status), function ($query) use ($status) { - if ($status == 1) { - $query->where('status', $status); - } elseif ($status == 2) { - $query->where('status', 0); - } elseif ($status == 3) { - $query->where('stock', '<=', 0); - } elseif ($status == 4) { - $query->where('stock', '<', 10)->where('stock', '>', 0); - } - }) ->count(); } diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index 39c010c45..3da16980b 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -30,7 +30,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['order_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'], + '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'], 'between_time' => 'create_time' ]; } @@ -47,7 +47,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return StoreOrder::with(['staff'])->where($this->searchWhere) + return StoreOrder::with(['staff','store'])->where($this->searchWhere) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->request->adminInfo['store_id']); }) diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index cdaa4ba66..338ab1517 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -29,7 +29,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function setSearch(): array { return [ - '=' => ['cate_id'], + '=' => ['cate_id','is_show'], + '<='=> ['stock'], '%like%' => ['store_name'], ]; } diff --git a/app/admin/lists/user_label/UserLabelLists.php b/app/admin/lists/user_label/UserLabelLists.php index 53261482b..79639ed74 100644 --- a/app/admin/lists/user_label/UserLabelLists.php +++ b/app/admin/lists/user_label/UserLabelLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\user_label; use app\admin\lists\BaseAdminDataLists; use app\common\model\user_label\UserLabel; use app\common\lists\ListsSearchInterface; -use app\common\model\user\UserShip; +use app\common\model\user_ship\UserShip; /** * 用户标签列表 diff --git a/app/admin/lists/user_product_storage/UserProductStorageLists.php b/app/admin/lists/user_product_storage/UserProductStorageLists.php index e7efd4b25..f44c9f8a3 100644 --- a/app/admin/lists/user_product_storage/UserProductStorageLists.php +++ b/app/admin/lists/user_product_storage/UserProductStorageLists.php @@ -29,7 +29,7 @@ class UserProductStorageLists extends BaseAdminDataLists implements ListsSearchI { return [ '=' => ['uid', 'oid', 'product_id'], - 'between_time' => ['create_time'], + 'between_time' => 'create_time', ]; } @@ -48,9 +48,15 @@ class UserProductStorageLists extends BaseAdminDataLists implements ListsSearchI $status=$this->request->get('status',1); if($status==1){ $this->searchWhere[]=['status','=',1];//只显示正常状态的记录,不显示已出库完的记录 + $field='id,uid,oid,product_id,sum(nums) nums,status,create_time'; + $group='product_id'; + }else{ + $field='id,uid,oid,product_id,nums,status,create_time'; + $group=null; } return UserProductStorage::where($this->searchWhere) - ->field(['id', 'uid', 'oid', 'product_id', 'nums', 'status','create_time']) + ->field($field) + ->group($group) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($item){ diff --git a/app/admin/lists/user_ship/UserShipLists.php b/app/admin/lists/user_ship/UserShipLists.php new file mode 100644 index 000000000..faf9b87b8 --- /dev/null +++ b/app/admin/lists/user_ship/UserShipLists.php @@ -0,0 +1,65 @@ + ['title'], + ]; + } + + + /** + * @notes 获取会员类型列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/06/29 14:18 + */ + public function lists(): array + { + return UserShip::where($this->searchWhere) + ->field(['id', 'title', 'discount', 'limit', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取会员类型数量 + * @return int + * @author admin + * @date 2024/06/29 14:18 + */ + public function count(): int + { + return UserShip::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/auth/AdminLogic.php b/app/admin/logic/auth/AdminLogic.php index b6967425f..0f92fa397 100644 --- a/app/admin/logic/auth/AdminLogic.php +++ b/app/admin/logic/auth/AdminLogic.php @@ -225,7 +225,7 @@ class AdminLogic extends BaseLogic { $admin = Admin::field([ 'id', 'account', 'name', 'disable', 'root', - 'multipoint_login', 'avatar', + 'multipoint_login', 'avatar','role_id' ])->findOrEmpty($params['id'])->toArray(); if ($action == 'detail') { diff --git a/app/admin/logic/statistic/TradeStatisticLogic.php b/app/admin/logic/statistic/TradeStatisticLogic.php index 9ffded419..7297e10c7 100644 --- a/app/admin/logic/statistic/TradeStatisticLogic.php +++ b/app/admin/logic/statistic/TradeStatisticLogic.php @@ -328,13 +328,13 @@ class TradeStatisticLogic extends BaseLogic ]; $Chain['deposit'] = $OrderDepositCurve; //兑换礼品券 - $userSign = $this->getUserSign($where, 'sum'); - $userSignTwo = $this->getUserSign($where, 'sum', "", $isNum); - $userSignGroup = $this->getUserSign($where, 'group', "create_time"); + $userSign = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $where['create_time']], 'sum'); + $userSignTwo = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $dateWhere['create_time']], 'sum', "", $isNum); + $userSignGroup = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $where['create_time']], 'group', 'create_time'); $userSignRate = countRate($userSign, $userSignTwo); $topData[9] = [ - 'title' => '兑换礼品券', - 'desc' => '后台给推广员支付的兑换礼品券,以实际支付为准', + 'title' => '礼品券消耗', + 'desc' => '用户下单时使用礼品券实际支付的金额', 'total_money' => $userSign, 'rate' => $userSignRate, 'value' => $userSignGroup['y'], @@ -385,20 +385,20 @@ class TradeStatisticLogic extends BaseLogic // $Chain['out'] = $outTotalCurve; //商品退款金额 - $outOrderRefund = $this->getOrderRefundTotalMoney(['create_time' => $where['create_time']], 'sum'); - $lastOutOrderRefund = $this->getOrderRefundTotalMoney(['create_time' => $dateWhere['create_time']], 'sum', "", $isNum); - $outOrderRefundCurve = $this->getOrderRefundTotalMoney(['create_time' => $where['create_time']], 'group', 'create_time'); - $orderRefundChain = countRate($outOrderRefund, $lastOutOrderRefund); - $topData[12] = [ - 'title' => '商品退款金额', - 'desc' => '用户成功退款的商品金额', - 'total_money' => $outOrderRefund, - 'rate' => $orderRefundChain, - 'value' => $outOrderRefundCurve['y'], - 'type' => 0, - 'sign' => 'refund', - ]; - $Chain['refund'] = $outOrderRefundCurve; + // $outOrderRefund = $this->getOrderRefundTotalMoney(['create_time' => $where['create_time']], 'sum'); + // $lastOutOrderRefund = $this->getOrderRefundTotalMoney(['create_time' => $dateWhere['create_time']], 'sum', "", $isNum); + // $outOrderRefundCurve = $this->getOrderRefundTotalMoney(['create_time' => $where['create_time']], 'group', 'create_time'); + // $orderRefundChain = countRate($outOrderRefund, $lastOutOrderRefund); + // $topData[12] = [ + // 'title' => '商品退款金额', + // 'desc' => '用户成功退款的商品金额', + // 'total_money' => $outOrderRefund, + // 'rate' => $orderRefundChain, + // 'value' => $outOrderRefundCurve['y'], + // 'type' => 0, + // 'sign' => 'refund', + // ]; + // $Chain['refund'] = $outOrderRefundCurve; @@ -602,7 +602,7 @@ class TradeStatisticLogic extends BaseLogic { /** 普通商品订单支付金额 */ $storeOrder = new StoreOrder(); - $where['refund_status'] = isset($where['refund_status']) ? $where['refund_status'] : [0, 3]; + $where['refund_status'] = 0; $where['paid'] = 1; $timeKey = $this->TimeConvert($where['create_time'], $isNum); @@ -647,7 +647,7 @@ class TradeStatisticLogic extends BaseLogic switch ($selectType) { case "sum": - $totalMoney = $userRechage->where(['paid' => 1]) + $totalMoney = $userRechage->where(['paid' => 1,'status'=>1]) ->when(isset($where['create_time']), function ($query) use ($where) { $query->whereBetweenTime('create_time', strtotime($where['timeKey']['start_time']), strtotime($where['timeKey']['end_time'])); }) diff --git a/app/admin/logic/user/UserLogic.php b/app/admin/logic/user/UserLogic.php index 809056e1d..d911d34f3 100644 --- a/app/admin/logic/user/UserLogic.php +++ b/app/admin/logic/user/UserLogic.php @@ -25,6 +25,7 @@ use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; use app\common\model\user_create_log\UserCreateLog; use app\common\model\user_label\UserLabel; +use app\common\model\user_ship\UserShip; use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use think\facade\Db; @@ -92,6 +93,9 @@ class UserLogic extends BaseLogic 'label_id' => $params['label_id']??0, 'store_id' => $params['store_id']??0, ]; + if(isset($params['user_ship']) &&$params['user_ship']==4){ + $data['user_ship']=4; + } $res=User::create($data); UserCreateLog::create([ 'uid' => $res['id'], @@ -161,7 +165,7 @@ class UserLogic extends BaseLogic public static function detail(int $userId): array { $field = [ - 'id', 'account', 'nickname', 'avatar', 'real_name','integral','label_id', + 'id', 'account', 'nickname', 'avatar', 'real_name','integral','label_id','user_ship', 'sex', 'mobile', 'create_time', 'login_time', 'channel','now_money','purchase_funds' ]; @@ -171,7 +175,7 @@ class UserLogic extends BaseLogic $user['channel'] = UserTerminalEnum::getTermInalDesc($user['channel']); $user->sex = $user->getData('sex'); $user['number']=StoreFinanceFlow::where('other_uid',$userId)->where(['status'=>0,'financial_pm'=>1,'type'=>1])->sum('number'); - $user['label_name']=$user->label_id?UserLabel::where('label_id',$user->label_id)->value('label_name'):""; + $user['user_ship_name']=$user->user_ship>0?UserShip::where('id',$user->user_ship)->value('title'):"一般用户"; return $user->toArray(); } diff --git a/app/admin/logic/user_ship/UserShipLogic.php b/app/admin/logic/user_ship/UserShipLogic.php new file mode 100644 index 000000000..0166b1a84 --- /dev/null +++ b/app/admin/logic/user_ship/UserShipLogic.php @@ -0,0 +1,98 @@ + $params['title'], + 'limit' => $params['limit'], + 'sort' => $params['sort'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑会员类型 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/29 14:18 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + UserShip::where('id', $params['id'])->update([ + 'title' => $params['title'], + 'limit' => $params['limit'], + 'sort' => $params['sort'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除会员类型 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/29 14:18 + */ + public static function delete(array $params): bool + { + return UserShip::destroy($params['id']); + } + + + /** + * @notes 获取会员类型详情 + * @param $params + * @return array + * @author admin + * @date 2024/06/29 14:18 + */ + public static function detail($params): array + { + return UserShip::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/user_ship/UserShipValidate.php b/app/admin/validate/user_ship/UserShipValidate.php new file mode 100644 index 000000000..e9a3899d3 --- /dev/null +++ b/app/admin/validate/user_ship/UserShipValidate.php @@ -0,0 +1,88 @@ + 'require', + 'title' => 'require', + 'limit' => 'require', + 'sort' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'title' => '会员名称', + 'limit' => '充值金额', + 'sort' => '排序倒序', + ]; + + + /** + * @notes 添加场景 + * @return UserShipValidate + * @author admin + * @date 2024/06/29 14:18 + */ + public function sceneAdd() + { + return $this->only(['title','limit','sort']); + } + + + /** + * @notes 编辑场景 + * @return UserShipValidate + * @author admin + * @date 2024/06/29 14:18 + */ + public function sceneEdit() + { + return $this->only(['id','title','limit','sort']); + } + + + /** + * @notes 删除场景 + * @return UserShipValidate + * @author admin + * @date 2024/06/29 14:18 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return UserShipValidate + * @author admin + * @date 2024/06/29 14:18 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/BackController.php b/app/api/controller/BackController.php deleted file mode 100644 index 50860985d..000000000 --- a/app/api/controller/BackController.php +++ /dev/null @@ -1,138 +0,0 @@ -=', $startTime) - ->where('create_time', '<', $endTime) - ->group('user_id, pay_type') - ->field('user_id, pay_type, COUNT(*) as transaction_count, SUM(number) as total_amount') - ->select()->toArray(); - - // 遍历查询结果并分类 现金不进入反的逻辑 - //3余额 18采购款 7微信小程序 9微信条码 13 支付宝条码支付 - $Balance = []; - $Procurement = []; - $WechatMiniPay = []; - $WechatBarcodePay = []; - $AliBarcodePay = []; - foreach ($result as $row) { - $payType = $row['pay_type']; - $userId = $row['user_id']; - $totalAmount = $row['total_amount']; - switch ($payType) { - case 3: - $user_now_money = User::where( - [ - 'id' => $userId - ] - )->withTrashed()->value('now_money'); - $Balance[] = [ - 'id' => $userId, - 'now_money' => bcadd($user_now_money, $totalAmount, 2), - ]; - break; - case 7: - $WechatMiniPay[] = [ - 'id' => $userId, - 'total_amount' => $totalAmount, - ]; - break; - case 9: - $WechatBarcodePay[] = [ - 'id' => $userId, - 'total_amount' => $totalAmount, - ]; - break; - case 13: - $AliBarcodePay[] = [ - 'id' => $userId, - 'total_amount' => $totalAmount, - ]; - break; - case 18: - $purchase_funds_money = User::where( - [ - 'id' => $userId - ] - )->withTrashed()->value('purchase_funds'); - $Procurement[] = [ - 'id' => $userId, - 'purchase_funds' => bcadd($purchase_funds_money, $totalAmount, 2), - ]; - break; - } - - } - //入记录表的话查询后便利入 3余额 18采购款 - if ($Balance) { - (new User())->saveAll($Balance); - $this->dealCapital($startTime, $endTime, 3); - } - if ($Procurement) { - (new User())->saveAll($Procurement); - $this->dealCapital($startTime, $endTime, 18); - } - //7微信小程序 9微信条码 13 支付宝条码支付 - - - } - - public function dealCapital($startTime, $endTime, $pay_type) - { - $vipFrozen = VipFlow::where('create_time', '>=', $startTime) - ->where('create_time', '<', $endTime) - ->where('pay_type', $pay_type)->select()->toArray(); - if ($pay_type == 18) { - $category_title = 'system_purchase_add'; - $title = '系统增加采购款'; - $mark = '系统增加采购款'; - $filed = 'purchase_funds'; - } else { - $category_title = 'system_balance_add'; - $title = '系统增加余额'; - $mark = '系统反余额冻结'; - $filed = 'now_money'; - } - - $newArr = []; - foreach ($vipFrozen as $k => $value) { - $user_funds = User::where('id', $value['user_id'])->value($filed); - $newArr[$k]['uid'] = $value['user_id']; - $newArr[$k]['category'] = $category_title; - $newArr[$k]['link_type'] = 'order'; - $newArr[$k]['link_id'] = $value['order_id']; - $newArr[$k]['amount'] = $value['number']; - $newArr[$k]['before_balance'] = $user_funds; - $newArr[$k]['balance'] = bcadd($user_funds, $value['number'], 2); - $newArr[$k]['create_time'] = date('Y-m-d H:i:s'); - $newArr[$k]['type'] = 'in'; - $newArr[$k]['title'] = $title . "{$value['number']}元"; - $newArr[$k]['mark'] = $mark; - } - (new CapitalFlow())->saveAll($newArr); - - } - - -} \ No newline at end of file diff --git a/app/api/controller/LiuController.php b/app/api/controller/LiuController.php index b70056582..1560f7d58 100644 --- a/app/api/controller/LiuController.php +++ b/app/api/controller/LiuController.php @@ -27,7 +27,7 @@ use app\common\model\system_store\SystemStore; use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; -use app\common\model\user\UserShip; +use app\common\model\user_ship\UserShip; use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use app\common\service\pay\PayService; diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index 0f0346d9b..e9ad6d214 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -40,15 +40,19 @@ class CartController extends BaseApiController return $this->fail('购物车商品不能大于100个,请先结算'); } //数量下单判断 - $stock = StoreBranchProduct::where( - ['product_id'=>$params['product_id'], - 'store_id'=>$params['store_id'] - ])->value('stock')??0; - if ($params['cart_num'] >$stock) { - return $this->fail('库存数量不足'); - } +// $stock = StoreBranchProduct::where( +// ['product_id'=>$params['product_id'], +// 'store_id'=>$params['store_id'] +// ])->value('stock')??0; +// if ($params['cart_num'] >$stock) { +// return $this->fail('库存数量不足'); +// } if ($result) { - $res = CartLogic::edit($params); + if(isset($params['type']) && $params['type'] == 1){ + $res = CartLogic::add($params); + }else{ + $res = CartLogic::edit($params); + } } else { $res = CartLogic::add($params); } diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index bb8b584d6..a72a22068 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -99,6 +99,21 @@ class OrderController extends BaseApiController return $this->data($res); } + public function checkInventory() + { + $params = (new OrderValidate())->post()->goCheck('cart'); + $res = OrderLogic::checkLeft($params, $this->userId); + if (!$res) { + $msg = OrderLogic::getError(); + if ($msg == '购物车为空') { + return $this->data([]); + } + return $this->fail(OrderLogic::getError()); + } + return $this->data($res); + } + + /** * 创建订单 */ @@ -131,7 +146,6 @@ class OrderController extends BaseApiController } $order = OrderLogic::createOrder($cartId, $addressId, $user, $params); - if ($order != false) { if ($order['pay_price'] <= 0) { $pay_type = 3; @@ -235,6 +249,10 @@ class OrderController extends BaseApiController } switch ($pay_type) { + case PayEnum::PURCHASE_FUNDS: + //采购款支付 + PayNotifyLogic::handle('purchase_funds', $order['order_id']); + return $this->success('采购款支付成功'); case PayEnum::BALANCE_PAY: //余额支付 PayNotifyLogic::handle('balancePay', $order['order_id']); diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index 698fe944c..61410d882 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -110,7 +110,7 @@ class StoreController extends BaseApiController $order['pay_price']=$order['price']; $result = PaymentLogic::codepay($auth_code, $order,'条码支付'); if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); + return $this->fail(PaymentLogic::getError()); } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index 08c0bbbc2..e66171fde 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -3,6 +3,8 @@ namespace app\api\controller\user; use app\api\controller\BaseApiController; +use app\api\lists\user_sign\UserSignLists; +use app\api\lists\user_sign_log\UserSignLogLists; use app\api\logic\user\UserLogic; use app\api\service\UserTokenService; use app\api\validate\UserValidate; @@ -10,6 +12,7 @@ use app\common\enum\PayEnum; use app\common\logic\PaymentLogic; use app\common\model\user\User; use app\common\model\user\UserAddress; +use app\common\model\user_ship\UserShip; use app\common\model\user_sign\UserSign; use support\Cache; use think\Exception; @@ -245,6 +248,21 @@ class UserController extends BaseApiController } + /** + * 礼品券/冻结券 + */ + public function userSing() + { + (new UserValidate())->get()->goCheck('fund'); + $type = (int)$this->request->get('type', 1); + if($type==1){ + return $this->dataLists(new UserSignLists()); + }else{ + return $this->dataLists(new UserSignLogLists()); + } + + } + /** * 用户信息 */ @@ -262,10 +280,11 @@ class UserController extends BaseApiController $brigade_name=Db::name('geo_brigade')->where('id',$address['brigade'])->value('brigade_name'); $address['address_like']=$city_name.$area_name.$street_name.$village_name.$brigade_name; } + $user['ship_name']=$user['user_ship']>0?UserShip::where('id',$user['user_ship'])->value('title'):''; $user['address_info']=$address; return $this->success('ok',$user->toArray()); }else{ - return $this->fail('用户不存在'); + return $this->fail('用户不存在',[],0,0); } } return $this->success('ok',[]); diff --git a/app/api/controller/user_product_storage/UserProductStorageController.php b/app/api/controller/user_product_storage/UserProductStorageController.php new file mode 100644 index 000000000..806a56204 --- /dev/null +++ b/app/api/controller/user_product_storage/UserProductStorageController.php @@ -0,0 +1,46 @@ +dataLists(new UserProductStorageLists()); + } + + /** + * 预约 + */ + public function reservation(){ + + $params=$this->request->post(); + $info=$params['info']; + $uid=$this->userId; + $store_id=$params['store_id']; + $times=$params['times']; + UserProductStorageLogic::supply($info,$uid,$store_id,0,$times); + if(UserProductStorageLogic::hasError()){ + return $this->fail(UserProductStorageLogic::getError()); + } + return $this->success('操作成功'); + } +} \ No newline at end of file diff --git a/app/api/lists/BaseApiDataLists.php b/app/api/lists/BaseApiDataLists.php index 38d01a3a0..5077e6d0b 100644 --- a/app/api/lists/BaseApiDataLists.php +++ b/app/api/lists/BaseApiDataLists.php @@ -8,7 +8,7 @@ abstract class BaseApiDataLists extends BaseDataLists protected array $userInfo = []; protected int $userId = 0; - public string $export; + // public string $export; public function __construct() { @@ -17,7 +17,7 @@ abstract class BaseApiDataLists extends BaseDataLists $this->userInfo = $this->request->userInfo; $this->userId = $this->request->userId; } - $this->export = $this->request->get('export', ''); + // $this->export = $this->request->get('export', ''); } diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index e97c09067..410e066f4 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -8,6 +8,7 @@ use app\common\lists\ListsSearchInterface; 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; /** @@ -56,6 +57,9 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface ->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time,old_cart_id,cart_info')->limit(3)->select() ->each(function ($v) use ($item) { $find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $item['store_id'])->withTrashed()->find(); + if(empty($find)){ + $find = StoreProduct::where('id', $v['product_id'])->withTrashed()->find(); + } $v['store_name'] = $find['store_name']; $v['image'] = $find['image']; // $v['price'] = $find['price']; diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index 9d299fedd..422e96207 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -89,10 +89,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L }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'; + $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']) diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index 52bef3231..4462b893b 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -5,6 +5,8 @@ namespace app\api\lists\store; use app\admin\lists\BaseAdminDataLists; use app\common\enum\YesNoEnum; +use app\common\model\order\Cart; +use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; use app\MyBusinessException; @@ -48,9 +50,10 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac { $latitude = $this->request->get('latitude',''); $longitude = $this->request->get('longitude',''); - if(empty($longitude) || empty($latitude)){ - throw new Exception('缺失经纬度'); - } + $cart_id = $this->request->get('cart_id',''); +// if(empty($longitude) || empty($latitude)){ +// throw new Exception('缺失经纬度'); +// } $where[]=['is_show','=',YesNoEnum::YES]; $data = SystemStore::where($this->searchWhere)->where($where) ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', @@ -61,10 +64,41 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac ->order(['id' => 'desc']) ->select() ->toArray(); + if($cart_id){ + if($latitude && $longitude){ + $cart_id = explode(',',$cart_id); + $cart_select = Cart::whereIn('id', $cart_id) + ->field('id,product_id,cart_num,store_id')->select()->toArray(); + foreach ($cart_select as $v) { + foreach ($data as &$values){ + $store = StoreBranchProduct::where([ + 'store_id'=>$values['id'], + 'product_id'=>$v['product_id'], + ])->field('id,store_name,stock')->withTrashed()->find(); + if(empty($store)){ + $store['stock'] =0; + } + $values['reservation'] = 0; + if($store['stock'] < $v['cart_num']){ + $values['reservation'] = 1; + } + $values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude); + } - foreach ($data as &$value){ - $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); + } + }else{ + foreach ($data as &$values){ + $values['distance'] = 0; + } + } + + }else{ + foreach ($data as &$value){ + $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); + + } } + usort($data, function ($a, $b) { return $a['distance'] <=> $b['distance']; }); diff --git a/app/api/lists/user/UserRechargeLists.php b/app/api/lists/user/UserRechargeLists.php index 62521a687..8c2703bf0 100644 --- a/app/api/lists/user/UserRechargeLists.php +++ b/app/api/lists/user/UserRechargeLists.php @@ -8,6 +8,7 @@ use app\common\model\user\UserFeedback; use app\common\model\user_label\UserLabel; use app\common\model\user_recharge\UserRecharge; +use app\common\model\user_ship\UserShip; //用户充值表 class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface @@ -44,11 +45,14 @@ use app\common\model\user_recharge\UserRecharge; ->order(['id' => 'desc']) ->select()->each(function($data){ $data['label_name']=''; + $data['ship_name']=''; + $data['mobile']=''; if($data['recharge_type']=='INDUSTRYMEMBERS'){ $find =User::where('id',$data['uid'])->find(); $data['real_name']=$find['real_name']??''; - if($find &&$find['label_id']>0){ - $data['label_name']=UserLabel::where('label_id',$find['label_id'])->value('label_name'); + if($find &&$find['user_ship']>0){ + $data['ship_name']=UserShip::where('id',$find['user_ship'])->value('title'); + $data['mobile']=$find['mobile']; } }else{ $data['real_name'] =User::where('id',$data['uid'])->value('real_name'); diff --git a/app/api/lists/user_create_log/UserCreateLogLists.php b/app/api/lists/user_create_log/UserCreateLogLists.php index 9b1a89eff..fc9d05a73 100644 --- a/app/api/lists/user_create_log/UserCreateLogLists.php +++ b/app/api/lists/user_create_log/UserCreateLogLists.php @@ -8,6 +8,7 @@ use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; use app\common\model\user\User; use app\common\model\user_create_log\UserCreateLog; +use app\common\model\user_ship\UserShip; /** * 用户前端添加记录列表 @@ -48,8 +49,16 @@ class UserCreateLogLists extends BaseAdminDataLists implements ListsSearchInterf ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item){ + $item['ship_name']=''; + $item['mobile']=''; + $item['nickname']=''; + $find =User::where('id',$item['uid'])->find(); + if($find &&$find['user_ship']>0){ + $item['ship_name']=UserShip::where('id',$find['user_ship'])->value('title'); + $item['mobile']=$find['mobile']; + $item['nickname'] = User::where('id',$item['uid'])->value('real_name'); + } $item['system_store_name'] = SystemStore::where('id',$item['store_id'])->value('name'); - $item['nickname'] = User::where('id',$item['uid'])->value('real_name'); $item['create_nickname'] = User::where('id',$item['create_uid'])->value('real_name'); }) ->toArray(); diff --git a/app/api/lists/user_product_storage/UserProductStorageLists.php b/app/api/lists/user_product_storage/UserProductStorageLists.php new file mode 100644 index 000000000..674f9e6e9 --- /dev/null +++ b/app/api/lists/user_product_storage/UserProductStorageLists.php @@ -0,0 +1,92 @@ + ['oid', 'product_id'], + 'between_time' => 'create_time', + ]; + } + + + /** + * @notes 获取用户商品储存列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/06/28 11:05 + */ + public function lists(): array + { + $status=$this->request->get('status',1); + if($status==1){ + $this->searchWhere[]=['status','=',1];//只显示正常状态的记录,不显示已出库完的记录 + $field='id,uid,oid,product_id,sum(nums) nums,status,create_time'; + $group='product_id'; + }else{ + $field='id,uid,oid,product_id,nums,status,create_time'; + $group=null; + } + $this->searchWhere[]=['uid','=',$this->userId]; + return UserProductStorage::where($this->searchWhere) + ->field($field) + ->group($group) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $user=User::where('id',$item['uid'])->field('nickname,real_name')->find(); + $item['nickname']=$user['real_name']?$user['real_name'].'|'.$item['uid']:$user['nickname'].'|'.$item['uid']; + $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,price')->find(); + $item['store_name']=$find['store_name']; + $item['image']=$find['image']; + $item['price']=$find['price']; + if($item['status']==1){ + $item['status_name']='正常'; + }else{ + $item['status_name']='已出库完'; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取用户商品储存数量 + * @return int + * @author admin + * @date 2024/06/28 11:05 + */ + public function count(): int + { + return UserProductStorage::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/user_sign/UserSignLists.php b/app/api/lists/user_sign/UserSignLists.php new file mode 100644 index 000000000..b1ffe274c --- /dev/null +++ b/app/api/lists/user_sign/UserSignLists.php @@ -0,0 +1,88 @@ +request->get('type',1); + $mark=$this->request->get('mark',''); + if($type==1){ + $this->searchWhere[]=['type','in',[4,9,8,2,3]]; + $this->searchWhere[]=['status','=',1]; + } + if($mark==1){ + $this->searchWhere[]=['financial_pm','=',1]; + }elseif($mark==2){ + $this->searchWhere[]=['financial_pm','=',0]; + } + $this->searchWhere[]=['uid','=',$this->userId]; + $list=UserSign::where($this->searchWhere)->order('id desc') + ->limit($this->limitOffset, $this->limitLength) + ->select()->each(function ($item){ + if($item['order_type']==0){ + $price=UserRecharge::where('order_id',$item['order_id'])->value('price')??0; + }else{ + $price=StoreOrder::where('order_id',$item['order_id'])->value('pay_price')??0; + } + $item['title']=UserSignLogic::getTitle($item['type'],$price,$item['number']); + return $item; + }); + return $list?->toArray(); + + } + + + /** + * @notes 获取用户标签数量 + * @return int + * @author admin + * @date 2024/06/17 17:02 + */ + public function count(): int + { + return UserSign::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/user_sign_log/UserSignLogLists.php b/app/api/lists/user_sign_log/UserSignLogLists.php new file mode 100644 index 000000000..907c707a2 --- /dev/null +++ b/app/api/lists/user_sign_log/UserSignLogLists.php @@ -0,0 +1,86 @@ +request->get('type',1); + $mark=$this->request->get('mark',''); + if($type==1){ + $this->searchWhere[]=['type','in',[1,7,3]]; + $this->searchWhere[]=['status','=',1]; + } + if($mark==1){ + $this->searchWhere[]=['financial_pm','=',1]; + }elseif($mark==2){ + $this->searchWhere[]=['financial_pm','=',0]; + } + $this->searchWhere[]=['uid','=',$this->userId]; + $list=UserSignLog::where($this->searchWhere)->order('id desc') + ->limit($this->limitOffset, $this->limitLength) + ->select()->each(function ($item){ + if($item['order_type']==0){ + $price=UserRecharge::where('order_id',$item['order_id'])->value('price')??0; + }else{ + $price=StoreOrder::where('order_id',$item['order_id'])->value('pay_price')??0; + } + $item['title']=UserSignLogic::getTitle($item['type'],$price,$item['number']); + return $item; + }); + return $list?->toArray(); + } + + + /** + * @notes 获取用户标签数量 + * @return int + * @author admin + * @date 2024/06/17 17:02 + */ + public function count(): int + { + return UserSignLog::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/logic/order/CartLogic.php b/app/api/logic/order/CartLogic.php index 8afb470ba..9b2d32d14 100644 --- a/app/api/logic/order/CartLogic.php +++ b/app/api/logic/order/CartLogic.php @@ -33,16 +33,29 @@ class CartLogic extends BaseLogic } Db::startTrans(); try { - $cart = Cart::create([ + //check + $check = Cart::where([ 'uid' => $params['uid'], - 'type' => $params['type']??'', + 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], - 'store_id' => $params['store_id']??0, - 'staff_id' => $params['staff_id']??0, - 'product_attr_unique' => '', - 'cart_num' => $params['cart_num'], - 'is_new' => $params['is_new']??0, - ]); + 'is_pay'=>0 + ])->field('id')->find(); + if($check){ + Cart::where('id',$check['id'])->inc('cart_num',$params['cart_num']) + ->update(); + $cart['id'] = $check['id']; + }else{ + $cart = Cart::create([ + 'uid' => $params['uid'], + 'type' => $params['type']??'', + 'product_id' => $params['product_id'], + 'store_id' => $params['store_id']??0, + 'staff_id' => $params['staff_id']??0, + 'product_attr_unique' => '', + 'cart_num' => $params['cart_num'], + 'is_new' => $params['is_new']??0, + ]); + } StoreProductLog::create([ 'type'=>'cart', 'uid' => $params['uid'], diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 2393ae4d6..9a997a7bd 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -10,6 +10,7 @@ use app\common\logic\BaseLogic; use app\common\logic\CapitalFlowLogic; use app\common\logic\PayNotifyLogic; use app\common\logic\StoreFinanceFlowLogic; +use app\common\logic\UserSignLogic; use app\common\model\Config; use app\common\model\dict\DictData; use app\common\model\dict\DictType; @@ -25,7 +26,7 @@ use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; use app\common\model\user\UserAddress; -use app\common\model\user\UserShip; +use app\common\model\user_ship\UserShip; use app\common\model\user_sign\UserSign; use app\common\model\user_spread_log\UserSpreadLog; use Picqer\Barcode\BarcodeGeneratorJPG; @@ -50,8 +51,9 @@ class OrderLogic extends BaseLogic public static $pay_price; public static $cost; public static $profit; - public static $store_price;//门店零售价 + public static $store_price; //门店零售价 public static $activity_price; + public static $deduction_price; /** * @notes 获取购物车商品信息 @@ -60,7 +62,6 @@ class OrderLogic extends BaseLogic */ static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = []) { - $where = ['is_pay' => 0]; $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); if (empty($cart_select)) { @@ -74,41 +75,49 @@ class OrderLogic extends BaseLogic self::$profit = 0; //利润 self::$activity_price = 0; //活动减少 self::$store_price = 0; //门店零售价 + self::$deduction_price =0; + $deduction_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'; + $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'; 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) { - 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;//缺货标识 } unset($cart_select[$k]['id']); - if($off_activity==1){ - $price=$find['cost']; - }else{ - $price=$find['price']; + $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 + if ($off_activity == 1) { + $price = $find['cost']; + } else { + $price = $find['price']; } $cart_select[$k]['price'] = $price; $cart_select[$k]['cost'] = $find['cost']; - $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 - $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 $cart_select[$k]['vip'] = 0; //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $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售价 - + $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;//抵扣金额 + } $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'] ?? ''; //vip1待返回金额 - $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'] ); + // 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']; $cartInfo['image'] = $find['image']; @@ -122,20 +131,21 @@ class OrderLogic extends BaseLogic self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); - self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 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::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); } //加支付方式限制 - $pay_type = isset($params['pay_type'])?$params['pay_type']:0; - if ($user && $user['user_ship'] == 1 && $pay_type !=17) { + $pay_type = isset($params['pay_type']) ? $params['pay_type'] : 0; + 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); //减去活动优惠金额 + } else { + $pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 } -// if($pay_price < 500){ -// throw new Exception('金额低于500'); -// } + // if($pay_price < 500){ + // throw new Exception('金额低于500'); + // } //成本价 收益 $order = [ @@ -153,24 +163,43 @@ class OrderLogic extends BaseLogic 'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 ,2=门店自提 'activity' => '减免', 'activity_price' => self::$activity_price, - 'activities' => self::$activity_price>0?1:0, - 'deduction_price' => self::$activity_price, - 'is_vip' => 0, - 'is_storage' => $params['is_storage']??0, + 'activities' => self::$activity_price > 0 ? 1 : 0, + 'deduction_price' => self::$deduction_price, + 'source' => 0, + 'is_storage' => $params['is_storage'] ?? 0, ]; $order['default_delivery'] = 0; if ($params['store_id']) { $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send'); } - if($user && $user['user_ship']>=1 &&$user['user_ship']<=3){ - $order['is_vip'] = 1; - + if (isset($params['source']) && $params['source'] > 0) { + $order['source'] = $params['source']; + } + //处理返回最近的店铺 + if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) { + $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); + $nearestStore = null; + $minDistance = PHP_FLOAT_MAX; + foreach ($storeAll as $value) { + $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $params['lat'], $params['long']); + if ($value['distance'] < $minDistance) { + $minDistance = $value['distance']; + $nearestStore = $value; + } + } + $store['near_store'] =[]; + if ($nearestStore) { + $store['near_store'] = $nearestStore; + } + }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()??[]; } } catch (\Exception $e) { self::setError($e->getMessage()); return false; } - return ['order' => $order, 'cart_list' => $cart_select]; + return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store']]; } /** @@ -180,28 +209,29 @@ class OrderLogic extends BaseLogic static public function createOrder($cartId, $addressId, $user = null, $params = []) { $order_id = getNewOrderId('PF'); - $code = rand(1,10).'-'.substr($order_id, -5); + $code = rand(1, 10) . '-' . substr($order_id, -5); $verify_code = createCode($code); $params['order_id'] = $order_id; - $params['verify_code'] =$verify_code; + $params['verify_code'] = $verify_code; $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params); if (!$orderInfo) { return false; } - $uid=$user['id']??0; + $uid = $user['id'] ?? 0; $_order = $orderInfo['order']; $_order['uid'] = $uid; - $_order['spread_uid'] =$params['spread_uid']??0; - $_order['real_name'] = $user['real_name']??''; - $_order['mobile'] = $user['mobile']??''; + $_order['spread_uid'] = $params['spread_uid'] ?? 0; + $_order['real_name'] = $user['real_name'] ?? ''; + $_order['mobile'] = $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; } - if ($addressId > 0 &&$uid>0 ) { + if ($addressId > 0 && $uid > 0) { $address = UserAddress::where(['id' => $addressId, 'uid' => $uid])->find(); if ($address) { $_order['real_name'] = $address['real_name']; @@ -215,8 +245,8 @@ class OrderLogic extends BaseLogic //生成核销码 $generator = new BarcodeGeneratorPNG(); $barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128); - $findPath = '/image/barcode/'.time().'.png'; - $savePath = public_path().$findPath; + $findPath = '/image/barcode/' . time() . '.png'; + $savePath = public_path() . $findPath; file_put_contents($savePath, $barcode); $_order['verify_img'] = $findPath; Db::startTrans(); @@ -228,10 +258,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]; @@ -245,6 +275,58 @@ class OrderLogic extends BaseLogic } } + /** + * 检验丢失 + * @param $params + * @return array|false + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function checkLeft($params, $uid, $type = 0) + { + $where = []; + if (empty($type)) { + $where = ['is_pay' => 0]; + } + $cart_select = Cart::whereIn('id', $params['cart_id']) + ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); + if (empty($cart_select)) { + self::setError('购物车为空'); + return false; + } + $newArr = []; + //检查购物车对比店铺得商品数量差异 + foreach ($cart_select as $v) { + $store = StoreBranchProduct::where([ + 'store_id' => $params['store_id'], + 'product_id' => $v['product_id'], + ])->field('id,store_name,stock')->withTrashed()->find(); + if (empty($store)) { + $store['stock'] = 0; + } + if ($store['stock'] < $v['cart_num']) { + //缺失 + $newArr[] = [ + 'uid' => $uid, + 'store_id' => $params['store_id'], + 'product_id' => $v['product_id'], + 'missing_quantity' => $v['cart_num'] - $store['stock'] + ]; + } + } + + if ($newArr) { + return [ + 'detail' => $newArr, + 'reservation' => 1 + ]; + } + return [ + 'detail' => [], + 'reservation' => 0 + ]; + } /** * @notes 获取订单号 @@ -313,7 +395,7 @@ class OrderLogic extends BaseLogic $data = []; foreach ($arr as $k => $v) { $data[$k]['product_id'] = $v['product_id']; -// $unique = StoreProductAttrValue::where('product_id', $v['product_id'])->value('v'); + // $unique = StoreProductAttrValue::where('product_id', $v['product_id'])->value('v'); $data[$k]['product_attr_unique'] = ''; $data[$k]['cart_num'] = $v['cart_num']; $data[$k]['type'] = ''; @@ -338,7 +420,7 @@ class OrderLogic extends BaseLogic } - public static function detail($params,$url='',$param=[]): array + public static function detail($params, $url = '', $param = []): array { $find = StoreOrder::where($params)->findOrEmpty()->toArray(); if ($find) { @@ -346,6 +428,9 @@ 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)){ + $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); + } $item['store_name'] = $find['store_name']; $item['image'] = $find['image']; $item['price'] = $find['price']; @@ -357,26 +442,24 @@ class OrderLogic extends BaseLogic $store = SystemStore::where('id', $find['store_id'])->field('id,name,phone,address,detailed_address')->find(); $find['store_info'] = $store; - if($find['verify_img']){ - $find['verify_img'] = $url.$find['verify_img']; + if ($find['verify_img']) { + $find['verify_img'] = $url . $find['verify_img']; } //处理返回最近的店铺 - if($param['lat'] && $param['long']){ + if ($param['lat'] && $param['long']) { $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); $nearestStore = null; $minDistance = PHP_FLOAT_MAX; - foreach ($storeAll as $value){ - $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$param['lat'] ,$param['long']); + foreach ($storeAll as $value) { + $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $param['lat'], $param['long']); if ($value['distance'] < $minDistance) { $minDistance = $value['distance']; $nearestStore = $value; } } if ($nearestStore) { - $find['near_store'] =$nearestStore; - + $find['near_store'] = $nearestStore; } - } } return $find; @@ -417,44 +500,47 @@ class OrderLogic extends BaseLogic Db::startTrans(); try { StoreOrder::update([ - 'verify_code'=>$params['verify_code'].'-1', + 'verify_code' => $params['verify_code'] . '-1', 'status' => OrderEnum::RECEIVED_GOODS, 'is_writeoff' => OrderEnum::IS_OK, 'update_time' => time(), 'store_id' => $params['store_id'], - 'staff_id' => $params['staff_id']??0, + 'staff_id' => $params['staff_id'] ?? 0, ], ['id' => $order['id']]); (new StoreOrderCartInfo())->update([ - 'verify_code'=>$params['verify_code'].'-1', + 'verify_code' => $params['verify_code'] . '-1', 'writeoff_time' => time(), 'is_writeoff' => YesNoEnum::YES, 'store_id' => $params['store_id'], - 'staff_id' => $params['staff_id']??0, + 'staff_id' => $params['staff_id'] ?? 0, 'update_time' => time(), ], ['oid' => $order['id']]); PayNotifyLogic::descStock($order['id']); - $financeFlow=new StoreFinanceFlow(); - $financeFlowLogic=new StoreFinanceFlowLogic(); - $select_1=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>['in'=>14,15,16]])->select(); - foreach($select_1 as $k=>$v){ - if($v['other_uid']>0){ - $financeFlowLogic->updateStatusUser($v['id'],$v['other_uid'],$v['number'],$v['order_id']); + $financeFlow = new StoreFinanceFlow(); + $financeFlowLogic = new StoreFinanceFlowLogic(); + $select_1 = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => ['in' => 14, 15, 16]])->select(); + foreach ($select_1 as $k => $v) { + if ($v['other_uid'] > 0) { + $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); } } - if($order['uid'] && $order['pay_price'] >= 500){ - $user_number = bcmul($order['pay_price'], '0.10', 2); - User::where('id', $order['uid'])->inc('integral', $user_number)->update(); - UserSign::where(['uid' => $order['uid'],'order_id' => $order['order_id']])->update(['status'=>1]); - } if ($order['spread_uid'] > 0) { - $spread_find=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>12,'other_uid'=>$order['spread_uid']])->find(); - if($spread_find){ - $financeFlowLogic->updateStatusUser($spread_find['id'],$order['spread_uid'],$spread_find['number'],$order['order_id']); + $spread_find = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 12, 'other_uid' => $order['spread_uid']])->find(); + if ($spread_find) { + $financeFlowLogic->updateStatusUser($spread_find['id'], $order['spread_uid'], $spread_find['number'], $order['id']); } } - $deposit=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>11])->value('number')??0; - $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); + $deposit = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 11])->value('number') ?? 0; + $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); + //积分结算 + $user_ship=-1; + if($order['uid']){ + $user_ship=User::where('id',$order['uid'])->value('user_ship'); + } + if($order['is_storage']==0&&$order['source']==0&&in_array($user_ship,[0,4])){ + UserSignLogic::WriteOff($order); + } Db::commit(); return true; } catch (\Exception $e) { @@ -476,19 +562,19 @@ class OrderLogic extends BaseLogic Db::startTrans(); try { StoreOrder::update([ - 'verify_code'=>$params['verify_code'].'-1', + 'verify_code' => $params['verify_code'] . '-1', 'status' => OrderEnum::RECEIVED_GOODS, 'is_writeoff' => OrderEnum::IS_OK, 'update_time' => time(), 'store_id' => $params['store_id'], - 'staff_id' => $params['staff_id']??0, + 'staff_id' => $params['staff_id'] ?? 0, ], ['id' => $data['id']]); (new StoreOrderCartInfo())->update([ - 'verify_code'=>$params['verify_code'].'-1', + 'verify_code' => $params['verify_code'] . '-1', 'writeoff_time' => time(), 'is_writeoff' => YesNoEnum::YES, 'store_id' => $params['store_id'], - 'staff_id' => $params['staff_id']??0, + 'staff_id' => $params['staff_id'] ?? 0, 'update_time' => time(), ], ['oid' => $data['id']]); // $financeFlow = (new StoreFinanceFlowLogic)->getStoreOrder($data['id'], $data['store_id']); @@ -496,7 +582,7 @@ class OrderLogic extends BaseLogic // $capitalFlowLogic = new CapitalFlowLogic($data->store, 'store'); // $capitalFlowLogic->storeIncome('store_order_income', 'order', $data['id'], $financeFlow['number']); // } - $order=StoreOrder::where('id',$data['id'])->find(); + $order = StoreOrder::where('id', $data['id'])->find(); PayNotifyLogic::descSwap($order['id']); Db::commit(); return true; diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index 9bc09a05e..67b4ee755 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -5,6 +5,7 @@ namespace app\api\logic\user; use app\api\service\UserTokenService; use app\common\{logic\BaseLogic, + logic\PayNotifyLogic, model\dict\DictData, model\finance\CapitalFlow, model\store_finance_flow\StoreFinanceFlow, @@ -15,11 +16,12 @@ use app\common\{logic\BaseLogic, model\user\User, model\user\UserAuth, model\user\UserRecharge, - model\user\UserShip, + model\user_ship\UserShip, model\user_sign\UserSign, model\vip_flow\VipFlow, service\SmsService, service\wechat\WeChatMnpService}; +use app\common\logic\UserSignLogic; use app\common\model\user_label\UserLabel; use support\Cache; use think\facade\Db; @@ -88,6 +90,7 @@ class UserLogic extends BaseLogic ->find(); //判断是不是员工 if($data){ + $GetNumber = $data['integral']; $data = $data->toArray(); $all =UserShip::field('id,title,limit')->select()->toArray(); $new = self::getNextArrayByID($all,$data['user_ship']); @@ -116,11 +119,10 @@ class UserLogic extends BaseLogic 'is_writeoff'=>0,'uid'=>$uid ])->whereIn('shipping_type',[1,2])->count(); $data['openid'] = UserAuth::where(['user_id'=>$uid,'terminal'=>1])->value('openid'); - $number=UserSign::where('uid',$uid)->where('status',0)->sum('number'); - $data['integral']=bcadd($data['integral'],$number,2); +// $number=UserSign::where('uid',$uid)->where('status',0)->sum('number'); +// $data['integral']=bcadd($data['integral'],$number,2); - $number = UserSign::where('uid',$uid)->where(['status'=>0,'financial_pm'=>1])->sum('number'); - $GetNumber = UserSign::where('uid',$uid)->where('status',1)->sum('number'); + $number = UserSign::where('uid',$uid)->where(['status'=>0])->sum('number'); $data['number'] =bcadd($number,0,2); $data['GetNumber'] =bcadd($GetNumber,0,2); }else{ @@ -242,9 +244,6 @@ class UserLogic extends BaseLogic } - - - public static function dealPayPassword($params,$uid) { $password = payPassword($params['password']); @@ -253,7 +252,6 @@ class UserLogic extends BaseLogic } - public static function dealDetails($params,$uid) { switch ($params['type']){ @@ -306,12 +304,13 @@ class UserLogic extends BaseLogic //礼品券明细 $query = UserSign::where(['uid'=>$uid]); if($params['mark'] == 1){ - $query->where('financial_pm',1); + $query->where('financial_pm',1);//获得 } if($params['mark'] == 2){ $query->where('financial_pm',0); } $count = $query->count(); + //todo 有就拿有得 没得就去获取对应得文本内容 $data =$query ->page($params['page_no'],$params['page_size']) ->order('id','desc') diff --git a/app/api/validate/OrderValidate.php b/app/api/validate/OrderValidate.php index f223800f6..ca8a6ec38 100644 --- a/app/api/validate/OrderValidate.php +++ b/app/api/validate/OrderValidate.php @@ -23,6 +23,8 @@ class OrderValidate extends BaseValidate 'id' => 'require|number', 'old_cart_id' => 'require|array', 'refund_type' => 'require|number', + 'cart_id' => 'require', + 'store_id' => 'require', ]; @@ -37,8 +39,15 @@ class OrderValidate extends BaseValidate 'id' => '订单id', 'old_cart_id' => '购物车id', 'refund_type' => '退款申请类型', + 'cart_id' => '购物车id', + 'store_id' => '店铺id', ]; + public function sceneCart() + { + return $this->only(['cart_id','store_id']); + } + /** * @notes 添加场景 diff --git a/app/common/lists/user/UserShipLists.php b/app/common/lists/user/UserShipLists.php index 5b4614510..55672fc82 100644 --- a/app/common/lists/user/UserShipLists.php +++ b/app/common/lists/user/UserShipLists.php @@ -5,7 +5,7 @@ namespace app\common\lists\user; use app\admin\lists\BaseAdminDataLists; -use app\common\model\user\UserShip; +use app\common\model\user_ship\UserShip; /** * 会员类型 @@ -37,12 +37,14 @@ class UserShipLists extends BaseAdminDataLists public function lists(): array { - $field = "id,title"; + $field = "id,title,limit"; $arr=[]; - if($this->request->__get('id')){ - $this->searchWhere[]=['id','in',[1,4]]; - }else{ - $arr[]=['id'=>0,'title'=>'一般用户']; + if(!$this->request->__get('id')){ + $arr[]=['id'=>0,'title'=>'一般用户','limit'=>0]; + } + $type_id=$this->request->get('type_id',0); + if($type_id!=4){ + $this->searchWhere[]=['id','<>',4]; } $lists = UserShip::where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) diff --git a/app/common/logic/BackLogic.php b/app/common/logic/BackLogic.php new file mode 100644 index 000000000..1187b28d2 --- /dev/null +++ b/app/common/logic/BackLogic.php @@ -0,0 +1,120 @@ +=', $startTime) + ->where('create_time', '<', $endTime) + ->where('status', 0) + ->where('type', 0) + ->select(); + //3余额 18采购款 7微信小程序 9微信条码 13 支付宝条码支付 + foreach ($result as $row) { + switch ($row['pay_type']) { + case 3: + case 18: + $this->dealCapital($row['pay_type'],$row); + break; + case 7: + case 9: + $this->wechat_refund($row['pay_type'],$row); + break; + case 13: + $this->ali_pay_refund($row['pay_type'],$row); + break; + } + } + //7微信小程序 9微信条码 13 支付宝条码支付 + + + } + + public function dealCapital($pay_type, $order) + { + + $user = User::where('id', $order['user_id'])->find(); + if ($pay_type == 18) { + $category_title = 'system_purchase_add'; + $title = '系统增加采购款'; + $mark = '系统增加采购款'; + $filed = 'purchase_funds'; + $user->purchase_funds = bcadd($user['purchase_funds'], $order['number'], 2); + } else { + $category_title = 'system_balance_add'; + $title = '系统增加余额'; + $mark = '系统反余额冻结'; + $filed = 'now_money'; + $user->now_money = bcadd($user['now_money'], $order['number'], 2); + } + $user->save(); + $newArr['uid'] = $order['user_id']; + $newArr['category'] = $category_title; + $newArr['link_type'] = 'order'; + $newArr['link_id'] = $order['order_id']; + $newArr['amount'] = $order['number']; + $newArr['before_balance'] = $user[$filed]; + $newArr['balance'] = bcadd($user[$filed], $order['number'], 2); + $newArr['create_time'] = date('Y-m-d H:i:s'); + $newArr['type'] = 'in'; + $newArr['title'] = $title . "{$order['number']}元"; + $newArr['mark'] = $mark; + CapitalFlow::create($newArr); + } + + public function wechat_refund($pay_type, $row){ + $pay_price=StoreOrder::where('id',$row['order_id'])->value('pay_price'); + $order = [ + 'out_trade_no' => (string)$row['order_sn'], + 'out_refund_no' => time(), + 'reason' => '待返还金返还', + 'amount' => [ + 'refund' => bcmul($row['number'], 100), + 'total' => bcmul($pay_price, 100), + 'currency' => 'CNY', + ], + ]; + try{ + $this->payService->wechat->refund($order); + VipFlow::where('id',$row['id'])->update(['status'=>1]); + }catch (\Exception $e){ + Log::error('微信退款失败'.$e->getMessage(),$row->toArray()); + } + } + + public function ali_pay_refund($pay_type, $row){ + $order = [ + 'out_trade_no' => (string)$row['order_sn'], + 'refund_reason' => '待返还金返还', + 'refund_amount' => $row['number'], + ]; + try{ + $this->payService->alipay->refund($order); + VipFlow::where('id',$row['id'])->update(['status'=>1]); + }catch (\Exception $e){ + Log::error('支付宝退款失败'.$e->getMessage(),$row->toArray()); + } + } +} diff --git a/app/common/logic/CommissionLogic.php b/app/common/logic/CommissionLogic.php index 7777efc1b..f866f4a8c 100644 --- a/app/common/logic/CommissionLogic.php +++ b/app/common/logic/CommissionLogic.php @@ -12,63 +12,62 @@ class CommissionLogic extends BaseLogic /** * 走村长分润 */ - public static function setVillage($order,$village_uid=0,$brigade_uid=0, $transaction_id=0) + public static function setVillage($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) { - $user_1=self::user($order, 0.05, $transaction_id,$village_uid,14);//村长 - $user_2=self::user($order, 0.03, $transaction_id,0,12);//会员、厨师 - $user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 + $user_1 = self::user($order, 0.05, $transaction_id, $village_uid, 14); //村长 + $user_2 = self::user($order, 0.03, $transaction_id, 0, 12); //会员、厨师 + $user_3 = self::user($order, 0.01, $transaction_id, $brigade_uid, 15); //队长 - $platform=self::platform($order, 0.02, $transaction_id);//平台 - $store=self::store($order, 0.05, $transaction_id,0);//门店 - $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他 + $platform = self::platform($order, 0.02, $transaction_id); //平台 + $store = self::store($order, 0.05, $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,$user_4,2),2); + $moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2); self::suppliter($order, $moeny, $transaction_id); } /** * 走队长分润 */ - public static function setBrigade($order,$village_uid=0,$brigade_uid=0, $transaction_id=0) + public static function setBrigade($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) { - $user_1=self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长 - $user_2=self::user($order, 0.03, $transaction_id,0,12);////会员、厨师 - $user_3=self::user($order, 0.01, $transaction_id,$village_uid,15);//村长 + $user_1 = self::user($order, 0.05, $transaction_id, $brigade_uid, 14); //队长 + $user_2 = self::user($order, 0.03, $transaction_id, 0, 12); ////会员、厨师 + $user_3 = self::user($order, 0.01, $transaction_id, $village_uid, 15); //村长 - $platform=self::platform($order, 0.02, $transaction_id);//平台 - $store=self::store($order, 0.05, $transaction_id,0);//门店 - $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他 + $platform = self::platform($order, 0.02, $transaction_id); //平台 + $store = self::store($order, 0.05, $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,$user_4,2),2); + $moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2); self::suppliter($order, $moeny, $transaction_id); } /** * 走厨师分润 */ - public static function setCook($order,$village_uid=0,$brigade_uid=0, $transaction_id=0) + public static function setCook($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) { - $user_1=self::user($order, 0.07, $transaction_id,0,12);//会员、厨师 - $user_2=self::user($order, 0.01, $transaction_id,$village_uid,14);//村长 - $user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 + $user_1 = self::user($order, 0.07, $transaction_id, $order['spread_uid'], 12); //会员、厨师 + $user_2 = self::user($order, 0.01, $transaction_id, $village_uid, 14); //村长 + $user_3 = self::user($order, 0.01, $transaction_id, $brigade_uid, 15); //队长 - $platform=self::platform($order, 0.02, $transaction_id);//平台 - $store=self::store($order, 0.05, $transaction_id,0);//门店 - $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他 + $platform = self::platform($order, 0.02, $transaction_id); //平台 + $store = self::store($order, 0.05, $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,$user_4,2),2); + $moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2); self::suppliter($order, $moeny, $transaction_id); } /** * 走线下分润 */ - public static function setStore($order, $transaction_id=0) + public static function setStore($order, $transaction_id = 0) { - $platform= self::platform($order, 0.05, $transaction_id);//平台 - $store= self::store($order, 0.02, $transaction_id,0);//门店 - $user= self::user($order, 0.01, $transaction_id,0,16);//其他 - $moeny=bcadd(bcadd($platform,$store,2),$user,2); - self::suppliter($order, $moeny, $transaction_id); - + $platform = self::platform($order, 0.05, $transaction_id); //平台 + $store = self::store($order, 0.02, $transaction_id, 0); //门店 + $attrition = self::attrition($order, 0.01,$transaction_id,16); //损耗 + $moeny = bcadd(bcadd($platform, $store, 2), $attrition, 2); + self::suppliter($order, $moeny, $transaction_id); } @@ -78,11 +77,11 @@ class CommissionLogic extends BaseLogic public static function platform($order, $platformRate, $transaction_id) { $financeLogic = new StoreFinanceFlowLogic(); - $financeLogic->order=$order; - $financeLogic->user['uid']=$order['uid']; + $financeLogic->order = $order; + $financeLogic->user['uid'] = $order['uid']; $fees = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2); if ($fees > 0) { - $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 + $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 $financeLogic->save(); } @@ -94,11 +93,11 @@ class CommissionLogic extends BaseLogic public static function suppliter($order, $platformRate, $transaction_id) { $financeLogic = new StoreFinanceFlowLogic(); - $financeLogic->order=$order; - $financeLogic->user['uid']=$order['uid']; - $fees = bcsub($order['pay_price'], $platformRate,2); + $financeLogic->order = $order; + $financeLogic->user['uid'] = $order['uid']; + $fees = bcsub($order['pay_price'], $platformRate, 2); if ($fees > 0) { - $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 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(); } @@ -106,12 +105,12 @@ class CommissionLogic extends BaseLogic /** * 门店分润 */ - public static function store($order, $platformRate, $transaction_id,$uid) + public static function store($order, $platformRate, $transaction_id, $uid) { $financeLogic = new StoreFinanceFlowLogic(); - $financeLogic->user['uid']=$order['uid']; - $financeLogic->other_arr['vip_uid']=$uid; - $financeLogic->order=$order; + $financeLogic->user['uid'] = $order['uid']; + $financeLogic->other_arr['vip_uid'] = $uid; + $financeLogic->order = $order; $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 //缴纳齐全了就加商户没有就加到平台 @@ -123,7 +122,7 @@ class CommissionLogic extends BaseLogic 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']); //平台手续费 + $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } else { $money = bcsub($store_profit, $deposit, 2); @@ -133,13 +132,13 @@ class CommissionLogic extends BaseLogic } 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']); //平台手续费 + $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 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']); //平台手续费 + $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } $financeLogic->save(); @@ -149,7 +148,7 @@ class CommissionLogic extends BaseLogic /** * 分给用户 */ - public static function user($order, $userRate, $transaction_id,$uid=0,$enum = 0) + public static function user($order, $userRate, $transaction_id, $uid = 0, $enum = 0) { $financeLogic = new StoreFinanceFlowLogic(); $fees = bcmul($order['pay_price'], $userRate, 2); @@ -160,13 +159,30 @@ class CommissionLogic extends BaseLogic $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; - $financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->user['uid'] = $order['uid']; + $financeLogic->other_arr['vip_uid'] = $uid; + $financeLogic->order = $order; + $financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->save(); } return $fees; } + + /** + * 损耗金 + */ + public static function attrition($order, $userRate, $transaction_id, $enum) + { + $financeLogic = new StoreFinanceFlowLogic(); + $financeLogic->order = $order; + $financeLogic->user['uid'] = $order['uid']; + $fees = bcmul($order['pay_price'], $userRate, 2); + if ($fees > 0) { + SystemStore::where('id', $order['store_id'])->inc('attrition', $fees)->update(); + $financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + $financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + } + return $fees; + } } diff --git a/app/common/logic/PayNotifyLogic copy.php b/app/common/logic/PayNotifyLogic copy.php index 3f641cfbc..015e4ec93 100644 --- a/app/common/logic/PayNotifyLogic copy.php +++ b/app/common/logic/PayNotifyLogic copy.php @@ -23,7 +23,7 @@ use app\common\model\system_store\SystemStore; use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; -use app\common\model\user\UserShip; +use app\common\model\user_ship\UserShip; use app\common\model\user_sign\UserSign; use app\common\service\Curl; use app\common\service\PushService; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 2f526d1de..889d6a2ae 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -2,6 +2,7 @@ namespace app\common\logic; +use app\admin\logic\user_ship\UserShipLogic; use app\api\logic\order\OrderLogic; use app\common\enum\OrderEnum; use app\common\enum\PayEnum; @@ -23,7 +24,7 @@ use app\common\model\system_store\SystemStore; use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; -use app\common\model\user\UserShip; +use app\common\model\user_ship\UserShip; use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use app\common\service\Curl; @@ -66,7 +67,6 @@ class PayNotifyLogic extends BaseLogic 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('余额不足'); @@ -95,11 +95,18 @@ 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']); - // } + if ($order['shipping_type'] == 3) { + // self::descStock($order['id']); + } self::afterPay($order); - if ($extra && $extra['store_id']) { + if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { + $checkArr = [ + 'cart_id' => $order['cart_id'], + 'store_id' => $order['store_id'], + ]; + self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); + } + if ($extra && $extra['store_id'] && $order['reservation'] !=1) { $params = [ 'verify_code' => $order['verify_code'], 'store_id' => $extra['store_id'], @@ -139,16 +146,18 @@ class PayNotifyLogic extends BaseLogic $user->integral = bcsub($user['integral'], $order['pay_price'], 2); $user->save(); //入礼品券表扣款记录 - $sing[] = [ + $sing = [ 'uid' => $order['uid'], 'order_id' => $order['order_id'], - 'title' => '订单扣除兑换券', + // 'title' => '订单扣除兑换券', + 'title' => 5, + 'financial_pm' => 0, + 'status' => 1, 'store_id' => $order['store_id'], 'number' => $order['pay_price'], - 'financial_pm' => 0, 'user_ship' => $user['user_ship'], ]; - (new UserSign())->saveAll($sing); + UserSign::create($sing); if ($extra && $extra['store_id']) { $params = [ @@ -199,7 +208,7 @@ class PayNotifyLogic extends BaseLogic // } // self::addUserSing($order); self::afterPay($order); - if ($extra && $extra['store_id']) { + if ($extra && $extra['store_id'] && $order['reservation'] !=1) { $params = [ 'verify_code' => $order['verify_code'], 'store_id' => $extra['store_id'], @@ -208,6 +217,14 @@ class PayNotifyLogic extends BaseLogic OrderLogic::writeOff($params); } self::dealProductLog($order); + if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { + $checkArr = [ + 'cart_id' => $order['cart_id'], + 'store_id' => $order['store_id'], + ]; + self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); + } + // $count = UserSign::where([ // 'uid'=>$order['uid'], // 'type'=>1, @@ -217,9 +234,10 @@ class PayNotifyLogic extends BaseLogic // if($count){ // self::addFlowLog($order); // } - // if($order['shipping_type'] == 3){ + //收银台下单直接到账 + // if($order['shipping_type'] == 3){ // self::descStock($order['id']); - // } + // } // Redis::send('push-platform-print', ['id' => $order['id']], 60); @@ -397,6 +415,13 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']); } $order->save(); + if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { + $checkArr = [ + 'cart_id' => $order['cart_id'], + 'store_id' => $order['store_id'], + ]; + self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); + } self::afterPay($order, $extra['transaction_id']); // self::addUserSing($order); self::dealProductLog($order); @@ -425,18 +450,18 @@ class PayNotifyLogic extends BaseLogic $orderRe->refund_time = time(); $orderRe->remarks = ''; $orderRe->save(); - $purchase_funds = User::where('id',$orderRe['uid'])->value('purchase_funds'); - $user = User::where('id',$orderRe['uid'])->find(); + $purchase_funds = User::where('id', $orderRe['uid'])->value('purchase_funds'); + $user = User::where('id', $orderRe['uid'])->find(); $capitalFlowDao = new CapitalFlowLogic($user); - if($purchase_funds >= $orderRe['price']){ - User::where('id',$orderRe['uid'])->dec('purchase_funds',$orderRe['refund_price'])->update(); + if ($purchase_funds >= $orderRe['price']) { + User::where('id', $orderRe['uid'])->dec('purchase_funds', $orderRe['refund_price'])->update(); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $orderRe['id'], $orderRe['refund_price'], '', 1, $orderRe['store_id']); - }else{ - User::where('id',$orderRe['uid'])->dec('purchase_funds',$purchase_funds)->update(); + } else { + User::where('id', $orderRe['uid'])->dec('purchase_funds', $purchase_funds)->update(); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $orderRe['id'], $purchase_funds, '', 1, $orderRe['store_id']); } - self::descUserSing($orderRe); -// d($purchase_funds,$orderRe['refund_price'],$orderRe); + //退还 充值得兑换券 + UserSignLogic::RefundRecharge($orderRe); return true; } $order->status = OrderEnum::REFUND_PAY; @@ -450,9 +475,11 @@ class PayNotifyLogic extends BaseLogic $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(); + //对应比例得退礼品券逻辑 + $discount = self::getDiscount($user->user_ship); + $total_price = bcmul($order->refund_price, $discount, 2); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { - if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 + if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 $user->now_money = bcadd($user->now_money, $deal_money, 2); $user->save(); //增加数量 @@ -460,7 +487,7 @@ class PayNotifyLogic extends BaseLogic //退款 $capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); } - if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款 + if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); $user->save(); //增加数量 @@ -468,82 +495,21 @@ class PayNotifyLogic extends BaseLogic //退款 $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); } - if ($check_user_sing) { - self::descUserSing($order); - } + UserSignLogic::RefundOrder($order); + return true; } //积分 - if ($check_user_sing) { - self::descUserSing($order); - } + UserSignLogic::RefundOrder($order); //微信日志 user_order_refund $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); //处理财务流水退还 - self::store_finance_back($orderSn); + (new StoreFinanceFlowLogic())->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); - //删除之前获得的兑换券 - UserSign::where([ - 'order_id' => $order['order_id'], - 'financial_pm' => 1, - ])->update(['delete_time' => time()]); - $now_int = User::where('id', $order['uid'])->withTrashed()->find(); - if ($now_int) { - if ($now_int['integral'] > $user_number) { - User::where('id', $order['uid'])->withTrashed()->dec('integral', $user_number)->update(); - } else { - User::where('id', $order['uid'])->withTrashed()->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 @@ -598,47 +564,6 @@ class PayNotifyLogic extends BaseLogic 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 dealRechargeFrozen($order) - { - $total_vip = bcmul($order['price'], 0.1, 2); - $user_sing = new UserSign(); - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '充值获得冻结兑换券', - 'financial_pm' => 1, - 'store_id' => $order['store_id'], - 'type' => 1, - 'status' => 1, - 'number' => $total_vip, - 'back_num' => $total_vip, - ]; - $user_sing->save($sing); - User::where('id', $order->uid)->inc('integral', $total_vip)->update(); - - return true; - } - - /** * 充值 */ @@ -667,11 +592,9 @@ class PayNotifyLogic extends BaseLogic return true; } bcscale(2); - // $user->now_money = bcadd($user->now_money, $price, 2);//v.1 - $check = UserSign::where(['uid' => $order->uid, 'type' => 1])->count(); - if (empty($check) && $user['user_ship'] == 0) { - self::dealRechargeFrozen($order); - } + + UserSignLogic::dealRechargeFrozen($user, $order, $order['user_ship']); + //更新等级 $user->user_ship = $order['user_ship']; @@ -694,7 +617,7 @@ class PayNotifyLogic extends BaseLogic /** * 现金支付 */ - public static function cash_pay($orderSn) + public static function cash_pay($orderSn,$extra =[]) { $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); @@ -704,6 +627,9 @@ class PayNotifyLogic extends BaseLogic $order->paid = 1; $order->pay_time = time(); $order->status = 2; + if ($order['reservation'] ==1) { + $order->status = 1; + } if (!$order->save()) { throw new \Exception('订单保存出错'); } @@ -714,9 +640,21 @@ class PayNotifyLogic extends BaseLogic $cashFlowLogic = new CashFlowLogic(); $cashFlowLogic->insert($order['store_id'], $order['pay_price']); self::dealProductLog($order); + if ($order['shipping_type'] == 3) { self::descStock($order['id']); } + + if ($extra && $extra['store_id'] && $order['reservation'] !=1) { + $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']]); return true; } @@ -773,11 +711,27 @@ class PayNotifyLogic extends BaseLogic public static function afterPay($order, $transaction_id = 0) { $financeLogic = new StoreFinanceFlowLogic(); - $user_sing = new UserSign(); $off_activity = Config::where('name', 'off_activity')->value('value'); $village_uid = 0; $brigade_uid = 0; $user_ship = 0; + try { + Redis::send('order_wetcha_push_send', ['order' => $order]); + } catch (\Exception $e) { + Log::error('订单推送失败:' . $e->getMessage()); + // 异常处理代码,例如记录日志或发送通知等。 + } + if ($order['uid'] > 0) { + // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 + //用户下单该用户等级为1得时候才处理冻结金额 + $user = User::where('id', $order['uid'])->find(); + $user_ship = $user['user_ship']; + + } + //积分写入 + if(in_array($user_ship,[0,4])){ + UserSignLogic::OrderWrite($order); + } if ($off_activity == 1) { //-----活动价结算更改 $financeLogic->order = $order; @@ -786,61 +740,51 @@ class PayNotifyLogic extends BaseLogic $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']); $financeLogic->save(); - if ($order['uid'] > 0 && $order['total_price'] >= 500 && $order['pay_type'] !=PayEnum::PURCHASE_FUNDS) { - $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 false; } - if ($order['uid'] > 0) { - // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 - //用户下单该用户等级为1得时候才处理冻结金额 - $user = User::where('id', $order['uid'])->find(); - $user_ship = $user['user_ship']; - //纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额) - if ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) { - $vipFrozenAmount = self::dealFrozenPrice($order['id']); - //为1的时候要去减活动价 - $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); - self::dealVipAmount($order, $order['pay_type']); - } - if($order['total_price'] >= 500 && $order['pay_type'] !=PayEnum::PURCHASE_FUNDS){ - $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); - } + + //纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额) + if ($user_ship== 1 && $order['pay_type'] != PayEnum::CASH_PAY) { + $vipFrozenAmount = self::dealFrozenPrice($order['id']); + //为1的时候要去减活动价 + $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); + self::dealVipAmount($order, $order['pay_type']); } - //查询用户对应的村长和队长 - $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) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; - } - } - if ($order['spread_uid'] > 0 || $user_ship>0) { - if($order['spread_uid'] > 0 && $user_ship == 0){ + if ($order['spread_uid'] > 0 || $user_ship > 0) { + if ($order['spread_uid'] > 0 && $user_ship == 0) { $user_ship = User::where('id', $order['spread_uid'])->value('user_ship'); + if ($user_ship == 2) { + $village_uid = $order['spread_uid']; + $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); + if ($address) { + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; + } + } + } elseif ($user_ship == 3) { + $brigade_uid = $order['spread_uid']; + $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); + if ($address) { + $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); + if ($arr1) { + $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; + } + } + } + } else { + //查询用户对应的村长和队长 + $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) { + $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; + } + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; + } + } } switch ($user_ship) { case 1: // 行业会员 @@ -954,8 +898,9 @@ class PayNotifyLogic extends BaseLogic foreach ($productLog as &$value) { $value['pay_uid'] = $uid; $value['oid'] = $order['id']; + $value['store_id'] = $store_id; $cart_info = StoreOrderCartInfo::where([ - 'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'store_id' => $store_id + 'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'oid' => $value['oid'] ])->find(); $value['order_num'] = $cart_info['cart_num'] ?? 1; $value['pay_num'] = $cart_info['cart_num'] ?? 1; @@ -1055,4 +1000,52 @@ class PayNotifyLogic extends BaseLogic (new StoreBranchProduct())->saveAll($updateData); } + + + /** + * 处理商品缺失新增到缺失列表 + * @param $cart_id //购物车ids + * @param $uid //用户id + * @param $oid //订单id + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function dealGoodsLeft($cart_id, $uid, $oid) + { + if (is_array($cart_id)) { + $cart_id['cart_id'] = $cart_id; + } else { + $cart_id['cart_id'] = explode(',', $cart_id); + } + $data = OrderLogic::checkLeft($cart_id, $uid, 1); + $format = $data['detail']; + foreach ($format as &$value) { + $value['oid'] = $oid; + $value['create_time'] = time(); + } + Db::name('store_product_miss')->insertAll($format); + } + + + + /** + * 会员等级对应得折扣比例 + * @param $level + * @return float|mixed + */ + public static function getDiscount($level) + { + switch ($level) { + case 0: //普通 + return Config::where('name', 'ordinary_member')->value('value') ?? 0.1; + case 1: //vip + return Config::where('name', 'vip_member')->value('value') ?? 0.1; + case 4: //商户 + return Config::where('name', 'merchant')->value('value') ?? 0.1; + default: + return 0.1; + } + } } diff --git a/app/common/logic/PaymentLogic.php b/app/common/logic/PaymentLogic.php index 51df608a2..a49df6407 100644 --- a/app/common/logic/PaymentLogic.php +++ b/app/common/logic/PaymentLogic.php @@ -8,6 +8,7 @@ use app\common\enum\PayEnum; use app\common\model\user\UserAuth; use app\common\service\pay\PayService; use Exception; +use support\Log; use function DI\string; @@ -101,6 +102,8 @@ class PaymentLogic extends BaseLogic try { $result = $wechat->wechat->pos($order)->toArray(); } catch (Exception $e) { + Log::error('条码支付报错',['message' => $e->extra['message']?? $e->getMessage(),'code'=>$e->getCode()]); + if (getenv('APP_DEBUG') == true) { self::$error = $e->extra['message'] ?? $e->getMessage(); } else { diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 44b3e75ed..ab6999160 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -70,6 +70,7 @@ class StoreFinanceFlowLogic extends BaseLogic switch ($financialType) { case OrderEnum::MERCHANT_ORDER_OBTAINS: // 商户 case OrderEnum::ORDER_MARGIN: // 商户保证金 + case OrderEnum::OTHER_ORDER_OBTAINS: // 损耗' $data['type'] = OrderEnum::MERCHANT; break; case OrderEnum::PLATFORM_ORDER_OBTAINS: // 平台 @@ -144,20 +145,63 @@ class StoreFinanceFlowLogic extends BaseLogic */ public function updateStatusStore($order_id, $store_id, $money, $deposit) { - StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 11])->update(['status' => 1]); - StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 2])->update(['status' => 1]); - if ($money>0) { + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1]); + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1]); + if ($money > 0) { SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); } - if ($deposit>0) { + if ($deposit > 0) { SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); } - $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16,'status'=>0])->find(); - StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 16])->update(['status' => 1]); + $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find(); + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]); if ($find) { if ($find['number'] > 0) { SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); } } } + + /** + * 财务退还金额相关 + * @param $orderSn + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public 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(); + if ($value['status'] == 1) { + switch ($value['type']) { + case 0: + $user = User::where('id', $value['other_uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + $capitalFlowDao->userExpense('system_now_money_back', 'system_back', $value['order_id'], $value['number']); + break; + case 1: + if ($value['number'] > 0 &&$value['financial_type']==2) { + SystemStore::where('id', $value['store_id'])->dec('store_money',$value['number'])->update(); + } + if ($value['number'] > 0 &&$value['financial_type']==11) { + SystemStore::where('id', $value['store_id'])->dec('paid_deposit',$value['number'])->update(); + } + if ($value['number'] > 0 &&$value['financial_type']==16) { + SystemStore::where('id', $value['store_id'])->dec('attrition',$value['number'])->update(); + } + break; + } + } + } + (new StoreFinanceFlow)->saveAll($data); + } } diff --git a/app/common/logic/UserSignLogic.php b/app/common/logic/UserSignLogic.php new file mode 100644 index 000000000..fc7e63791 --- /dev/null +++ b/app/common/logic/UserSignLogic.php @@ -0,0 +1,201 @@ +uid)->count(); + if ($count == 0 && in_array($user_ship, [1, 2, 3, 5, 6, 7, 8])) { + //首充 + $write = self::write($order, $total_vip, 0, 1, 9); + self::write_log($write, $total_vip, 0, 7); + self::write_log($write, $total_vip, 0, 9, 0); + User::where('id', $order->uid)->inc('integral', $total_vip)->update(); + } + return true; + } + /** + * 充值退款 + */ + public static function RefundRecharge($order) + { + $find = UserSign::where('uid', $order['uid'])->where('order_id', $order['order_id'])->find(); + if ($find) { + $number = UserSignLog::where('sid', $find->id)->where('financial_pm', 0)->sum('number'); + self::write($find, $number, 0, 1, 3, 0); + User::where('id', $order['uid'])->dec('integral', $number)->update(); + } + } + + /** + * 来自订单 + */ + public static function OrderWrite($order) + { + $total_vip = bcmul($order['pay_price'], 0.1, 2); + + if ($order['source'] == 0) { + //冻结礼品券 + if ($order['pay_price'] >= 500) { + $write = self::write($order, $total_vip, 1, 0, 4); + self::write_log($write, $total_vip, 1, 1, 1); + } + } else { + //不冻结礼品券 + if ($order['pay_price'] >= 500) { + $write = self::write($order, $total_vip, 1, 1, 4); + self::write_log($write, $total_vip, 1, 1); + self::write_log($write, $total_vip, 1, 2, 0); + User::where('id', $order->uid)->inc('integral', $total_vip)->update(); + } + } + } + /** + * 订单退款 + */ + public static function RefundOrder($order) + { + $find = UserSign::where('uid', $order['uid'])->where('order_id', $order['order_id'])->find(); + if ($find) { + $number = UserSignLog::where('sid', $find->id)->where('financial_pm', 0)->sum('number'); + self::write($find, $number, 1, 1, 3, 0); + User::where('id', $order['uid'])->dec('integral', $number)->update(); + } + } + + /** + * 核销 + */ + public static function WriteOff($order) + { + $find = UserSign::where(['order_id' => $order['order_id'], 'status' => 0, 'financial_pm' => 1, 'order_type' => 1])->find(); + if ($find) { + $find->status = 1; + $find->save(); + User::where('id', $order->uid)->inc('integral', $find['number'])->update(); + self::write_log($find, $find['number'], 1, 2, 0); + // self::write_log($find, $find['number'], 1, 4); + } + } + /** + * 储存商品积分结算 + */ + public static function storage($order_id, $price) + { + $find = UserSign::where(['order_id' => $order_id, 'status' => 0, 'financial_pm' => 1, 'order_type' => 1])->find(); + if ($find) { + self::write_log($find, $price, 1, 2, 0); + self::write_log($find, $price, 1, 2, 1); + if ($price > $find['number']) { + $find->status = 1; + $find->save(); + } + User::where('id', $find['uid'])->inc('integral', $price)->update(); + } + } + + /** + * @param type 1:购买商品冻结 + * @param type 2:核销商品解冻 + * @param type 3:退款扣除冻结 + * @param type 4:核销商品获得 + * @param type 5:兑换商品扣除 + * @param type 6:退款扣除礼品 + * @param type 7:充值冻结 + * @param type 8:收银台支付增加 + * @param type 9:充值解冻 + */ + public static function write($order, $total_vip, $order_type = 0, $status = 0, $type = 4, $pm = 1) + { + //礼品券得 + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'type' => $type, + 'financial_pm' => $pm, + 'store_id' => $order['store_id'], + 'status' => $status, + 'number' => $total_vip, + 'back_num' => $total_vip, + 'order_type' => $order_type, + + ]; + return UserSign::create($sing); + } + /** + * @param type 1:购买商品冻结 + * @param type 2:核销商品解冻 + * @param type 3:退款扣除冻结 + * @param type 4:核销商品获得 + * @param type 5:兑换商品扣除 + * @param type 6:退款扣除礼品 + * @param type 7:充值冻结 + * @param type 8:收银台支付增加 + * @param type 9:充值解冻 + */ + public static function write_log($write, $total_vip, $order_type = 0, $type = 4, $pm = 1) + { + //礼品券日志记录 + $sing = [ + 'uid' => $write['uid'], + 'sid' => $write['id'], + 'order_id' => $write['order_id'], + 'type' => $type, + 'financial_pm' => $pm, + 'order_type' => $order_type, + 'status' => 1, + 'number' => $total_vip, + ]; + UserSignLog::create($sing); + } + + //礼品券相关对应文本 + public static function getTitle($type, $amount, $number) + { + switch ($type) { + /**冻结券**/ + //收入 + case 1: + return "购买商品{$amount}元获得{$number}元冻结券"; + case 7: + return "充值{$amount}元获得{$number}元冻结券"; + //支出 + case 2: + return "核销商品{$amount}元解冻{$number}元礼品券"; + case 3: + return "退款{$amount}元扣除{$number}元冻结券"; + /**礼品券**/ + //收入 + case 4: + return "核销商品{$amount}元获得{$number}元礼品券"; + //支出 + case 5: + return "兑换{$amount}元商品扣除{$number}元礼品券"; + case 6: + return "退款{$amount}元扣除{$number}元礼品券"; + case 8: + return "收银台支付{$amount}元增加{$number}元礼品券"; + case 9: + return "充值{$amount}元解冻{$number}元礼品券"; + default: + return "订单支付{$amount}元"; + } + } +} diff --git a/app/common/logic/VipLogic.php b/app/common/logic/VipLogic.php index d47b95051..3131a9973 100644 --- a/app/common/logic/VipLogic.php +++ b/app/common/logic/VipLogic.php @@ -42,142 +42,7 @@ class VipLogic extends BaseLogic 'create_time'=>time() ]; Db::name('vip_flow')->insert($data); - //todo 限制执行 -// self::afterPay($order,$transaction_id,$total_vip); return true; } - - - - - - - public static function afterPay($order, $transaction_id = 0,$Vipmoney=0) - { - $financeLogic = new StoreFinanceFlowLogic(); - $financeLogic->order = $order; - $financeLogic->user = ['uid' => $order['uid']]; - - $financeLogic->in($transaction_id, $Vipmoney, OrderEnum::USER_ORDER_PAY); //用户订单支付 - $count_frees = 0; - - //平台手续费 - $fees = bcdiv(bcmul($Vipmoney, '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($Vipmoney, '0.05', 2), 1, 2); - $count_frees = bcadd($count_frees, $store_profit, 2); - if ($deposit > 0) { - if ($deposit > $store_profit) { - if ($store_profit > 0) { - $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - } else { - $money = bcsub($store_profit, $deposit, 2); - if ($deposit > 0) { - $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']; - $fees = bcdiv(bcmul($Vipmoney, '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(); - $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($Vipmoney, '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) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); - if($village_uid){ - User::where('id', $village_uid)->inc('integral', $fees)->update(); - } - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); - if($brigade_uid){ - User::where('id', $brigade_uid)->inc('integral', $fees)->update(); - } - } - } - } - if ($fees > 0) { - //村长获得 - $sing=[]; - $user_sing=new UserSign(); - - $sing[]=[ - 'uid'=>$village_uid, - 'title'=>'村长订单获得兑换券', - 'store_id'=>$order['store_id'], - 'number'=>$fees, - ]; - $sing[]=[ - 'uid'=>$brigade_uid, - 'title'=>'队长订单获得兑换券', - 'store_id'=>$order['store_id'], - 'number'=>$fees, - ]; - // if ($village_uid > 0) { - // $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) { - // $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($Vipmoney, $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(); - - } - - } \ No newline at end of file diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 8b5a8943a..1ae877833 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -378,12 +378,13 @@ class StoreOrderLogic extends BaseLogic } $template = getenv('SMS_TEMPLATE'); $check =(new SmsService())->client($phone,$template,$code); - if($check){ if($type == 1){ $remark = $param['uid'].'_smsPay'; - }else{ + }elseif($type == 2){ $remark = $param['uid'].'_giftPay'; + }else{ + $remark = $param['uid'].'_moneyPay';//余额支付 } Cache::set($remark,$code,5*60); return true; @@ -393,5 +394,53 @@ class StoreOrderLogic extends BaseLogic } +//检查缺失 + public static function checkLeft($params, $uid, $type = 0) + { + $where = []; + if (empty($type)) { + $where = ['is_pay' => 0]; + } + $cart_select = Cart::whereIn('id', $params['cart_id']) + ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); + if (empty($cart_select)) { + self::setError('购物车为空'); + return false; + } + $newArr = []; + //检查购物车对比店铺得商品数量差异 + foreach ($cart_select as $v) { + $store = StoreBranchProduct::where([ + 'store_id' => $params['store_id'], + 'product_id' => $v['product_id'], + ])->field('id,store_name,stock')->withTrashed()->find(); + if (empty($store)) { + $store['stock'] = 0; + } + if ($store['stock'] < $v['cart_num']) { + //缺失 + $newArr[] = [ + 'uid' => $uid, + 'store_id' => $params['store_id'], + 'product_id' => $v['product_id'], + 'missing_quantity' => $v['cart_num'] - $store['stock'] + ]; + } + } + + if ($newArr) { + return [ + 'detail' => $newArr, + 'reservation' => 1 + ]; + } + return [ + 'detail' => [], + 'reservation' => 0 + ]; + } + + + } diff --git a/app/common/logic/user_product_storage/UserProductStorageLogic.php b/app/common/logic/user_product_storage/UserProductStorageLogic.php index ed775d912..fdea6c23f 100644 --- a/app/common/logic/user_product_storage/UserProductStorageLogic.php +++ b/app/common/logic/user_product_storage/UserProductStorageLogic.php @@ -3,7 +3,10 @@ namespace app\common\logic\user_product_storage; use app\common\logic\BaseLogic; +use app\common\logic\UserSignLogic; +use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\user\User; use app\common\model\user_product_storage\UserProductStorage; use app\common\model\user_product_storage_log\UserProductStorageLog; use think\facade\Db; @@ -39,15 +42,20 @@ class UserProductStorageLogic extends BaseLogic /** * 出库 */ - public static function supply($data,$uid,$store_id){ + public static function supply($data,$uid,$store_id,$status=1,$times=''){ Db::startTrans(); try { $data_log=[]; + if($times!=''){ + $times=strtotime($times); + } + $user_ship=User::where('id',$uid)->value('user_ship'); foreach ($data as $k=>$v){ $find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find(); if($find){ if($find['nums']<$v['nums']){ self::setError('库存不足'); + Db::commit(); return false; } $nums=bcsub($find['nums'],$v['nums']); @@ -56,12 +64,31 @@ class UserProductStorageLogic extends BaseLogic $find->status=0; } $find->save(); + if(in_array($user_ship,[0,4])){ + $cart_info=StoreOrderCartInfo::where(['oid'=>$find['oid'],'uid'=>$uid,'product_id'=>$find['product_id']])->value('cart_info'); + if($cart_info){ + $price=bcdiv($cart_info['pay_price'],$cart_info['cart_num'],2); + if($price){ + $price=bcmul($price,$v['nums'],2); + $rate=bcdiv($price,100,2); + $order_id= StoreOrder::where('id',$cart_info['oid'])->value('order_id'); + UserSignLogic::storage($order_id,$rate); + } + + } + } $data_log[$k]['uid']=$uid; $data_log[$k]['oid']=$find['oid']; $data_log[$k]['product_id']=$find['product_id']; $data_log[$k]['store_id']=$store_id; $data_log[$k]['financial_pm']=0; $data_log[$k]['nums']=$v['nums']; + $data_log[$k]['times']=$times; + $data_log[$k]['status']=$status; + }else{ + self::setError('没有查询到该商品'); + Db::commit(); + return false; } } (new UserProductStorageLog())->saveAll($data_log); diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index ea80beca0..290132284 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -7,6 +7,7 @@ namespace app\common\model\user; use app\common\enum\user\UserEnum; use app\common\model\BaseModel; use app\common\model\user_label\UserLabel; +use app\common\model\user_ship\UserShip; use app\common\service\FileService; use think\model\concern\SoftDelete; diff --git a/app/common/model/user/UserShip.php b/app/common/model/user/UserShip.php deleted file mode 100644 index 7d0a05ed1..000000000 --- a/app/common/model/user/UserShip.php +++ /dev/null @@ -1,13 +0,0 @@ -update(['status'=>-1]); if($res){ + PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>$data['id'],'paid'=>0]]); PushService::push('wechat_mmp_' . $order['uid'], $order['uid'], ['type'=>'INDUSTRYMEMBERS','msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>$data['id'],'paid'=>0]]); } } diff --git a/app/store/controller/cart/CartController.php b/app/store/controller/cart/CartController.php index ae4587eee..97666dd81 100644 --- a/app/store/controller/cart/CartController.php +++ b/app/store/controller/cart/CartController.php @@ -42,13 +42,13 @@ class CartController extends BaseAdminController return $this->fail('购物车商品不能大于100个,请先结算'); } //数量下单判断 - $stock = StoreBranchProduct::where( - ['product_id'=>$params['product_id'], - 'store_id'=>$params['store_id'] - ])->value('stock')??0; - if ($params['cart_num'] >$stock) { - return $this->fail('库存数量不足'); - } +// $stock = StoreBranchProduct::where( +// ['product_id'=>$params['product_id'], +// 'store_id'=>$params['store_id'] +// ])->value('stock')??0; +// if ($params['cart_num'] >$stock) { +// return $this->fail('库存数量不足'); +// } if ($result) { $res = CartLogic::edit($params); } else { diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index cbba40a69..17e1f8c12 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -118,6 +118,10 @@ class StoreOrderController extends BaseAdminController if ($order['order']['pay_price'] > $user['integral']) { return $this->fail('当前用户礼品券不足支付'); } + }elseif($params['type'] == 3){ + if ($order['order']['pay_price'] > $user['now_money']) { + return $this->fail('当前用户余额不足支付'); + } } $res = (new StoreOrderLogic())->dealSendSms($params, $params['type']); @@ -128,6 +132,23 @@ class StoreOrderController extends BaseAdminController } } + //检查库存足够与否 + public function checkInventory() + { + $params = (new StoreOrderValidate())->post()->goCheck('cart'); + $params['store_id'] = $this->request->adminInfo['store_id']??22; + $res = StoreOrderLogic::checkLeft($params, $params['uid']); + if (!$res) { + $msg = StoreOrderLogic::getError(); + if ($msg == '购物车为空') { + return $this->data([]); + } + return $this->fail(StoreOrderLogic::getError()); + } + return $this->data($res); + } + + /** * 创建订单 @@ -142,7 +163,7 @@ class StoreOrderController extends BaseAdminController $params = $this->request->post(); if ( $auth_code == '' && $pay_type != PayEnum::CASH_PAY && $pay_type != PayEnum::PURCHASE_FUNDS - && $pay_type != PayEnum::GIFT_FUNDS + && $pay_type != PayEnum::GIFT_FUNDS && $pay_type != PayEnum::BALANCE_PAY ) { return $this->fail('支付条码不能为空'); } @@ -165,12 +186,22 @@ class StoreOrderController extends BaseAdminController } } + if ($pay_type == PayEnum::BALANCE_PAY) { + $remark = $uid . '_moneyPay'; + $code = Cache::get($remark); + if ($code && isset($params['code']) && $code != $params['code']) { + throw new Exception('验证码错误'); + } + } + + $user = null; if ($uid) { $user = User::where('id', $uid)->find(); } $params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id,用于判断是否是当前店铺的订单 $params['shipping_type'] =3; + $params['source'] =1; $order = OrderLogic::createOrder($cartId, $addressId, $user, $params); if ($order != false) { switch ($pay_type) { @@ -180,7 +211,7 @@ class StoreOrderController extends BaseAdminController 'store_id' => $this->request->adminInfo['store_id'], 'staff_id' => $this->request->adminInfo['admin_id'] ]); - return $this->success('余额支付成功'); + return $this->success('余额支付成功', ['id' => $order['id']]); case PayEnum::PURCHASE_FUNDS: //采购款支付 PayNotifyLogic::handle('purchase_funds', $order['order_id'], [ @@ -197,7 +228,10 @@ class StoreOrderController extends BaseAdminController return $this->success('礼品券支付成功', ['id' => $order['id']]); case PayEnum::CASH_PAY: //现金支付 - PayNotifyLogic::handle('cash_pay', $order['order_id']); + PayNotifyLogic::handle('cash_pay', $order['order_id'], [ + 'uid' => $uid, 'store_id' => $this->request->adminInfo['store_id'], + 'staff_id' => $this->request->adminInfo['admin_id'] + ]); return $this->success('现金支付成功', ['id' => $order['id']]); case PayEnum::WECHAT_PAY_BARCODE: @@ -451,6 +485,8 @@ class StoreOrderController extends BaseAdminController $item['price'] = $item['cart_info']['price']; return $item; }); + }else { + return $this->fail('订单不存在'); } return $this->success('获取成功', $find?->toArray()); } diff --git a/app/store/controller/user/UserController.php b/app/store/controller/user/UserController.php index dd6b82e4b..47e6b8653 100644 --- a/app/store/controller/user/UserController.php +++ b/app/store/controller/user/UserController.php @@ -40,16 +40,16 @@ class UserController extends BaseAdminController { $params = (new UserValidate())->post()->goCheck('storeAdd'); $code = $params['code']; - if($code && $params['mobile']){ - $remark = $params['mobile'].'_userArchives'; - $codeCache = Cache::get($remark); - if(empty($codeCache)){ - return $this->fail('验证码不存在'); - } - if ($codeCache != $code) { - return $this->fail('验证码错误'); - } - } +// if($code && $params['mobile']){ +// $remark = $params['mobile'].'_userArchives'; +// $codeCache = Cache::get($remark); +// if(empty($codeCache)){ +// return $this->fail('验证码不存在'); +// } +// if ($codeCache != $code) { +// return $this->fail('验证码错误'); +// } +// } UserLogic::StoreAdd($params); if (UserLogic::hasError() ) { return $this->fail(UserLogic::getError()); diff --git a/app/store/lists/store_order/StoreOrderLists.php b/app/store/lists/store_order/StoreOrderLists.php index 416fc983a..7f1d9b8a4 100644 --- a/app/store/lists/store_order/StoreOrderLists.php +++ b/app/store/lists/store_order/StoreOrderLists.php @@ -50,9 +50,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface $is_sashier = $this->request->get('is_sashier'); if ($is_sashier == 1) { //收银台订单 $this->searchWhere[] = ['store_id', '=', $store_id]; - $this->searchWhere[] = ['pay_type', 'in', [17, 9, 13, 18,19]]; + $this->searchWhere[] = ['source', '=', 1]; } elseif ($is_sashier == 2) { //小程序订单 - $this->searchWhere[] = ['pay_type', 'in', [7, 3, 18,19]]; + $this->searchWhere[] = ['source', '=', 0]; } $status = $this->request->get('status',''); switch ($status){ diff --git a/app/store/lists/user/UserLists.php b/app/store/lists/user/UserLists.php index 91a532214..08e05e13b 100644 --- a/app/store/lists/user/UserLists.php +++ b/app/store/lists/user/UserLists.php @@ -11,6 +11,7 @@ use app\common\model\user\User; use app\common\model\user_ship\UserShip; use app\common\lists\ListsSearchInterface; use app\common\model\user\UserAddress; +use app\common\model\vip_flow\VipFlow; class UserLists extends BaseAdminDataLists implements ListsSearchInterface { @@ -57,11 +58,17 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface $data['sex_text'] = $data->sex_text; $data['mobile'] = substr_replace($data['mobile'], '****', 3, 4); $data['user_ship_name'] =$data['user_ship']==0?'一般用户':UserShip::where('id',$data['user_ship'])->value('title'); - $data['return_money'] = StoreFinanceFlow:: - where(['user_id'=>$data['id'],'status'=>0,'financial_pm'=>0]) - ->sum('number'); + $data['return_money'] = VipFlow:: + where(['user_id'=>$data['id'],'status'=>0]) + ->sum('number')??0; $data['amount_frozen'] = UserSign::where('uid',$data['id'])->where('status',0)->sum('number'); - $data['get_frozen'] = UserSign::where('uid',$data['id'])->where('status',1)->sum('number'); + $number1 = UserSign::where('uid',$data['id'])->where('status',1)->where('type','<>',3)->sum('number'); + $number2 = UserSign::where('uid',$data['id'])->where('status',1)->where('type',3)->sum('number'); + if($number1<$number2){ + $data['get_frozen']=0; + }else{ + $data['get_frozen']=bcsub($number1,$number2,2)??0; + } })->toArray(); return $lists; diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index e80449753..4f3ff7681 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -137,9 +137,9 @@ class WorkbenchLogic extends BaseLogic $recharge_field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(price) as pay_price'; } $data['order_list'] = StoreOrder::with('user')->where($where) - ->whereBetweenTime('pay_time', $startTime, $endTime) +// ->whereBetweenTime('pay_time', $startTime, $endTime) ->order('pay_time', 'desc') - ->limit(6) +// ->limit(6) ->select()->each(function($item){ $item->pay_time=$item->pay_time>0?date('Y-m-d H:i:s',$item->pay_time):''; }) @@ -628,7 +628,6 @@ class WorkbenchLogic extends BaseLogic //总的营业额的统计 总的利润的统计 总的成本合集的统计 总的加到保证金的 $all = StoreOrder::where(['paid' => YesNoEnum::YES, 'store_id' => $params['store_id']]); - $deposit_all = StoreFinanceFlow::where(['store_id' => $params['store_id'], 'status' => YesNoEnum::YES]) ->sum('number'); @@ -732,7 +731,7 @@ class WorkbenchLogic extends BaseLogic { $endTime = date('Y-m-d', strtotime($startTime) + 86400); //当日营业额的统计 当日利润的统计 当日成本合集的统计 当日加到保证金的 当日的现金收银 - $today = StoreOrder::where(['paid' => YesNoEnum::YES, 'store_id' => $store_id]); + $today = StoreOrder::where(['paid' => YesNoEnum::YES, 'store_id' => $store_id,'refund_status'=>0]); $turnover_today = $today ->whereBetweenTime('create_time', $startTime, $endTime) ->sum('pay_price'); @@ -905,7 +904,9 @@ class WorkbenchLogic extends BaseLogic 'SUM(collect_num) as collect', 'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes', 'COUNT(distinct(pay_uid))-1 as repeats' - ])->group('product_id')->order('pay', ' desc')->limit(20)->select()->toArray(); + ])->group('product_id')->order('pay', 'desc') +// ->limit(20) + ->select()->toArray(); foreach ($list as $key => &$item) { $find = StoreProduct::where('id', $item['product_id'])->field('store_name,image')->find(); $item['store_name'] = $find['store_name']; diff --git a/app/store/logic/auth/AdminLogic.php b/app/store/logic/auth/AdminLogic.php index b0a1b4372..fd63d0ef4 100644 --- a/app/store/logic/auth/AdminLogic.php +++ b/app/store/logic/auth/AdminLogic.php @@ -225,7 +225,7 @@ class AdminLogic extends BaseLogic public static function detail($params, $action = 'detail'): array { $admin = SystemStoreStaff::field([ - 'id', 'account', 'staff_name', 'avatar', 'is_admin', 'is_manager', 'store_id' + 'id', 'account', 'staff_name', 'avatar', 'is_admin', 'is_manager', 'store_id','role_id' ])->findOrEmpty($params['id'])->toArray(); if ($action == 'detail') { diff --git a/app/store/logic/store_order/StoreOrderLogic.php b/app/store/logic/store_order/StoreOrderLogic.php index f8808002c..80df42e05 100644 --- a/app/store/logic/store_order/StoreOrderLogic.php +++ b/app/store/logic/store_order/StoreOrderLogic.php @@ -3,6 +3,8 @@ namespace app\store\logic\store_order; +use app\common\model\order\Cart; +use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; use think\facade\Db; diff --git a/app/store/validate/store_order/StoreOrderValidate.php b/app/store/validate/store_order/StoreOrderValidate.php index adf8b8f9b..df8c18a78 100644 --- a/app/store/validate/store_order/StoreOrderValidate.php +++ b/app/store/validate/store_order/StoreOrderValidate.php @@ -35,9 +35,15 @@ class StoreOrderValidate extends BaseValidate 'id' => 'id', 'verify_code' => '核销码', 'type' => '发送短信类型', + 'cart_id' => '购物车id', ]; + public function sceneCart() + { + return $this->only(['cart_id']); + } + /** * @notes 添加场景 * @return StoreOrderValidate diff --git a/config/server.php b/config/server.php index fb3af3c30..3b49e4ce2 100644 --- a/config/server.php +++ b/config/server.php @@ -13,7 +13,7 @@ */ return [ - 'listen' => 'http://0.0.0.0:8545', + 'listen' => getenv('HOST'), 'transport' => 'tcp', 'context' => [], 'name' => 'webman',