From b812b36e3ec0741f0239d0904890e5adba2f8419 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 27 Jun 2024 13:46:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86StoreProduct?= =?UTF-8?q?Lists.php,=20LoginLogic.php,=20OperationLogMiddleware.php,=20In?= =?UTF-8?q?dexController.php,=20OrderEnum.php,=20CommissionLogic.php,=20St?= =?UTF-8?q?oreFinanceFlowLogic.php,=20StoreOrderController.php,=20middlewa?= =?UTF-8?q?re.php=E7=AD=89=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_product/StoreProductLists.php | 2 +- app/admin/logic/LoginLogic.php | 5 +- .../middleware/OperationLogMiddleware.php | 71 +++++++++++++++++++ app/api/controller/IndexController.php | 48 +------------ app/common/enum/OrderEnum.php | 7 +- app/common/logic/CommissionLogic.php | 12 ++-- app/common/logic/StoreFinanceFlowLogic.php | 10 +++ .../store_order/StoreOrderController.php | 6 -- config/middleware.php | 2 + 9 files changed, 97 insertions(+), 66 deletions(-) create mode 100644 app/admin/middleware/OperationLogMiddleware.php diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 360cda90..ceabcc76 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -58,7 +58,7 @@ 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) { diff --git a/app/admin/logic/LoginLogic.php b/app/admin/logic/LoginLogic.php index aaad5646..f52d7981 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/middleware/OperationLogMiddleware.php b/app/admin/middleware/OperationLogMiddleware.php new file mode 100644 index 00000000..91a553fb --- /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 cd0862a8..060283c3 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/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 1ffb751c..6674b96a 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 f9a438e5..07273103 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/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index fab95809..01a9e59c 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -5,6 +5,7 @@ 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\user\User; class StoreFinanceFlowLogic extends BaseLogic { @@ -126,4 +127,13 @@ class StoreFinanceFlowLogic extends BaseLogic $model->save(); } + /** + * 核销后更新余额 + */ + public function updateStatusUser($id,$uid,$money){ + StoreFinanceFlow::where('id', $id)->update(['status' => 1]); + User::where('id',$uid)->inc('now_money',$money)->update(); + } + + } diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index c1780917..fbaa308e 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -358,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) { diff --git a/config/middleware.php b/config/middleware.php index f2a5297f..537b58ac 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' => [ // 跨域中间件