diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php index ee7ca21d0..2c1cc96fa 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php @@ -46,7 +46,7 @@ class StoreFinanceFlowDayLists extends BaseAdminDataLists implements ListsSearch return StoreFinanceFlow::where($this->searchWhere) ->field(' FROM_UNIXTIME(create_time, "%Y-%m-%d") as date, - SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income, + SUM(CASE WHEN financial_pm = 1 AND financial_type = 1 THEN number ELSE 0 END) as income, SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure ') ->limit($this->limitOffset, $this->limitLength) diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php index 45bb608a7..53384f8c5 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php @@ -32,7 +32,7 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt public function setSearch(): array { return [ - '=' => ['store_id', 'user_id', 'create_time', 'staff_id'], + '=' => ['store_id', 'user_id', 'create_time', 'staff_id','financial_type','financial_pm','order_id'], 'between_time' => 'create_time', '%pipe_like%' => ['keyword' => 'order_sn'], ]; @@ -53,18 +53,24 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt $field = [ 'id', 'order_id', 'order_sn', 'create_time', 'other_uid', 'user_id', 'store_id', 'staff_id', 'financial_type', 'financial_pm', 'pay_type', 'type', 'number', 'status' ]; - $this->searchWhere[] = ['financial_type', '=', 1]; - $this->searchWhere[] = ['financial_pm', '=', 1]; + if($this->request->get('order_id')){ + $order=['financial_pm'=>'desc']; + }else{ + $order=['id'=>'desc']; + } $data = StoreFinanceFlow::where($this->searchWhere) ->field($field) ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) + ->order($order) ->select()->each(function ($item) { if ($item['user_id'] <= 0) { $item['nickname'] = '游客'; } else { $id = $item['user_id']; - $item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "|$id"; + $user=User::where('id', $item['user_id'])->field('real_name,nickname')->find(); + if($user){ + $item['nickname'] =$user['real_name']!=''?$user['real_name']:$user['nickname'].'|'.$id; + } } if (!empty($this->request->adminInfo['store_id'])) { $item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0; diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php index c91be7381..3ee82eb3c 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php @@ -46,7 +46,7 @@ class StoreFinanceFlowMonthLists extends BaseAdminDataLists implements ListsSear return StoreFinanceFlow::where($this->searchWhere) ->field(' CONCAT(YEAR(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "年", MONTH(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "月") as date, - SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income, + SUM(CASE WHEN financial_pm = 1 AND financial_type = 1 THEN number ELSE 0 END) as income, SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure ') ->limit($this->limitOffset, $this->limitLength) diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php index 00513e499..41c2386dc 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php @@ -46,7 +46,7 @@ class StoreFinanceFlowWeekLists extends BaseAdminDataLists implements ListsSearc return StoreFinanceFlow::where($this->searchWhere) ->field(' CONCAT("第", LPAD(YEAR(FROM_UNIXTIME(create_time, "%Y-%m-%d")), 4, "0"), "-", LPAD(WEEK(FROM_UNIXTIME(create_time, "%Y-%m-%d"), 3), 2, "0"), "周(", LPAD(MONTH(FROM_UNIXTIME(create_time, "%Y-%m-%d")), 2, "0"), "月)") as date, - SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income, + SUM(CASE WHEN financial_pm = 1 AND financial_type = 1 THEN number ELSE 0 END) as income, SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure ') ->limit($this->limitOffset, $this->limitLength) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index 5b2e2d84f..39c010c45 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -10,6 +10,7 @@ use app\common\model\store_order\StoreOrder; use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\user\User; /** * 订单列表列表 @@ -29,7 +30,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['order_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id'], + '=' => ['order_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'], 'between_time' => 'create_time' ]; } @@ -46,7 +47,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return StoreOrder::with(['user', 'staff'])->where($this->searchWhere) + return StoreOrder::with(['staff'])->where($this->searchWhere) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->request->adminInfo['store_id']); }) @@ -58,20 +59,29 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface $query->whereIn('status', $status); } }) - ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status']) + ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : ''; $item['status_name'] = OrderEnum::getOrderType($item['status']) ?? ''; + if ($item['uid'] <= 0) { + $item['nickname'] = '游客'; + } else { + $id = $item['uid']; + $user=User::where('id', $item['uid'])->field('real_name,nickname')->find(); + if($user){ + $item['nickname'] =$user['real_name']!=''?$user['real_name'].'|'.$id:$user['nickname'].'|'.$id; + } + } if ($item['paid'] == 0) { $item['status_name'] = '待支付'; } $product = StoreOrderCartInfo::where('oid', $item['id'])->field(['id', 'oid', 'product_id', 'cart_info']) ->limit(3)->select(); foreach ($product as &$items) { - $items['store_name'] = $items['cart_info']['name']; - $items['image'] = $items['cart_info']['image']; + $items['store_name'] = $items['cart_info']['name']??''; + $items['image'] = $items['cart_info']['image']??''; } $item['product'] = $product; return $item; diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 360cda901..cdaa4ba66 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -58,15 +58,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa } } return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_name','swap', 'cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code','manufacturer_information']) + ->field(['id', 'image', 'store_name','swap','product_type','cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code','manufacturer_information']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); return $item; - }) - ->toArray(); + })?->toArray(); } diff --git a/app/admin/lists/user_label/UserLabelLists.php b/app/admin/lists/user_label/UserLabelLists.php index 4e142b649..53261482b 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; /** * 用户标签列表 @@ -42,11 +42,14 @@ class UserLabelLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { + $limit=UserShip::where('id',1)->value('limit'); return UserLabel::where($this->searchWhere) ->field(['label_id', 'label_name']) ->limit($this->limitOffset, $this->limitLength) ->order(['label_id' => 'desc']) - ->select() + ->select()->each(function ($item) use($limit){ + $item->limit = $limit; + }) ->toArray(); } diff --git a/app/admin/logic/LoginLogic.php b/app/admin/logic/LoginLogic.php index aaad56466..f52d7981a 100644 --- a/app/admin/logic/LoginLogic.php +++ b/app/admin/logic/LoginLogic.php @@ -19,7 +19,7 @@ use app\common\model\auth\Admin; use app\admin\service\AdminTokenService; use app\common\model\auth\AdminRole; use app\common\service\FileService; -use app\MyBusinessException; +use Exception; use think\facade\Db; use Webman\Config; @@ -44,6 +44,9 @@ class LoginLogic extends BaseLogic { $time = time(); $admin = Admin::where('account', '=', $params['account'])->find(); + if(!$admin) { + throw new Exception('账号不存在'); + } //用户表登录信息更新 $admin->login_time = $time; $admin->login_ip = request()->getLocalIp(); diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index bcecea565..1220fab27 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -127,6 +127,33 @@ class StoreProductLogic extends BaseLogic } } + /* + * 传入三级或者二级分类返还上级分类 一级那全是相同 + */ + public static function dealChangeCate($cate_id) + { + $value =[]; + $last_cate = Db::name('store_category')->where('id',$cate_id)->value('pid'); + if(!empty($last_cate)){ + //2 + $value['two_cate_id'] = $last_cate; + //1 + $first_cate = Db::name('store_category')->where('id',$value['two_cate_id'])->value('pid'); + if(empty($first_cate)){//顶级了 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $last_cate; + }else{ + $value['top_cate_id'] = $first_cate; + } + + }else{ + //1-2 选的1级目录 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $cate_id; + } + return $value; + } + /** * @notes 编辑商品列表 * @param array $params @@ -175,15 +202,15 @@ class StoreProductLogic extends BaseLogic self::updateGoodsclass($params['cate_id'], $value['store_id']); } }*/ - - + $dealCate = self::dealChangeCate($params['cate_id']); //修改 StoreBranchProduct::where('product_id', $params['id'])->update([ 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'cost' => $params['cost'],'unit'=>$params['unit'], 'batch'=>$params['batch'],'store_name'=>$params['store_name'], 'manufacturer_information' => $params['manufacturer_information']??'', - 'store_info' => $params['store_info']??'', + 'store_info' => $params['store_info']??'','cate_id'=>$params['cate_id'], + 'top_cate_id'=>$dealCate['top_cate_id'],'two_cate_id'=>$dealCate['two_cate_id'] ]); Db::commit(); @@ -283,6 +310,7 @@ class StoreProductLogic extends BaseLogic $attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty(); Db::startTrans(); try { + $dealCate = self::dealChangeCate($find['cate_id']); $product = [ 'product_id' => $find['id'], 'image' => $find['image'], @@ -291,6 +319,8 @@ class StoreProductLogic extends BaseLogic 'keyword' => $find['keyword'], 'bar_code' => $find['bar_code'], 'cate_id' => $find['cate_id'], + 'top_cate_id' => $dealCate['top_cate_id'], + 'two_cate_id' => $dealCate['two_cate_id'], 'price' => $find['price'], 'unit' => $find['unit'], 'store_id' => $store_id, diff --git a/app/admin/logic/user/UserLogic.php b/app/admin/logic/user/UserLogic.php index 7a6f7e8a6..3d02c5872 100644 --- a/app/admin/logic/user/UserLogic.php +++ b/app/admin/logic/user/UserLogic.php @@ -89,7 +89,6 @@ class UserLogic extends BaseLogic 'account' => $params['mobile'], 'password' => $password, 'mobile' => $params['mobile'], - 'user_ship' => $params['user_ship']??0, 'label_id' => $params['label_id']??0, ]; diff --git a/app/admin/middleware/OperationLogMiddleware.php b/app/admin/middleware/OperationLogMiddleware.php new file mode 100644 index 000000000..91a553fb9 --- /dev/null +++ b/app/admin/middleware/OperationLogMiddleware.php @@ -0,0 +1,71 @@ +controllerObject->isNotNeedLogin() && empty($request->adminInfo)) { + return $handler($request); + } + //不记录日志操作 + if (strtolower(str_replace('.', '\\', $request->controller)) === 'setting\system\log') { + return $handler($request); + } + + //获取操作注解 + $notes = ''; + try { + $re = new ReflectionClass($request->controllerObject); + $doc = $re->getMethod($request->action)->getDocComment(); + if (empty($doc)) { + throw new Exception('请给控制器方法注释'); + } + preg_match('/\s(\w+)/u', $re->getMethod($request->action)->getDocComment(), $values); + $notes = $values[0]; + } catch (Exception $e) { + $notes = $notes ?: '无法获取操作名称,请给控制器方法注释'; + } + + $params = $request->all(); + + //过滤密码参数 + if (isset($params['password'])) { + $params['password'] = "******"; + } + //过滤密钥参数 + if(isset($params['app_secret'])){ + $params['app_secret'] = "******"; + } + + //导出数据操作进行记录 + if (isset($params['export']) && $params['export'] == 2) { + $notes .= '-数据导出'; + } + //记录日志 + $systemLog = new \app\common\model\OperationLog(); + $systemLog->admin_id = $request->adminInfo['admin_id'] ?? 0; + $systemLog->admin_name = $request->adminInfo['name'] ?? ''; + $systemLog->action = $notes; + $systemLog->account = $request->adminInfo['account'] ?? ''; + $systemLog->url = $request->url(true); + $systemLog->type = $request->post()?'POST':'GET'; + $systemLog->params = json_encode($params, true); + $systemLog->ip = $request->getRemoteIp(); + // $systemLog->result = $response->getContent(); + $systemLog->save(); + return $handler($request); + + } +} \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index cd0862a83..060283c38 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -32,53 +32,7 @@ class IndexController extends BaseApiController public function index() { - $config = [ - // HTTP 请求的超时时间(秒) - 'timeout' => 5.0, - - // 默认发送配置 - 'default' => [ - // 网关调用策略,默认:顺序调用 - 'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class, - - // 默认可用的发送网关 - 'gateways' => [ - 'yunpian', 'aliyun', - ], - ], - // 可用的网关配置 - 'gateways' => [ - 'errorlog' => [ - 'file' => runtime_path() . '/logs/' . date('Ymd') . '/easy-sms.log', - ], - 'aliyun' => [ - 'access_key_id' => 'LTAI5t7mhH3ij2cNWs1zhPmv', - 'access_key_secret' => 'gqo2wMpvi8h5bDBmCpMje6BaiXvcPu', - 'sign_name' => '里海科技', - ], - //... - ], - ]; - - try { - $easySms = new EasySms($config); - $template = getenv('SMS_TEMPLATE'); - $a = $easySms->send(18715753257, [ - 'content' => '您的验证码为: 6379', - 'template' => $template, - 'data' => [ - 'code' => 6379 - ], - ]); -// d($a); - }catch (NoGatewayAvailableException $exception){ - throw new \Exception($exception->getExceptions()); - } - - d($a,getenv('SMS_TEMPLATE')); - - - + return json([1]); $all_where['paid'] = 1; d(OrderLogic::dayPayPrice($all_where,date('Y-m-d',time()))); diff --git a/app/api/controller/LoginController.php b/app/api/controller/LoginController.php index dd8ab2244..a2e35b993 100644 --- a/app/api/controller/LoginController.php +++ b/app/api/controller/LoginController.php @@ -77,7 +77,7 @@ class LoginController extends BaseApiController */ public function updateUser() { - $params = (new WechatLoginValidate())->post()->goCheck("updateUser"); + $params = $this->request->post(); $result = LoginLogic::updateUser($params, $this->userId); if ($result === false) { return $this->fail(LoginLogic::getError()); diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index 2d91c792b..21b5b5b5c 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -77,13 +77,15 @@ class StoreController extends BaseApiController return $this->fail('验证码错误'); } } - $find=User::where('mobile',$params['mobile'])->find(); + if($params['price']>10000){ + return $this->fail('充值金额不能大于10000'); + } + $find=User::where('account|mobile',$params['mobile'])->find(); if(!$find){ $params['create_uid']=$this->userId; $find=UserUserLogic::StoreAdd($params); }else{ $find['real_name']=$params['real_name']; - $find['user_ship']=$params['user_ship']??0; $find['label_id']=$params['label_id']??0; $find->save(); } @@ -99,8 +101,9 @@ class StoreController extends BaseApiController 'other_uid'=>$this->userId, 'staff_id'=>0, 'order_id'=>getNewOrderId('CZ'), - 'price'=>Config::where('name','recharge')->value('value')??1000, + 'price'=>$params['price']??1000, 'recharge_type'=>'INDUSTRYMEMBERS', + 'user_ship'=>$params['user_ship']??0, ]; $order = UserRecharge::create($data); diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index e924419bf..7139e303d 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -6,6 +6,7 @@ namespace app\api\lists\cate; use app\admin\lists\BaseAdminDataLists; use app\common\model\cate\Cate; use app\common\lists\ListsSearchInterface; +use app\common\model\store_branch_product\StoreBranchProduct; use app\Request; use think\facade\Db; @@ -27,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['name', 'data', 'store_id', 'sort', 'pid'], + '=' => ['name', 'data', 'store_id', 'sort'], ]; } @@ -44,10 +45,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function lists(): array { $level = Request()->get('level', 1); - $this->searchWhere[] = ['level', '=', $level]; - $this->searchWhere[] = ['count', '>', 0]; - $this->searchWhere[] = ['delete_time', '=', null]; - $cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('cate_id'); + $pid = $this->request->get('pid',0); + $this->searchWhere[] = ['stock', '>', 0]; + $this->searchWhere[] = ['status', '=', 1]; + if($pid == 0 && $level ==1){ + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('top_cate_id'); + } + if($pid && $level ==2){ + $this->searchWhere[] = ['top_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('two_cate_id'); + } + + if($pid && $level ==3){ + $this->searchWhere[] = ['two_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('cate_id'); + } $lists = []; if ($cate_arr) { return Cate::where('id', 'in', $cate_arr) @@ -56,18 +71,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface ->order(['sort' => 'desc', 'id' => 'desc']) ->select()->toArray(); } - - // ->each(function ($item) { - // $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); - // $item['children'] = $a; - // foreach ($a as $k => &$v) { - // $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); - // $v['children'] = $b; - // } - // })->toArray(); - return $lists; - // return linear_to_tree($lists, 'children'); } @@ -80,8 +84,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { + $level = Request()->get('level', 1); + $pid = $this->request->get('pid',0); + if($pid == 0 && $level ==1){ + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('top_cate_id'); + } - return Db::name('store_product_cate')->where($this->searchWhere) - ->count(); + if($pid && $level ==2){ + $this->searchWhere[] = ['top_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('two_cate_id'); + } + + if($pid && $level ==3){ + $this->searchWhere[] = ['two_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('cate_id'); + } + return Cate::where('id', 'in', $cate_arr)->count(); } } diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index de0fc8e24..d46a21334 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -108,14 +108,16 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists $data= [ 'off_activity' => $this->off_activity, 'total_price' => $this->total_price, - 'msg' => '', + 'msg' => '您已选购满500元,支付成功后即可获得'.bcmul($this->total_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。', 'pay_price' => $this->total_price ]; if($this->off_activity==1){ $data['pay_price']=$this->activity_price; if($this->activity_price<500){ - $data['msg']='还差'.bcsub(500,$this->activity_price,2).'元可获得10%品牌礼品券'; + $data['msg']='还差'.bcsub(500,$this->activity_price,2).'即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。'; $data['pay_price']= $this->activity_price; + }else{ + $data['msg']= '您已选购满500元,支付成功后即可获得'.bcmul($this->activity_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。'; } } return $data; diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index a2aec1a21..9d299fedd 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -33,13 +33,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L public function setSearch(): array { return [ - '=' => ['store_id', 'cate_id'], - '%pipe_like%' => ['store_name' => 'store_name|bar_code'], - ]; - return [ - '=' => ['store_id', 'cate_id'], + '=' => ['store_id', 'cate_id','top_cate_id','two_cate_id'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'], ]; + } /** * @notes 设置支持排序字段 @@ -74,17 +71,17 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L */ public function lists(): array { - $class_all = $this->request->get('class_all'); - if ($class_all) { - //查3级别的 - $arr = Cate::where('pid', $class_all)->column('id'); - if ($arr) { - $arr2 = Cate::where('pid', 'in', $arr)->column('id'); - $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; - } else { - $this->searchWhere[] = ['cate_id', '=', $class_all]; - } - } +// $class_all = $this->request->get('class_all'); +// if ($class_all) { +// //查3级别的 +// $arr = Cate::where('pid', $class_all)->column('id'); +// if ($arr) { +// $arr2 = Cate::where('pid', 'in', $arr)->column('id'); +// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; +// } else { +// $this->searchWhere[] = ['cate_id', '=', $class_all]; +// } +// } $order = $this->request->get('order',''); $field = $this->request->get('field',''); if(empty($order)||empty($field)){ @@ -92,7 +89,7 @@ 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'; + $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'; $this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['stock', '>', 0]; diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index 798b3b577..c4d715a3d 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -441,20 +441,22 @@ class LoginLogic extends BaseLogic */ public static function updateUser($params, $userId) { - $find=User::where(['mobile' =>$params['mobile']])->find(); - if($find){ - $auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的 - if($auth){ - self::$error ='该手机号已绑定'; - return false; - }else{ - UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]); + $data=['is_new_user' => YesNoEnum::NO]; + + if(isset($params['mobile']) && $params['mobile']!=''){ + $data['mobile']=$params['mobile']; + $find=User::where(['mobile' =>$params['mobile']])->find(); + if($find){ + $auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的 + if($auth){ + self::$error ='该手机号已绑定'; + return false; + }else{ + UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]); + } } } - $data=[ - 'mobile'=>$params['mobile'], - 'is_new_user' => YesNoEnum::NO - ]; + if(!empty($params['nickname'])){ $data['nickname'] = $params['nickname']; } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index e033c3815..a50baf6c9 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -15,6 +15,7 @@ use app\common\model\dict\DictData; use app\common\model\dict\DictType; use app\common\model\order\Cart; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; @@ -405,10 +406,11 @@ class OrderLogic extends BaseLogic */ public static function writeOff($params): bool { - $data = StoreOrder::with('store')->where([ + $order = StoreOrder::with('store')->where([ 'verify_code' => $params['verify_code'] ])->find(); - if (empty($data)) { + if (empty($order)) { + self::setError('订单不存在'); return false; } Db::startTrans(); @@ -420,7 +422,7 @@ class OrderLogic extends BaseLogic 'update_time' => time(), 'store_id' => $params['store_id'], 'staff_id' => $params['staff_id']??0, - ], ['id' => $data['id']]); + ], ['id' => $order['id']]); (new StoreOrderCartInfo())->update([ 'verify_code'=>$params['verify_code'].'-1', 'writeoff_time' => time(), @@ -428,20 +430,90 @@ class OrderLogic extends BaseLogic 'store_id' => $params['store_id'], 'staff_id' => $params['staff_id']??0, 'update_time' => time(), - ], ['oid' => $data['id']]); + ], ['oid' => $order['id']]); // $financeFlow = (new StoreFinanceFlowLogic)->getStoreOrder($data['id'], $data['store_id']); // if (!empty($financeFlow)) { // $capitalFlowLogic = new CapitalFlowLogic($data->store, 'store'); // $capitalFlowLogic->storeIncome('store_order_income', 'order', $data['id'], $financeFlow['number']); // } - $order=StoreOrder::where('id',$data['id'])->find(); - // PayNotifyLogic::afterPay($order); PayNotifyLogic::descStock($order['id']); - if($order['uid'] && $order['total_price'] >= 500){ + $financeFlow=new StoreFinanceFlow(); + $financeFlowLogic=new StoreFinanceFlowLogic(); + $select_1=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>['in'=>14,15],'other_uid'=>['>'=>0]])->select(); + foreach($select_1 as $k=>$v){ + $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']); + } + } + $deposit=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>11])->value('number'); + $money=$financeFlow->where(['order_id'=>$order['id'],'financial_pm'=>1,'financial_type'=>2])->value('number'); + $financeFlowLogic->updateStatusStore($order['id'],$order['store_id'],$money,$deposit); + + /* $check = Db::name('user_sign_log')->where('order_id',$order['order_id']) + ->where(['status'=>0]) + ->find();//$check['number']扣的 + if($check){ +// User::where('id',$order['uid'])->inc('purchase_funds',$check['number'])->update(); +// $user_number = bcmul($order['pay_price'], '0.10', 2); + + $base = UserSign::where([ + 'uid'=>$order['uid'], + 'type'=>1, + 'status'=>1 + ])->find(); + $user_sing = new UserSign(); + if($base['number'] > 0 && $base['number'] >= $check['number']){ + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'].'-b', + 'title' => '返还兑换券', + 'financial_pm' => 1, + 'store_id' => $order['store_id'], + 'status' => 1, + ]; + $sing['number'] = $check['number']; + $user_sing->save($sing); + User::where('id',$order['uid'])->inc('integral',$check['number'])->update(); + //减少 + UserSign::where('id',$check['sid'])->dec('number',$check['number'])->update(); + if($base['number'] == $check['number']){ + UserSign::where([ + 'id'=>$order['sid'] + ])->update(['status'=>1]); + } + } + if($base['number'] < $check['number']){ + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'].'-b', + 'title' => '返还兑换券', + 'financial_pm' => 1, + 'store_id' => $order['store_id'], + 'status' => 1, + ]; + $sing['number'] = $base['number']; + $user_sing->save($sing); + + UserSign::where('id',$check['sid'])->dec('number',$base['number'])->update(); + User::where('id',$order['uid'])->inc('integral',$base['number'])->update(); + + + UserSign::where([ + 'id'=>$order['sid'] + ])->update(['status'=>1]); + } + + Db::name('user_sign_log')->where('order_id',$order['order_id'])->update(['status'=>1]); + }*/ Db::commit(); return true; diff --git a/app/api/validate/WechatLoginValidate.php b/app/api/validate/WechatLoginValidate.php index 18425f745..079a744a9 100644 --- a/app/api/validate/WechatLoginValidate.php +++ b/app/api/validate/WechatLoginValidate.php @@ -91,7 +91,7 @@ class WechatLoginValidate extends BaseValidate */ public function sceneUpdateUser() { - return $this->only(['mobile']); + return $this->only([]); } diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 1ffb751c1..6674b96ad 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -46,6 +46,7 @@ class OrderEnum const CASHIER_FACE_PAY = 17;//现金收银 const PURCHASE_FUNDS = 18;//采购款收银 + const USER_ORDER_REFUND = 19;//订单返还 const PAY_BACK =-1; @@ -165,11 +166,7 @@ class OrderEnum self::ORDER_MARGIN=>'保证金', self::VIP_ORDER_OBTAINS=>'会员', self::OTHER_ORDER_OBTAINS=>'其他', - - - - - + self::USER_ORDER_REFUND=>'订单返还' ]; if ($value === true) { diff --git a/app/common/logic/CommissionLogic.php b/app/common/logic/CommissionLogic.php index f9a438e59..072731033 100644 --- a/app/common/logic/CommissionLogic.php +++ b/app/common/logic/CommissionLogic.php @@ -14,7 +14,6 @@ class CommissionLogic extends BaseLogic */ public static function setVillage($order, $transaction_id) { - self::user($order, 0.05, $transaction_id,$order['uid'],14); $village_uid=0; $brigade_uid=0; if ($order['uid'] > 0) { @@ -36,7 +35,8 @@ class CommissionLogic extends BaseLogic } } } - self::user($order, 0.03, $transaction_id,$village_uid,12);//会员 + self::user($order, 0.05, $transaction_id,$village_uid,14);//村长 + self::user($order, 0.03, $transaction_id,0,12);//会员、厨师 self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 self::user($order, 0.01, $transaction_id,0,16);//其他 } @@ -45,7 +45,6 @@ class CommissionLogic extends BaseLogic */ public static function setBrigade($order, $transaction_id) { - self::user($order, 0.05, $transaction_id,$order['uid'],14); $village_uid=0; $brigade_uid=0; if ($order['uid'] > 0) { @@ -67,8 +66,9 @@ class CommissionLogic extends BaseLogic } } } - self::user($order, 0.03, $transaction_id,$village_uid,12);//会员 - self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 + self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长 + self::user($order, 0.03, $transaction_id,0,12);////会员、厨师 + self::user($order, 0.01, $transaction_id,$village_uid,15);//村长 self::user($order, 0.01, $transaction_id,0,16);//其他 } /** @@ -76,7 +76,6 @@ class CommissionLogic extends BaseLogic */ public static function setCook($order, $transaction_id) { - self::user($order, 0.07, $transaction_id,$order['uid'],12);//改到带返还金中 $village_uid=0; $brigade_uid=0; if ($order['uid'] > 0) { @@ -98,6 +97,7 @@ class CommissionLogic extends BaseLogic } } } + self::user($order, 0.07, $transaction_id,0,12);//会员、厨师 self::user($order, 0.01, $transaction_id,$village_uid,14);//村长 self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 self::user($order, 0.01, $transaction_id,0,16);//其他 diff --git a/app/common/logic/PayNotifyLogic copy.php b/app/common/logic/PayNotifyLogic copy.php new file mode 100644 index 000000000..a03f8fd3e --- /dev/null +++ b/app/common/logic/PayNotifyLogic copy.php @@ -0,0 +1,1000 @@ +getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); + throw new \Exception($e->getMessage()); + } + } + + /** + * 余额支付 + * @param $orderSn + * @param $extra + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function balancePay($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + $user = User::where('id', $order['uid'])->find(); + if ($user['now_money'] < $order['pay_price']) { + throw new \Exception('余额不足'); + } + $order->money = $order['pay_price']; + $order->paid = 1; + $order->pay_time = time(); + if (!$order->save()) { + throw new \Exception('订单保存出错'); + } + if($order['is_storage']==1){ + $order->status=2; + UserProductStorageLogic::add($order); + } + // 减去余额 + $user->now_money = bcsub($user['now_money'], $order['pay_price'], 2); + $user->save(); + + if ($order['spread_uid'] > 0 && $user['user_ship'] == 1) { + $oldUser = User::where('id', $order['spread_uid'])->value('purchase_funds'); + if ($oldUser < $order['pay_price']) { + $order['pay_price'] = $oldUser; + } + } + // self::addUserSing($order); + $capitalFlowDao = new CapitalFlowLogic($user); + $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); + self::dealProductLog($order); +// if ($order['shipping_type'] == 3) { +// self::descStock($order['id']); +// } + self::afterPay($order); + if ($extra && $extra['store_id']) { + $params = [ + 'verify_code' => $order['verify_code'], + 'store_id' => $extra['store_id'], + 'staff_id' => $extra['staff_id'] + ]; + OrderLogic::writeOff($params); + } + // Redis::send('push-platform-print', ['id' => $order['id']], 60); + // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); + } + + /** + * 礼品券支付 + * @param $orderSn + * @param $extra + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + + public static function gift_pay($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + $user = User::where('id', $order['uid'])->find(); + if ($user['integral'] < $order['pay_price']) { + throw new \Exception('礼品券不足'); + } + $order->money = $order['pay_price']; + $order->paid = 1; + $order->pay_time = time(); + if (!$order->save()) { + throw new \Exception('订单保存出错'); + } + // 减去礼品券 + $user->integral = bcsub($user['integral'], $order['pay_price'], 2); + $user->save(); + //入礼品券表扣款记录 + $sing[] = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '订单扣除兑换券', + 'store_id' => $order['store_id'], + 'number' => $order['pay_price'], + 'financial_pm' => 0, + 'user_ship' => $user['user_ship'], + ]; + (new UserSign())->saveAll($sing); + + if ($extra && $extra['store_id']) { + $params = [ + 'verify_code' => $order['verify_code'], + 'store_id' => $extra['store_id'], + 'staff_id' => $extra['staff_id'] + ]; + OrderLogic::lessWriteOff($params); + } + self::dealProductLog($order); + } + + + /** + * 采购款支付 + * @param $orderSn + * @param $extra + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function purchase_funds($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + $user = User::where('id', $order['uid'])->find(); + if ($user['purchase_funds'] < $order['pay_price']) { + throw new \Exception('采购款不足'); + } + $order->money = $order['pay_price']; + $order->paid = 1; + $order->pay_time = time(); + if (!$order->save()) { + throw new \Exception('订单保存出错'); + } + if($order['is_storage']==1){ + $order->status=2; + UserProductStorageLogic::add($order); + } + // 减去采购款 + $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); + $user->save(); + + $capitalFlowDao = new CapitalFlowLogic($user); + $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 1, $order['store_id']); + // if ($user['user_ship'] == 1) { + // self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); + // } + // self::addUserSing($order); + self::afterPay($order); + if ($extra && $extra['store_id']) { + $params = [ + 'verify_code' => $order['verify_code'], + 'store_id' => $extra['store_id'], + 'staff_id' => $extra['staff_id'] + ]; + OrderLogic::writeOff($params); + } + self::dealProductLog($order); + // if($order['shipping_type'] == 3){ + // self::descStock($order['id']); + // } + + + // Redis::send('push-platform-print', ['id' => $order['id']], 60); + // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); + } + + /** + * @notes 微信通用回调 + * @param $orderSn + * @param array $extra + * @date 2023/2/27 15:28 + */ + public static function wechat_common($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + + if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + $order->status = 1; + $order->paid = 1; + $order->pay_time = time(); + if($order['is_storage']==1){ + $order->status=2; + UserProductStorageLogic::add($order); + } + if ($order->pay_type != 10) { + $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2); + } else { + $extra['transaction_id'] = time(); + } + $user = User::where('id', $order['uid'])->find(); + if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付 + $order->status = 2; + } else { + $capitalFlowDao = new CapitalFlowLogic($user); + //微信支付和用户余额无关 + $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']); + } + $order->save(); + self::afterPay($order, $extra['transaction_id']); + // self::addUserSing($order); + self::dealProductLog($order); + if ($order['shipping_type'] == 3) { + self::descStock($order['id']); + } + if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { + Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4); + } + return true; + } + + //退款 + public static function refund($orderSn, $extra = []) + { + //更新状态 + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { + //充值 + $orderRe = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); + if ($orderRe->isEmpty() || $orderRe->status == -1) { + return true; + } + $orderRe->status = -1; + $orderRe->refund_price = $orderRe->price; + $orderRe->refund_time = time(); + $orderRe->remarks = ''; + $orderRe->save(); + + return true; + } + $order->status = OrderEnum::REFUND_PAY; + $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; + $order->refund_price = bcdiv($extra['amount']['refund'], 100, 2); + $order->refund_reason_time = time(); + $order->refund_num += 1; + $order->save(); + //日志记录 + //加用户余额,采购款, 日志记录 加数量 + $user = User::where('id', $order['uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + $deal_money = bcdiv($extra['amount']['refund'], 100, 2); + $check_user_sing = UserSign::where('order_id',$order['order_id'])->count(); + if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 + $user->now_money = bcadd($user->now_money, $deal_money, 2); + $user->save(); + //增加数量 + self::addStock($order['id']); + //退款 + $capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); + } + if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款 + $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); + $user->save(); + //增加数量 + self::addStock($order['id']); + //退款 + $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); + } + if($check_user_sing){ + self::descUserSing($order); + } + return true; + } + //积分 + if($check_user_sing){ + self::descUserSing($order); + } + //微信日志 user_order_refund + $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); + //处理财务流水退还 + self::store_finance_back($orderSn); + self::addStock($order['id']); //微信 + return true; + // self::afterPay($order,$extra['transaction_id']); + } + + //退积分 + public static function descUserSing($order) + { + $user_sing = new UserSign(); + if ($order['uid'] > 0 ) { + $user_number = bcmul($order['refund_price'], '0.10', 2); + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '退款扣除兑换券', + 'financial_pm' => 0, + 'store_id' => $order['store_id'], + 'number' => $user_number, + ]; + $user_sing->save($sing); + $now_int = User::where('id',$order['uid'])->find(); + if($now_int){ + if($now_int['integral'] > $user_number){ + User::where('id',$order['uid'])->dec('integral',$user_number)->update(); + }else{ + User::where('id',$order['uid'])->dec('integral',$now_int['integral'])->update(); + } + + } + } + return true; + + } + + + + /** + * 财务退还金额相关 + * @param $orderSn + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function store_finance_back($orderSn) + { + $data = StoreFinanceFlow::where('order_sn', $orderSn) + ->where(['financial_pm' => 1]) + ->select()->toArray(); + foreach ($data as &$value) { + unset($value['id']); + $value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn(); + $value['financial_pm'] = 0; + $value['financial_type'] = OrderEnum::PAY_BACK; + $value['create_time'] = time(); + } + (new StoreFinanceFlow)->saveAll($data); + } + + /** + * 现金退款相关 + * @param $orderSn + * @param $extra + * @return true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function cash_refund($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { + return true; + } + $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; + $order->refund_price = $order->pay_price; + $order->refund_reason_time = time(); + $order->refund_num += 1; + $order->save(); + //日志记录 + $model = new StoreCashFinanceFlow(); + $model->store_id = $order['store_id'] ?? 0; + $model->cash_price = $order->pay_price; + $model->receivable = $order->pay_price; + $model->remark = '退款'; + $model->type = 1; + $model->status = YesNoEnum::YES; + $model->save(); + //增加数量 + self::addStock($order['id']); + return true; + } + + /** + * 充值现金退款相关 + * @param $orderId + * @param $extra + * @return true + */ + public static function recharge_cash_refund($orderId, $extra = []) + { + $order = UserRecharge::where('id', $orderId)->findOrEmpty(); + if ($order->isEmpty() || $order->status == -1) { + return true; + } + $order->status = -1; + $order->refund_price = $order->price; + $order->refund_time = time(); + $order->remarks = ''; + $order->save(); + return true; + } + + //入冻结礼品券 + public static function addUserSing($order) + { + $user_sing = new UserSign(); + if ($order['uid'] > 0 && $order['total_price'] >= 500) { + $user_number = bcmul($order['pay_price'], '0.10', 2); + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '购买商品获得兑换券', + 'financial_pm' => 1, + 'store_id' => $order['store_id'], + 'number' => $user_number, + ]; + $user_sing->save($sing); + } + return true; + } + + + /** + * 充值 + */ + public static function recharge($orderSn, $extra = [], $type = 'wechat') + { + $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); + if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + if ($type == 'wechat') { + $price = bcdiv($extra['amount']['payer_total'], 100, 2); + } else { + $price = $extra['buyer_pay_amount']; + } + $order->price = $price; + $order->paid = 1; + $order->pay_time = time(); + $order->save(); + $uid = $order->uid; + $user = User::where('id', $uid)->findOrEmpty(); + //用户的财务add + $capitalFlowDao = new CapitalFlowLogic($user); + $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price); + + if ($user->isEmpty()) { + return true; + } + bcscale(2); + // $user->now_money = bcadd($user->now_money, $price, 2);//v.1 + //更新等级 + if ($price >= Config::where('name','recharge')->value('value')) { + $user->user_ship = 1; //v.1 + } + $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); + $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); + $user->save(); + if($order['other_uid']>0){ + $uid=$order['other_uid']; + } + PushService::push('wechat_mmp_' . $uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); + PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); + if (!empty($extra['payer']['openid'])) { + Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); + } + return true; + } + + /** + * 现金支付 + */ + public static function cash_pay($orderSn) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + + if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + $order->paid = 1; + $order->pay_time = time(); + $order->status = 2; + if (!$order->save()) { + throw new \Exception('订单保存出错'); + } + self::afterPay($order); + $cashFlowLogic = new CashFlowLogic(); + $cashFlowLogic->insert($order['store_id'], $order['pay_price']); + self::dealProductLog($order); + if ($order['shipping_type'] == 3) { + self::descStock($order['id']); + } + // Redis::send('push-platform-print', ['id' => $order['id']]); + return true; + } + + /** + * @notes 阿里回调 + * @param $orderSn + * @param array $extra + * @author 段誉 + * @date 2023/2/27 15:28 + */ + public static function alipay_cashier($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + + if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + if ($order->pay_type != 10) { + $order->money = $extra['buyer_pay_amount']; + $order->paid = 1; + $order->pay_time = time(); + $order->status = 1; + $order->save(); + } else { + $extra['transaction_id'] = time(); + } + if ($order->pay_type == 9) { + $order->status = 2; + self::afterPay($order); + } + self::dealProductLog($order); + if ($order['shipping_type'] == 3) { + self::descStock($order['id']); + } + + // if ($order->pay_type == 9) { + // $extra['create_time'] = $order['create_time']; + // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); + // Redis::send('push-platform-print', ['id' => $order['id']]); + // } + // else { + // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); + // } + return true; + } + + /** + * 支付后逻辑 + * @param $order + * @return void + */ + public static function afterPay($order, $transaction_id = 0) + { + $financeLogic = new StoreFinanceFlowLogic(); + $user_sing = new UserSign(); + $off_activity = Config::where('name', 'off_activity')->value('value'); + if ($off_activity == 1) { + //-----活动价结算更改 + $financeLogic->order = $order; + $financeLogic->user = ['uid' => $order['uid']]; + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + if ($order['uid'] > 0 && $order['total_price'] > 500 && $order['pay_type'] !=18 + && $order['pay_type'] !=3) { + $user_number = bcmul($order['pay_price'], '0.10', 2); + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '购买商品获得兑换券', + 'financial_pm' => 1, + 'store_id' => $order['store_id'], + 'number' => $user_number, + ]; + $user_sing->save($sing); + } + $financeLogic->save(); + return false; + } + $vipFen = 0; + if ($order['uid'] > 0) { + // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 + //用户下单该用户等级为1得时候才处理冻结金额 + $user = User::where('id', $order['uid'])->find(); + //纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额) + if ($order['spread_uid'] > 0) { + $oldUser = User::where('id', $order['spread_uid'])->field('purchase_funds,user_ship')->find(); + if ($oldUser && $oldUser['user_ship'] == 1) { + if ($oldUser['purchase_funds'] < $order['pay_price']) { + $vipFen = $oldUser['purchase_funds']; + } + } + } elseif ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) { + $vipFrozenAmount = self::dealFrozenPrice($order['id']); + //为1的时候要去减活动价 + // $final_price = bcsub($order['pay_price'],$order['deduction_price'],2); + // d($final_price,$vipFrozenAmount); + $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); + self::dealVipAmount($order, $order['pay_type']); + } + if($order['total_price'] > 500 && $order['pay_type'] !=18 + && $order['pay_type'] !=3){ + $user_number = bcmul($order['pay_price'], '0.10', 2); + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '购买商品获得兑换券', + 'financial_pm' => 1, + 'store_id' => $order['store_id'], + 'number' => $user_number, + 'status' => 0, + ]; + $user_sing->save($sing); + } + + // User::where('id', $order['uid'])->inc('integral', $user_number)->update(); + } + + + $financeLogic->order = $order; + $financeLogic->user = ['uid' => $order['uid']]; + // if ($order->pay_type != 9 || $order->pay_type != 10) { + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $count_frees = 0; + + //平台手续费 + $fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); + $count_frees = bcadd($count_frees, $fees, 2); + if ($fees > 0) { + $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 + $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 + } + // $frozen = bcsub($order->profit, $fees, 2); + //缴纳齐全了就加商户没有就加到平台 + $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); + $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 + $store_profit = bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2); + $count_frees = bcadd($count_frees, $store_profit, 2); + if ($deposit > 0) { + if ($deposit > $store_profit) { + if ($store_profit > 0) { + SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update(); + $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 + } + } else { + $money = bcsub($store_profit, $deposit, 2); + if ($deposit > 0) { + SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update(); + $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + } + if ($money) { + SystemStore::where('id', $order['store_id'])->inc('store_money', $money)->update(); + $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 + } + } + } else { + if ($store_profit > 0) { + SystemStore::where('id', $order['store_id'])->inc('store_money', $store_profit)->update(); + $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 + } + } + // if ($order['is_vip'] >= 1) { + if ($order['spread_uid'] > 0) { + $financeLogic->other_arr['vip_uid'] = $order['spread_uid']; + if ($vipFen) { + $fees = bcdiv(bcmul($vipFen, '0.08', 2), 1, 2); + } else { + $fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2); + } + $count_frees = bcadd($count_frees, $fees, 2); + if ($fees > 0) { + User::where('id', $order['spread_uid'])->inc('now_money', $fees)->update(); + //记录用户余额收入 + $GiveUser = User::where('id', $order['spread_uid'])->find(); + $capitalFlowDao = new CapitalFlowLogic($GiveUser); + $capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees); + + $financeLogic->in($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //vip订单获得 + $financeLogic->out($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + } + } + $fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2); + $count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2); + $village_uid = 0; + $brigade_uid = 0; + //查询用户对应的村长和队长 + if ($order['uid'] > 0) { + $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); + if ($address) { + $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); + if ($arr1) { + $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); + if ($uid) { + User::where('id', $uid)->inc('integral', $fees)->update(); + $village_uid = $uid; + } + } + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); + if ($uid) { + User::where('id', $uid)->inc('integral', $fees)->update(); + $brigade_uid = $uid; + } + } + } + } + if ($fees > 0) { + //村长获得 + // $sing = []; + + // $sing[] = [ + // 'uid' => $village_uid, + // 'order_id' => $order['order_id'], + // 'title' => '村长订单获得兑换券', + // 'store_id' => $order['store_id'], + // 'number' => $fees, + // 'financial_pm' => 1, + // 'user_ship' => 2, + // ]; + // $sing[] = [ + // 'uid' => $brigade_uid, + // 'order_id' => $order['order_id'], + // 'title' => '队长订单获得兑换券', + // 'store_id' => $order['store_id'], + // 'number' => $fees, + // 'financial_pm' => 1, + // 'user_ship' => 3, + // ]; + // $sing[] = [ + // 'uid' => $village_uid, + // 'order_id' => $order['order_id'], + // 'title' => '订单扣除兑换券', + // 'store_id' => $order['store_id'], + // 'number' => $fees, + // 'financial_pm' => 0, + // 'user_ship' => 2, + // ]; + // $sing[] = [ + // 'uid' => $brigade_uid, + // 'order_id' => $order['order_id'], + // 'title' => '订单扣除兑换券', + // 'store_id' => $order['store_id'], + // 'number' => $fees, + // 'financial_pm' => 0, + // 'user_ship' => 3, + // ]; + if ($village_uid > 0) { + SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update(); + $financeLogic->other_arr['vip_uid'] = $village_uid; + } + $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + //队长获得 + if ($brigade_uid > 0) { + SystemStore::where('id', $brigade_uid)->inc('store_money', $fees)->update(); + $financeLogic->other_arr['vip_uid'] = $brigade_uid; + } + $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + // $user_sing->saveAll($sing); + //其他获得 + $financeLogic->other_arr['vip_uid'] = 0; + $financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + } + // } + $fees = bcsub($order['pay_price'], $count_frees, 2); + //供应链订单获得 + if ($fees > 0) { + $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + } + // } + $financeLogic->save(); + // } + } + + /** + * 回调日志 + * @param $order + * @param $extra + * @return void + */ + public static function notifyLog($order, $extra) + { + $data = [ + 'pay_type' => 'wechat', + 'type' => OrderEnum::PAY, + 'amount' => $extra['amount']['payer_total'], //分 + 'order_sn' => $order, + 'out_trade_no' => $extra['transaction_id'], + 'attach' => $extra['attach'], + 'create_time' => date('Y-m-d H:i:s', time()), + ]; + PayNotify::create($data); + } + + /** + * 冻结金额 + * @param $oid + * @return int|mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + + public static function dealFrozenPrice($oid) + { + $detail = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); + $total_vip = 0; + foreach ($detail as $value) { + $total_vip += $value['cart_info']['vip_frozen_price']; + } + return $total_vip; + } + + + /** + * 处理用户为vip1时得冻结资金 + * @param $order + * @param $pay_type + * @param $transaction_id + * @return true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function dealVipAmount($order, $pay_type = 1, $transaction_id = 0) + { + $total_vip = self::dealFrozenPrice($order['id']); + $data = [ + 'order_id' => $order['id'], + 'transaction_id' => $transaction_id ?? 0, + 'order_sn' => $order['order_id'], + 'user_id' => $order['uid'], + 'number' => $total_vip, + 'pay_type' => $pay_type ?? 1, + 'status' => 0, + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], + 'create_time' => time() + ]; + Db::name('vip_flow')->insert($data); + return true; + } + + /** + * 商品统计逻辑 + * @param $order + * @return true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function dealProductLog($order) + { + $store_id = $order['store_id']; + $cart_id = $order['cart_id']; + $uid = $order['uid']; + if ($uid && $cart_id && $store_id) { + $cart_id = explode(',', $cart_id); + $productLog = StoreProductLog::where([ + 'uid' => $uid + ])->whereIn('cart_id', $cart_id) + ->select()->toArray(); + + foreach ($productLog as &$value) { + $value['pay_uid'] = $uid; + $value['oid'] = $order['id']; + $cart_info = StoreOrderCartInfo::where([ + 'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'store_id' => $store_id + ])->find(); + $value['order_num'] = $cart_info['cart_num'] ?? 1; + $value['pay_num'] = $cart_info['cart_num'] ?? 1; + $value['pay_price'] = $cart_info['price'] ?? 0; + $value['cost_price'] = $cart_info['cart_info']['cost'] ?? 0; + $value['update_time'] = time(); + unset($value['create_time'], $value['delete_time']); + } + + (new StoreProductLog())->saveAll($productLog); + } + return true; + } + + + public static function descSwap($oid) + { + $updateData = []; + $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); + foreach ($goods_list as $v) { + $StoreBranchProduct = StoreBranchProduct::where( + [ + 'store_id' => $v['store_id'], + 'product_id' => $v['product_id'], + ] + )->withTrashed()->find(); + $updateData[] = [ + 'id' => $StoreBranchProduct['id'], + 'swap' => $StoreBranchProduct['swap'] - $v['cart_num'], + 'sales' => ['inc', $v['cart_num']] + ]; + } + + (new StoreBranchProduct())->saveAll($updateData); + } + + + /** + * 扣库存 + * @param $oid + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function descStock($oid) + { + $updateData = []; + $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); + foreach ($goods_list as $v) { + $StoreBranchProduct = StoreBranchProduct::where( + [ + 'store_id' => $v['store_id'], + 'product_id' => $v['product_id'], + ] + )->withTrashed()->find(); + if ($StoreBranchProduct) { + $updateData[] = [ + 'id' => $StoreBranchProduct['id'], + 'stock' => $StoreBranchProduct['stock'] - $v['cart_num'], + 'sales' => ['inc', $v['cart_num']] + ]; + } + } + + (new StoreBranchProduct())->saveAll($updateData); + } + + /** + * 加库存 + * @param $oid + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function addStock($oid) + { + $updateData = []; + $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); + foreach ($goods_list as $v) { + $StoreBranchProduct = StoreBranchProduct::where( + [ + 'store_id' => $v['store_id'], + 'product_id' => $v['product_id'], + ] + )->withTrashed()->find(); + if ($StoreBranchProduct) { + $updateData[] = [ + 'id' => $StoreBranchProduct['id'], + 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], + // 'sales' => ['inc', $v['cart_num']] + // 'sales' => ['inc', $v['cart_num']] + ]; + } + } + + (new StoreBranchProduct())->saveAll($updateData); + } +} diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index efa099861..86ea0a28e 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -25,6 +25,8 @@ use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; use app\common\model\user\UserShip; use app\common\model\user_sign\UserSign; +use app\common\model\vip_flow\VipFlow; +use app\common\service\Curl; use app\common\service\PushService; use support\Log; use think\facade\Db; @@ -92,10 +94,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']) { + $params = [ + 'verify_code' => $order['verify_code'], + 'store_id' => $extra['store_id'], + 'staff_id' => $extra['staff_id'] + ]; + OrderLogic::writeOff($params); + } // Redis::send('push-platform-print', ['id' => $order['id']], 60); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } @@ -186,6 +196,7 @@ class PayNotifyLogic extends BaseLogic // self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); // } // self::addUserSing($order); + self::afterPay($order); if ($extra && $extra['store_id']) { $params = [ 'verify_code' => $order['verify_code'], @@ -195,14 +206,163 @@ class PayNotifyLogic extends BaseLogic OrderLogic::writeOff($params); } self::dealProductLog($order); +// $count = UserSign::where([ +// 'uid'=>$order['uid'], +// 'type'=>1, +// 'status'=>0 +// ])->count(); +// +// if($count){ +// self::addFlowLog($order); +// } // if($order['shipping_type'] == 3){ // self::descStock($order['id']); // } - self::afterPay($order); + // Redis::send('push-platform-print', ['id' => $order['id']], 60); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } + + //采购款支付后如果有对应的冻结的话就去反对应的log + public static function addFlowLog($order) + { + //查询当前用户有无对应的充值的冻结金额 + if($order['uid'] >0){ + $query = UserSign::where([ + 'uid'=>$order['uid'], + 'type'=>1, + 'status'=>0 + ]); +// $query1 = clone $query; +// $ids = $query->column('id'); + $check = $query->sum('number'); +// $count = $query1->count(); + if($check && $check >0){ + $backPurchase = bcmul($order['pay_price'],0.1,2); + +// if($count == 1){ + //存在拆单子否 + //少了就冻结减去这个对应的金额 + $one = UserSign::where([ + 'uid'=>$order['uid'], + 'type'=>1, + 'status'=>0 + ])->find(); + $data = [ + 'sid'=>$one['id'], + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '充值获得冻结兑换券', + 'financial_pm' => 1, + 'type' => 1, + 'status' => 1, + ]; + + if($one['number'] >= $backPurchase){ +// $wait = bcsub($one['number'],$backPurchase,2)??0; + $data['number'] =$backPurchase; + + Db::name('user_sign_log')->insert($data); + + //总的减去采购款百分之十剩余的 +// if(empty($wait)){ +// UserSign::where('id',$one['id'])->update( +// [ +// 'number'=>0, +// 'status'=>1 +// ] +// ); +// }else{ +// //add +// UserSign::where('id',$one['id'])->update( +// [ +// 'number'=>$wait +// ] +// ); +// } + + //并且加到对应的用户的采购款中 +// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); + } + else{ + //对比采购款支付的多少 多了就拿冻结金额即可 + $data['number'] =$one['number']; + //都存到对应的log日志 + Db::name('user_sign_log')->insert($data); +// UserSign::where('id',$one['id'])->update( +// [ +// 'number'=>0, +// 'status'=>1 +// ] +// ); + //并且加到对应的用户的采购款中 +// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); + } + + } + /* else{ + //大于0的时候 + //先处理金额大的再处理剩余的 + //把所有的金额改为正的再加一条后再加 + UserSign::where([ + 'uid'=>$order['uid'], + 'type'=>1, + 'status'=>0 + ])->update([ + 'status'=>1, + 'title'=>json_encode($ids) + ]); + if ($check >= $backPurchase) { + //补一条待解冻的 + $left = bcsub($check,$backPurchase,2); + if($left > 0){ + $data = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '补冻结兑换券', + 'financial_pm' => 0, + 'type' => 1, + ]; + $data['number'] =$check; + $sid = Db::name('user_sign')->insertGetId($data); + + $data = [ + 'uid' => $order['uid'], + 'sid' => $sid, + 'order_id' => $order['order_id'], + 'title' => '充值获得冻结兑换券', + 'financial_pm' => 1, + 'type' => 1, + ]; + $data['number'] =$backPurchase; + Db::name('user_sign_log')->insert($data); + } +// User::where('id',$order['uid'])->inc('purchase_funds',$backPurchase)->update();//add + + }else{ + //log + $data = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '充值获得冻结兑换券', + 'financial_pm' => 1, + 'type' => 1, + ]; + $data['number'] =$check; + Db::name('user_sign_log')->insert($data); +// User::where('id',$order['uid'])->inc('purchase_funds',$check)->update();//add + } + + }*/ + +// } + return true; + + } + + return true; + } /** * @notes 微信通用回调 @@ -280,7 +440,7 @@ 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(); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 $user->now_money = bcadd($user->now_money, $deal_money, 2); @@ -290,7 +450,6 @@ 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(); @@ -299,6 +458,14 @@ class PayNotifyLogic extends BaseLogic //退款 $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); } + if($check_user_sing){ + self::descUserSing($order); + } + return true; + } + //积分 + if($check_user_sing){ + self::descUserSing($order); } //微信日志 user_order_refund $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); @@ -308,9 +475,38 @@ class PayNotifyLogic extends BaseLogic return true; // self::afterPay($order,$extra['transaction_id']); } + + //退积分 + public static function descUserSing($order) + { + $user_sing = new UserSign(); + if ($order['uid'] > 0 ) { + $user_number = bcmul($order['refund_price'], '0.10', 2); + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '退款扣除兑换券', + 'financial_pm' => 0, + 'store_id' => $order['store_id'], + 'number' => $user_number, + ]; + $user_sing->save($sing); + $now_int = User::where('id',$order['uid'])->find(); + if($now_int){ + if($now_int['integral'] > $user_number){ + User::where('id',$order['uid'])->dec('integral',$user_number)->update(); + }else{ + User::where('id',$order['uid'])->dec('integral',$now_int['integral'])->update(); + } + + } + } + return true; + } + /** * 财务退还金额相关 * @param $orderSn @@ -357,7 +553,6 @@ class PayNotifyLogic extends BaseLogic //日志记录 $model = new StoreCashFinanceFlow(); $model->store_id = $order['store_id'] ?? 0; - $model->store_id = $order['store_id'] ?? 0; $model->cash_price = $order->pay_price; $model->receivable = $order->pay_price; $model->remark = '退款'; @@ -399,6 +594,7 @@ class PayNotifyLogic extends BaseLogic 'uid' => $order['uid'], 'order_id' => $order['order_id'], 'title' => '购买商品获得兑换券', + 'financial_pm' => 1, 'store_id' => $order['store_id'], 'number' => $user_number, ]; @@ -407,6 +603,27 @@ class PayNotifyLogic extends BaseLogic 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; + } + /** * 充值 @@ -438,15 +655,20 @@ class PayNotifyLogic extends BaseLogic bcscale(2); // $user->now_money = bcadd($user->now_money, $price, 2);//v.1 //更新等级 - if ($price >= Config::where('name','recharge')->value('value')) { - $user->user_ship = 1; //v.1 - } + $user->user_ship = $order['user_ship']; + $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); $user->save(); if($order['other_uid']>0){ $uid=$order['other_uid']; } + $check = UserSign::where(['uid'=>$order->uid,'type'=>1])->count(); + if(empty($check)){ + self::dealRechargeFrozen($order); + + } + PushService::push('wechat_mmp_' . $uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); if (!empty($extra['payer']['openid'])) { @@ -542,13 +764,14 @@ class PayNotifyLogic extends BaseLogic $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - if ($order['uid'] > 0 && $order['total_price'] > 500 && $order['pay_type'] !=18 - && $order['pay_type'] !=3) { + $financeLogic->save(); + 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, ]; @@ -577,13 +800,13 @@ class PayNotifyLogic extends BaseLogic $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); self::dealVipAmount($order, $order['pay_type']); } - if($order['total_price'] > 500 && $order['pay_type'] !=18 - && $order['pay_type'] !=3){ + if($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, 'status' => 0, @@ -617,46 +840,35 @@ class PayNotifyLogic extends BaseLogic if ($deposit > 0) { if ($deposit > $store_profit) { if ($store_profit > 0) { - SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update(); + // SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update(); $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 } } else { $money = bcsub($store_profit, $deposit, 2); if ($deposit > 0) { - SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update(); + // SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update(); $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); } if ($money) { - SystemStore::where('id', $order['store_id'])->inc('store_money', $money)->update(); + // 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(); + // SystemStore::where('id', $order['store_id'])->inc('store_money', $store_profit)->update(); $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 } } // if ($order['is_vip'] >= 1) { if ($order['spread_uid'] > 0) { - $financeLogic->other_arr['vip_uid'] = $order['spread_uid']; if ($vipFen) { $fees = bcdiv(bcmul($vipFen, '0.08', 2), 1, 2); } else { $fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2); } $count_frees = bcadd($count_frees, $fees, 2); - if ($fees > 0) { - User::where('id', $order['spread_uid'])->inc('now_money', $fees)->update(); - //记录用户余额收入 - $GiveUser = User::where('id', $order['spread_uid'])->find(); - $capitalFlowDao = new CapitalFlowLogic($GiveUser); - $capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees); - - $financeLogic->in($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //vip订单获得 - $financeLogic->out($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } } $fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2); $count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2); @@ -670,7 +882,7 @@ class PayNotifyLogic extends BaseLogic if ($arr1) { $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); if ($uid) { - User::where('id', $uid)->inc('integral', $fees)->update(); + // User::where('id', $uid)->inc('integral', $fees)->update(); $village_uid = $uid; } } @@ -678,7 +890,7 @@ class PayNotifyLogic extends BaseLogic if ($arr2) { $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); if ($uid) { - User::where('id', $uid)->inc('integral', $fees)->update(); + // User::where('id', $uid)->inc('integral', $fees)->update(); $brigade_uid = $uid; } } @@ -725,14 +937,14 @@ class PayNotifyLogic extends BaseLogic // 'user_ship' => 3, // ]; if ($village_uid > 0) { - SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update(); + // SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update(); $financeLogic->other_arr['vip_uid'] = $village_uid; } $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //队长获得 if ($brigade_uid > 0) { - SystemStore::where('id', $brigade_uid)->inc('store_money', $fees)->update(); + // SystemStore::where('id', $brigade_uid)->inc('store_money', $fees)->update(); $financeLogic->other_arr['vip_uid'] = $brigade_uid; } $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index fab958091..f5bb794f9 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -5,6 +5,8 @@ namespace app\common\logic; use app\common\enum\OrderEnum; use app\common\enum\PayEnum; use app\common\model\store_finance_flow\StoreFinanceFlow; +use app\common\model\system_store\SystemStore; +use app\common\model\user\User; class StoreFinanceFlowLogic extends BaseLogic { @@ -126,4 +128,28 @@ class StoreFinanceFlowLogic extends BaseLogic $model->save(); } + /** + * 核销后更新用户余额 + */ + public function updateStatusUser($id,$uid,$money,$order_id){ + StoreFinanceFlow::where('id', $id)->update(['status' => 1]); + $find=User::where('id',$uid)->find(); + $capitalFlowDao = new CapitalFlowLogic($find); + $capitalFlowDao->userIncome('system_balance_add', 'order', $order_id, $money); + $find->inc('now_money',$money)->update(); + } + /** + * 核销后更新门店余额 + */ + public function updateStatusStore($order_id,$store_id,$money,$deposit){ + StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>11])->update(['status' => 1]); + StoreFinanceFlow::where(['order_id'=>$order_id,'financial_pm'=>1,'financial_type'=>2])->update(['status' => 1]); + if($money){ + SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); + } + if($deposit){ + SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); + } + } + } diff --git a/app/queue/redis/OrderWetchaPushSend.php b/app/queue/redis/OrderWetchaPushSend.php new file mode 100644 index 000000000..0f6315125 --- /dev/null +++ b/app/queue/redis/OrderWetchaPushSend.php @@ -0,0 +1,68 @@ +value('name'); + $cart_info=StoreOrderCartInfo::where('oid',$order['id'])->field('cart_info')->select(); + $product_info="\r\n>商品信息:------------------"; + foreach($cart_info as $k=>$v['cart_info']){ + $a=$v['cart_info']['cart_info']['name'].' 数量:'.$v['cart_info']['cart_info']['cart_num'].' 价格:'.$v['cart_info']['cart_info']['pay_price'].'元'; + $product_info.="\r\n>$a"; + } + $arr = ["msgtype" => "markdown", "markdown" => ["content" => "有新的订单请及时跟踪 + >订单号:$order_id + >门店信息:$store_name" + .$product_info + ."\r\n>下单时间:$pay_time + >订单金额:$total_price + >支付金额:$pay_price + >支付方式:$pay_type + >下单用户手机号:$phone"]]; + (new Curl())->postJson($url, json_encode($arr)); + } + } + // 消费失败时 + public function onConsumeFailure(\Throwable $exception, $package) + { + $package['max_attempts'] = 0; + Log::error('推送订单失败', ['order_id' => $package['data'], 'error' => $package['error']]); + return true; + } +} diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php index 02e7eefe6..04f5ad9ba 100644 --- a/app/queue/redis/StoreStorageSend.php +++ b/app/queue/redis/StoreStorageSend.php @@ -46,6 +46,7 @@ class StoreStorageSend implements Consumer $attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty(); Db::startTrans(); try { + $dealCate = self::dealChangeCate($find['cate_id']); $product = [ 'product_id' => $find['id'], 'image' => $find['image'], @@ -54,6 +55,8 @@ class StoreStorageSend implements Consumer 'keyword' => $find['keyword'], 'bar_code' => $find['bar_code'], 'cate_id' => $find['cate_id'], + 'top_cate_id' => $dealCate['top_cate_id'], + 'two_cate_id' => $dealCate['two_cate_id'], 'price' => $find['price'], // 'cost' => $find['cost'], //v1.0 'cost' => $find['cost'], @@ -179,4 +182,31 @@ class StoreStorageSend implements Consumer Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); return $package; } + + /* + * 传入三级或者二级分类返还上级分类 一级那全是相同 + */ + public static function dealChangeCate($cate_id) + { + $value =[]; + $last_cate = Db::name('store_category')->where('id',$cate_id)->value('pid'); + if(!empty($last_cate)){ + //2 + $value['two_cate_id'] = $last_cate; + //1 + $first_cate = Db::name('store_category')->where('id',$value['two_cate_id'])->value('pid'); + if(empty($first_cate)){//顶级了 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $last_cate; + }else{ + $value['top_cate_id'] = $first_cate; + } + + }else{ + //1-2 选的1级目录 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $cate_id; + } + return $value; + } } diff --git a/app/statistics/logic/OrderLogic.php b/app/statistics/logic/OrderLogic.php index 3f1617ac7..274653768 100644 --- a/app/statistics/logic/OrderLogic.php +++ b/app/statistics/logic/OrderLogic.php @@ -67,6 +67,18 @@ class OrderLogic extends BaseLogic return bcadd($todayAmount, $pay_price, 2); } + public static function dealFlexiblePrice($where,$start,$end) + { + $todayAmount = UserRecharge::where($where) + ->whereBetweenTime('create_time', $start, $end) + ->sum('price'); + $pay_price = StoreOrder::where($where) + ->whereBetweenTime('create_time', $start, $end) + ->sum('pay_price'); + return bcadd($todayAmount, $pay_price, 2); + + } + public static function sales($where,$time){ $select=StoreOrder::where($where)->whereDay('create_time',$time)->limit(10)->order('id desc')->field('id,order_id,pay_price,create_time')->select(); return $select?->toArray(); diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 1b14fec01..6527e6e78 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -174,6 +174,13 @@ class StoreOrderController extends BaseAdminController $order = OrderLogic::createOrder($cartId, $addressId, $user, $params); if ($order != false) { switch ($pay_type) { + case PayEnum::BALANCE_PAY: + //余额支付 + PayNotifyLogic::handle('balancePay', $order['order_id'],[ + 'store_id' => $this->request->adminInfo['store_id'], + 'staff_id' => $this->request->adminInfo['admin_id'] + ]); + return $this->success('余额支付成功'); case PayEnum::PURCHASE_FUNDS: //采购款支付 PayNotifyLogic::handle('purchase_funds', $order['order_id'], [ @@ -248,9 +255,17 @@ class StoreOrderController extends BaseAdminController return $this->fail('订单不存在或已支付'); } switch ($pay_type) { + case PayEnum::BALANCE_PAY: + //余额支付 + PayNotifyLogic::handle('balancePay', $order['order_id'],[ + 'store_id' => $this->request->adminInfo['store_id'], + 'staff_id' => $this->request->adminInfo['admin_id'] + ]); + return $this->success('余额支付成功'); case PayEnum::PURCHASE_FUNDS: //采购款支付 - PayNotifyLogic::handle('purchase_funds', $order['order_id'], ['uid' => $order['uid']]); + PayNotifyLogic::handle('purchase_funds', $order['order_id'], ['uid' => $order['uid'],'store_id' => $this->request->adminInfo['store_id'], + 'staff_id' => $this->request->adminInfo['admin_id']]); return $this->success('采购款支付成功', ['id' => $order['id']]); case PayEnum::CASH_PAY: //现金支付 @@ -343,12 +358,6 @@ class StoreOrderController extends BaseAdminController */ public function rechange_amount() { - // $order = UserRecharge::where('order_id','CZ1719052252643357')->find(); - // $order['pay_price'] = $order['price']; - // d(1); - // PayNotifyLogic::handle('recharge', $order['order_id'], $order); - - // d(1); $pay_type = $this->request->post('pay_type'); $auth_code = $this->request->post('auth_code'); //微信支付条码 if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) { @@ -362,6 +371,7 @@ class StoreOrderController extends BaseAdminController 'order_id' => getNewOrderId('CZ'), 'price' => $params['price'], 'recharge_type' => 'INDUSTRYMEMBERS', + 'user_ship'=>$params['user_ship']??0, ]; $order = UserRecharge::create($data); $order['pay_price'] = $order['price']; diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index 72431a400..748df2080 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -84,7 +84,8 @@ class WorkbenchLogic extends BaseLogic $data['income_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); //门店收款金额 $all_where['paid'] = 1; - $data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time())); +// $data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time())); + $data['receipt_amount'] = OrderLogic::dealFlexiblePrice($all_where,$startTime,$endTime); // $data['receipt_amount'] = UserRecharge::where($userRechargeWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('price'); //保证金金额 $data['deposit_amount'] = StoreFinanceFlow::where($storeFinanceWhereTwo)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); diff --git a/config/middleware.php b/config/middleware.php index f2a5297fd..537b58ac2 100644 --- a/config/middleware.php +++ b/config/middleware.php @@ -23,6 +23,8 @@ return [ app\admin\middleware\LoginMiddleware::class, // 权限认证 app\admin\middleware\AuthMiddleware::class, + // 操作日志记录 + app\admin\middleware\OperationLogMiddleware::class, ], 'api' => [ // 跨域中间件