wugg 4 månader sedan
förälder
incheckning
8f8eaceeb8
4 ändrade filer med 75 tillägg och 24 borttagningar
  1. 19 13
      app/admin/controller/GoodZx.php
  2. 0 1
      app/event.php
  3. 17 10
      app/middleware/HttpLog.php
  4. 39 0
      app/user/model/SystemLog.php

+ 19 - 13
app/admin/controller/GoodZx.php

@@ -89,29 +89,35 @@ class GoodZx extends Base{
         $good_tax->out_tax = $param['out_tax'];
         $good_tax->cgd_tax_id = $param['cgd_tax_id'];
         $good_tax->cgd_tax = $param['cgd_tax'];
-        $good_tax->createrid=$this->uid;
-        $good_tax->creater=$this->uname;
+        $good_tax->createrid=$good_tax->createrid??$this->uid;
+        $good_tax->creater=$good_tax->creater??$this->uname;
         $this->model->startTrans();
         try{
             $save=$good_tax->save();
             if($save==false) throw new \Exception("添加失败");
             if($param['isToSale']==1){
                 $sale = \app\admin\model\Sale::where("good_code","=",$param['spuCode'])->findOrEmpty();
-                if($sale->isEmpty()) return error("咨询销售单不存在");
-                $sale->updatetime=date('Y-m-d H:i:s');
-                $sale->save();
-                if($sale->save()==false) throw new \Exception("同步销售单失败");
+                if(!$sale->isEmpty()){
+                    $sale->updatetime=date('Y-m-d H:i:s');
+                    $sale->save();
+                    if($sale->save()==false) throw new \Exception('同步销售单失败');
+                }
                 OrderTax::where(["spuCode"=>$param['spuCode'],"code"=>$sale->orderCode])->delete();
                 OrderCategory::where(["spuCode"=>$param['spuCode']])->whereNotLike("code","CG%")
                 ->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
             }
             if($param['isToCgd']==1){
                 $cgd = \app\admin\model\PurcheaseOrder::where("spuCode","=",$param['spuCode'])->findOrEmpty();
-                if($cgd->isEmpty()) return error("咨询采购单不存在");
-                $cgd->updatetime=date('Y-m-d H:i:s');
-                if($cgd->save()==false) throw new \Exception("同步采购单失败");
-                OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete();
-                OrderCategory::where(["spuCode"=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
+                if(!$cgd->isEmpty()) {
+                    $cgd->updatetime=date('Y-m-d H:i:s');
+                    if($cgd->save()==false) throw new \Exception('同步采购单失败');
+                     OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete();
+                     OrderCategory::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']);
+
+                }else{
+                    OrderTax::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->delete();
+                    OrderCategory::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']);
+                }
             }
             if($param['isToGood']==1){
                 $good->updatetime=date('Y-m-d H:i:s');
@@ -121,9 +127,9 @@ class GoodZx extends Base{
             $this->model->commit();
         }catch (\Exception $e){
             $this->model->rollback();
-            return error("添加失败");
+            return error($e->getMessage());
         }
-        return success("添加成功");
+        return success("更新成功");
     }
 
     public function info(){

+ 0 - 1
app/event.php

@@ -17,7 +17,6 @@ return [
         "copyCompany"=>[\app\listener\CopyCompany::class],
         "updateSupplierGood"=>[app\admin\listener\updateSupplierGood::class],
         "report_code"=>[app\cxinv\listener\ReportCode::class],
-        "voucher"=>[app\youzan\listener\Voucher::class],
     ],
 
     'subscribe' => [

+ 17 - 10
app/middleware/HttpLog.php

@@ -3,9 +3,10 @@ declare (strict_types = 1);
 
 namespace app\middleware;
 
-use think\facade\Log;
+use app\user\model\SystemLog;use think\facade\Cache;use think\facade\Route;
 class HttpLog
 {
+    private $logid;
     /**
      * 处理请求
      *
@@ -18,19 +19,25 @@ class HttpLog
         if ($request->isOptions()) {
             error('OPTIONS请求');
         }
+        $response = $next($request);
+        $token=$request->param('token');
+        $userinfo = Cache::get('user:info:'.$token);
         $data=[
-        	'url'=>array_values(array_filter(explode('/',$request->url()))),
-        	'method'=>$request->method(),
-        	'ip'=>$request->ip(),
-        	'param'=>$request->param(),
-        	'addtime'=>date('Y-m-d H:i:s')
-        ];
-        Log::info(json_encode($data,JSON_UNESCAPED_UNICODE));
-        return $next($request);
+                'system' =>strtolower(ltrim($request->root(),"/")),
+                'controller' => strtolower($request->controller()),
+                'action' =>strtolower($request->action()),
+                'param' =>json_encode($request->param(),JSON_UNESCAPED_UNICODE),
+                'response' =>"[]",
+                'action_id' => $userinfo->id??0,
+                'action_name' => $userinfo->nickname??'system'
+                ];
+        $log=SystemLog::create($data);
+        $this->logid=$log->id;
+        return  $response;
     }
 
     public function end(\think\Response $response)
     {
-        Log::info('响应结束:'.json_encode($response->getData(),JSON_UNESCAPED_UNICODE));
+       SystemLog::where('id',$this->logid)->update(['response'=>json_encode($response->getData(),JSON_UNESCAPED_UNICODE)]);
     }
 }

+ 39 - 0
app/user/model/SystemLog.php

@@ -0,0 +1,39 @@
+<?php
+
+
+namespace app\user\model;
+
+
+class SystemLog extends Base{
+//    CREATE TABLE `sys_system_log` (
+//      `id` bigint(20) NOT NULL AUTO_INCREMENT,
+//      `system` varchar(255) NOT NULL,
+//      `controller` varchar(255) NOT NULL,
+//      `action` varchar(255) NOT NULL,
+//      `param` text NOT NULL,
+//      `response` text NOT NULL,
+//      `action_name` varchar(255) NOT NULL,
+//      `action_id` int(11) NOT NULL,
+//      `createTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+//      PRIMARY KEY (`id`)
+//    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
+
+    protected $schema = [
+        'id' => 'bigint',
+        'system' => 'string',
+        'controller' => 'string',
+        'action' => 'string',
+        'param' => 'text',
+        'response' => 'text',
+        'action_name' => 'string',
+        'action_id' => 'int',
+        'createTime' => 'datetime',
+    ];
+    protected $json = ['param','response'];
+    protected $type = [
+        'id' => 'integer',
+        'createTime' => 'datetime',
+    ];
+    protected $createTime = 'createTime';
+
+}