xxxrrrdddd il y a 2 ans
Parent
commit
a1d87ba8bc

+ 2 - 2
application/admin/controller/Mobile.php

@@ -201,7 +201,7 @@ class Mobile extends Backend
         }else{
             Db::startTrans();
             $data=input('row/a');
-            (new MobilePriceLogService)->setMobile($mobile)->setAdminId($this->auth->id)->setBeforePrice($mobile['amount_base'])->setAfterPrice($data['amount_base'])->log();
+            //(new MobilePriceLogService)->setMobile($mobile)->setAdminId($this->auth->id)->setBeforePrice($mobile['amount_base'])->setAfterPrice($data['amount_base'])->log();
             $mobile->allowField(true)->save($data);
             Db::commit();
             $this->success();
@@ -228,7 +228,7 @@ class Mobile extends Backend
                     $data['city_id']=\app\common\model\Area::getIdByName($data['city']);
                 }
                 if(isset($data['amount_base'])) {
-                    (new MobilePriceLogService)->setMobile($mobile)->setAdminId($this->auth->id)->setBeforePrice($mobile['amount_base'])->setAfterPrice($data['amount_base'])->log();
+                    //(new MobilePriceLogService)->setMobile($mobile)->setAdminId($this->auth->id)->setBeforePrice($mobile['amount_base'])->setAfterPrice($data['amount_base'])->log();
                 }
                 $mobile->allowField(true)->save($data);
                 $describe=$data['describe']??'';

+ 1 - 0
application/common/controller/Backend.php

@@ -152,6 +152,7 @@ class Backend extends Controller
                 }
                 $this->error(__('Please login first'), url('index/login', ['url' => $url]));
             }
+            $_SERVER['admin']=$this->auth->getUserInfo();
             // 判断是否需要验证权限
             if (!$this->auth->match($this->noNeedRight)) {
                 // 判断控制器和方法是否有对应权限

+ 9 - 0
application/common/model/Mobile.php

@@ -4,6 +4,7 @@ namespace app\common\model;
 
 use app\admin\model\Admin;
 use app\common\service\MobileComputer;
+use app\common\service\MobilePriceLogService;
 use think\Cache;
 use think\db\Query;
 use think\helper\Str;
@@ -110,6 +111,13 @@ class Mobile extends Model
             $mobile['city']=Area::where('id',$mobile['city_id'])->value('shortname');
         }
     }
+    public function makePriceLog(){
+        (new MobilePriceLogService)
+            ->setMobile($this)
+            ->setBeforePrice($this->origin['amount'])
+            ->setAfterPrice($this['amount'])
+            ->log();
+    }
     public function makeRules(){
         $mobile=$this;
         foreach (MobileComputer::setMobile($mobile['no'])->filter() as $key=>$value){
@@ -156,6 +164,7 @@ class Mobile extends Model
                 $mobile->makeAmount();
             }
             $mobile->makeArea();
+            $mobile->makePriceLog();
         });
         self::beforeInsert(function (self $mobile){
             $mobile['sort']=mt_rand(0,99999999);

+ 4 - 0
application/common/service/MobilePriceLogService.php

@@ -56,6 +56,10 @@ class MobilePriceLogService{
     }
 
     public function log(){
+        if(empty($_SERVER['admin'])){
+            return;
+        }
+        $this->setAdminId($_SERVER['admin']['id']);
         if($this->before_price!=$this->after_price){
             MobilePriceLog::create([
                 'admin_id'=>$this->admin_id,

+ 3 - 3
application/sub/controller/Mobile.php

@@ -31,15 +31,15 @@ class Mobile extends SubCommon
             $this->validate($data,[
                 'amount_base'=>['require','number','gt:0'],
             ]);
-            $s=(new MobilePriceLogService())
+            /*$s=(new MobilePriceLogService())
                 ->setMobile($mobile)
                 ->setAfterPrice($data['amount_base'])
                 ->setBeforePrice($mobile['amount_base'])
-                ->setUserId($this->auth->id);
+                ->setUserId($this->auth->id);*/
             foreach ($this->request->only('amount_base') as $key=>$value){
                 $mobile[$key]=$value;
             }
-            $s->log();
+            //$s->log();
             $mobile->save();
             $this->success();
         }