xxxrrrdddd 3 years ago
parent
commit
2b52027c4c

+ 4 - 1
application/admin/model/Admin.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\model;
 
+use app\common\model\MobileHoldLog;
 use think\Model;
 use think\Session;
 
@@ -30,5 +31,7 @@ class Admin extends Model
     {
         return $encrypt($password . $salt);
     }
-
+    public function mobileHoldLog(){
+        return $this->morphMany(MobileHoldLog::class,'holdable','admin');
+    }
 }

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

@@ -42,6 +42,9 @@ class Mobile extends Model
     public function proxy(){
         return $this->belongsTo(Admin::class,'proxy_id');
     }
+    public function holdLog(){
+        return $this->hasMany(MobileHoldLog::class);
+    }
     const BEAUTI=1;
     const FLOW=2;
 

+ 41 - 0
application/common/model/MobileHoldLog.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace app\common\model;
+
+use app\admin\model\Admin;
+use think\Model;
+use Yansongda\Supports\Str;
+
+/**
+ * 配置模型
+ */
+class MobileHoldLog extends Model
+{
+    protected $autoWriteTimestamp=true;
+    protected $updateTime=null;
+
+    public function holdable(){
+        return $this->morphTo('holdable',[
+            'admin'=>Admin::class,
+            'user' =>User::class,
+        ]);
+    }
+    public function mobile(){
+        return $this->belongsTo(Mobile::class,'mobile_id','id')->setEagerlyType(0);
+    }
+
+    public static function withHoldUser(User $user,$is_hold){
+        return new self([
+            'holdable_type'=>'user',
+            'holdable_id'=>$user['id'],
+            'is_hold'=>$is_hold,
+        ]);
+    }
+    public static function withHoldAdmin(Admin $user,$is_hold){
+        return new self([
+            'holdable_type'=>'admin',
+            'holdable_id'=>$user['id'],
+            'is_hold'=>$is_hold,
+        ]);
+    }
+}

+ 3 - 0
application/common/model/User.php

@@ -268,6 +268,9 @@ class User extends Model
     public function verification(){
         return $this->hasOne(UserVerification::class);
     }
+    public function mobileHoldLog(){
+        return $this->morphMany(MobileHoldLog::class,'holdable','user');
+    }
     /** 模糊搜索 */
     public function scopeDim(Query $query,$keyword){
         $keyword="%{$keyword}%";

+ 1 - 0
application/sub/config.php

@@ -8,4 +8,5 @@ return [
         'var_page'  => 'page',
         'list_rows' => 15,
     ],
+    'exception_handle'        => '\\app\\sub\\library\\ExceptionHandle',
 ];

+ 18 - 0
application/sub/controller/Mobile.php

@@ -3,6 +3,8 @@
 namespace app\sub\controller;
 
 use app\common\model\Mobile as M;
+use app\common\model\MobileHoldLog;
+use think\Db;
 
 /**
  * 会员中心
@@ -32,4 +34,20 @@ class Mobile extends SubCommon
             $this->success();
         }
     }
+    #修改预占
+    public function hold(){
+        $data=input();
+        $user=$this->auth->getUser();
+        $this->validate($data,[
+            'id'=>['require','integer'],
+            'is_hold'=>['require','in:0,1'],
+        ]);
+        $mobile=M::where('s_id',$this->auth->id)->findOrFail($data['id']);
+        Db::startTrans();
+        $mobile['is_hold']=$data['is_hold'];
+        $mobile->save();
+        $mobile->holdLog()->save(MobileHoldLog::withHoldUser($user,$data['is_hold']));
+        Db::commit();
+        $this->success();
+    }
 }

+ 55 - 0
application/sub/library/ExceptionHandle.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace app\sub\library;
+
+use app\UserException;
+use Exception;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\ModelNotFoundException;
+use think\exception\Handle;
+
+/**
+ * 自定义API模块的错误显示
+ */
+class ExceptionHandle extends Handle
+{
+
+    protected $ignoreReport = [
+        '\\think\\exception\\HttpException',
+        UserException::class,
+    ];
+    public function render(Exception $e)
+    {
+        // 在生产环境下返回code信息
+        //if (!\think\Config::get('app_debug')) {
+        if(request()->isAjax() || strpos(request()->header('Accept'),'/json')!==false) {
+            $statuscode = $code = 0;
+            //$msg = 'An error occurred';
+            $msg = $e->getMessage();
+            // 验证异常
+            if ($e instanceof \think\exception\ValidateException) {
+                $code = 0;
+                $statuscode = 200;
+                $msg = $e->getError();
+            }
+            // Http异常
+            if ($e instanceof \think\exception\HttpException) {
+                $statuscode = $code = $e->getStatusCode();
+            }
+            if ($e instanceof UserException) {
+                $code = 0;
+                $msg = $e->getMessage();
+                $statuscode = 200;
+            }
+            if ($e instanceof ModelNotFoundException) {
+                $msg = '查找的数据不存在';
+            }
+            return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
+        }
+        //}
+
+        //其它此交由系统处理
+        return parent::render($e);
+    }
+
+}

+ 20 - 13
application/sub/view/order/mobile.html

@@ -39,7 +39,7 @@
         <tbody class="news_content">
         {foreach name="list" item="a"}
         <tr>
-            <th><input type="checkbox" lay-skin="primary" lay-filter="allChoose" id="id-{$a.id}"></th>
+            <th><input type="checkbox" lay-skin="primary" class="choose" lay-filter="choose" value="{$a.id}"></th>
             <td>{$a.id}</td>
             <td>{$a.no}</td>
             <td>{$a.network}</td>
@@ -49,7 +49,7 @@
             <td>{$a.amount_di}</td>
             <td>{$a.amount_charge}</td>
             <td>
-                <input type="checkbox" value="1" name="is_hold" class="hold-change" lay-filter="holdChange" lay-skin="switch" lay-text="开启|关闭" {$a.is_hold?'checked':''}>
+                <input type="checkbox" value="{$a.id}" name="is_hold" class="hold-change" lay-filter="holdChange" lay-skin="switch" lay-text="开启|关闭" {$a.is_hold?'checked':''}>
             </td>
             <td>
                 <a class="layui-btn layui-btn-mini news_edit" data-id="{$a.id}"><i class="iconfont icon-edit"></i> 编辑</a>
@@ -104,8 +104,8 @@
 
         //批量删除
         $(".batchDel").click(function(){
-            var $checkbox = $('.news_list tbody input[type="checkbox"][name="checked"]');
-            var $checked = $('.news_list tbody input[type="checkbox"][name="checked"]:checked');
+            var $checkbox = $('.news_list tbody .choose');
+            var $checked = $('.news_list tbody .choose:checked');
             if($checkbox.is(":checked")){
                 layer.confirm('确定删除选中的信息?',{icon:3, title:'提示信息'},function(index){
                     var index = layer.msg('删除中,请稍候',{icon: 16,time:false,shade:0.8});
@@ -132,7 +132,7 @@
 
         //全选
         form.on('checkbox(allChoose)', function(data){
-            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
+            var child = $(data.elem).parents('table').find('tbody .choose');
             child.each(function(index, item){
                 item.checked = data.elem.checked;
             });
@@ -141,8 +141,8 @@
 
         //通过判断文章是否全部选中来确定全选按钮是否选中
         form.on("checkbox(choose)",function(data){
-            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
-            var childChecked = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"]):checked')
+            var child = $(data.elem).parents('table').find('tbody input.choose');
+            var childChecked = $(data.elem).parents('table').find('tbody input.choose:checked')
             if(childChecked.length == child.length){
                 $(data.elem).parents('table').find('thead input#allChoose').get(0).checked = true;
             }else{
@@ -153,12 +153,19 @@
 
         //是否展示
         form.on('switch(holdChange)', function(data){
-            console.log(data.elem.checked)
-            var index = layer.msg('修改中,请稍候',{icon: 16,time:false,shade:0.8});
-            setTimeout(function(){
-                layer.close(index);
-                layer.msg("展示状态修改成功!");
-            },200);
+            let open=data.elem.checked,
+                _this=this
+            var index = layer.msg('修改中,请稍候',{icon: 16,time:5000,shade:0.1});
+            $.post('{:url("mobile/hold")}',{is_hold:open?1:0,id:_this.value},function (res) {
+                if(res.code===0){
+                    layer.alert(res.msg)
+                    _this.checked=!open
+                    form.render('checkbox')
+                }else{
+                    layer.close(index)
+                    layer.msg('修改成功')
+                }
+            })
         })
 
         //操作