byzhenyu před 1 rokem
rodič
revize
2f828839f0

+ 28 - 5
application/approve/controller/ApproveMaintainUser.php

@@ -17,6 +17,7 @@ namespace app\approve\controller;
 
 use app\common\constant\CommonConstant;
 use app\common\constant\MaintainConstant;
+use app\common\model\ApproveMaintainUser as model;
 use library\Controller;
 
 /**
@@ -49,12 +50,24 @@ class ApproveMaintainUser extends Controller
      */
     public function index()
     {
+        $name = input('name');
+        $mobile = input('mobile');
+
         $this->title = '维修人员列表';
-        $query = $this->_query($this->table)
-            ->field('is_deleted', true)
+        $data = model::field('is_deleted', true)
             ->where('is_deleted', CommonConstant::IS_DELETED_0)
-            ->like('name,mobile');
-        $query->page();
+            ->when($name, function ($query) use ($name) {
+                $query->where('name', 'like', '%' . $name . '%');
+            })
+            ->when($mobile, function ($query) use ($mobile) {
+                $query->where('mobile', 'like', '%' . $mobile . '%');
+            })
+            ->with([
+                'log' => function ($query) {
+                    $query->field('comment,create_at', true);
+                }
+            ]);
+        self::_init($data);
     }
 
     /**
@@ -65,7 +78,17 @@ class ApproveMaintainUser extends Controller
     protected function _index_page_filter(&$data)
     {
         foreach ($data as &$value) {
-
+            $comment_count = !empty($value['log']) ? count($value['log']) : 0;
+            $comment_score = 0;
+            if (!empty($value['log'])) {
+                foreach ($value['log'] as $k => $v) {
+                    $comment_score = bcadd($comment_score, $v['comment_score']);
+                }
+            }
+            $log_score = $comment_score > 0 ? bcdiv($comment_score, $comment_count, 1) : 0;
+            $value['comment_count'] = $comment_count;
+            $value['comment_score'] = $comment_score;
+            $value['log_score'] = $log_score;
         }
     }
 

+ 59 - 0
application/approve/controller/ApproveMaintainUserLog.php

@@ -0,0 +1,59 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | ThinkAdmin
+// +----------------------------------------------------------------------
+// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// +----------------------------------------------------------------------
+// | 官方网站: http://demo.thinkadmin.top
+// +----------------------------------------------------------------------
+// | 开源协议 ( https://mit-license.org )
+// +----------------------------------------------------------------------
+// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
+// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
+// +----------------------------------------------------------------------
+
+namespace app\approve\controller;
+
+use app\common\model\ApproveMaintainUserLog as model;
+use library\Controller;
+
+/**
+ * 评价记录
+ */
+class ApproveMaintainUserLog extends Controller
+{
+    /**
+     * 绑定数据表
+     * @var string
+     */
+    protected $table = 'ApproveMaintainUserLog';
+
+    /**
+     * 控制器初始化
+     */
+    protected function initialize()
+    {
+
+    }
+
+    /**
+     * 列表
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function index()
+    {
+        $this->user_id = $user_id = input('user_id') ?: 0;
+        $this->title = '评价记录';
+
+        $data = model::where('user_id', $user_id)
+            ->order('id desc');
+        self::_init($data);
+    }
+
+}

+ 6 - 0
application/approve/view/approve_maintain_user/index.html

@@ -26,6 +26,8 @@
             <th class='text-left nowrap'>姓名</th>
             <th class='text-left nowrap'>手机号码</th>
             <th class='text-left nowrap'>生日</th>
+            <th class='text-left nowrap'>评价数量</th>
+            <th class='text-left nowrap'>综合评分</th>
             <th class="text-left nowrap">操作</th>
         </tr>
         </thead>
@@ -40,7 +42,11 @@
             <td class='text-left nowrap'>{$vo.name|default=''}</td>
             <td class='text-left nowrap'>{$vo.mobile|default='--'}</td>
             <td class='text-left nowrap'>{$vo.birthday|default='--'}</td>
+            <td class='text-left nowrap color-red'><strong>{$vo.comment_count|default='--'}</strong></td>
+            <td class='text-left nowrap color-red'><strong>{$vo.log_score|default='--'}</strong></td>
             <td class='text-left nowrap'>
+                <a class="layui-btn layui-btn-xs layui-bg-blue"
+                   data-open="{:url('approve_maintain_user_log/index')}?user_id={$vo.id}">评价记录</a>
 
                 {if auth("edit")}
                 <a class="layui-btn layui-btn-xs" data-modal="{:url('edit')}?id={$vo.id}">编 辑</a>

+ 40 - 0
application/approve/view/approve_maintain_user_log/index.html

@@ -0,0 +1,40 @@
+{extend name='admin@main'}
+
+{block name="button"}
+
+<button class="layui-btn layui-btn-sm layui-btn-primary" type='button' data-open="{:url('approve_maintain_user/index')}">返回</button>
+
+{/block}
+
+{block name="content"}
+<div class="think-box-shadow">
+    {include file='approve_maintain_user_log/index_search'}
+    <table class="layui-table margin-top-10" lay-skin="line">
+        {notempty name='list'}
+        <thead>
+        <tr>
+            <th class='text-left nowrap'>评分</th>
+            <th class='text-left nowrap'>评价内容</th>
+            <th class='text-left nowrap'>创建时间</th>
+        </tr>
+        </thead>
+        {/notempty}
+        <tbody>
+        {foreach $list as $key=>$vo}
+        <tr>
+            <td class='text-left nowrap'>
+                {$vo.comment_score|default='--'}
+            </td>
+            <td class='text-left nowrap'>
+                {$vo.comment|default='--'}
+            </td>
+            <td class='text-left nowrap'>
+                {$vo.create_at|default='--'}
+            </td>
+        </tr>
+        {/foreach}
+        </tbody>
+    </table>
+    {empty name='list'}<span class="notdata">没 有 记 录 哦!</span>{else}{$pagehtml|raw|default=''}{/empty}
+</div>
+{/block}

+ 0 - 0
application/approve/view/approve_maintain_user_log/index_search.html


+ 7 - 0
application/common/model/ApproveMaintainUser.php

@@ -17,4 +17,11 @@ class ApproveMaintainUser extends Model
 
     ];
 
+
+    // 关联评价记录 (后台)
+    public function log()
+    {
+        return $this->hasMany(ApproveMaintainUserLog::class, 'user_id', 'id');
+    }
+
 }

+ 3 - 3
application/common/model/GoodsUseLog.php → application/common/model/ApproveMaintainUserLog.php

@@ -5,12 +5,12 @@ namespace app\common\model;
 use think\Model;
 
 /**
- * 商品出库记录模型
+ * 维修人员-评价记录模型
  */
-class GoodsUseLog extends Model
+class ApproveMaintainUserLog extends Model
 {
     // 表名
-    protected $name = 'goods_use_log';
+    protected $name = 'approve_maintain_user_log';
 
     // 追加属性
     protected $append = [

+ 15 - 4
application/common/service/ApproveInfoService.php

@@ -8,6 +8,7 @@ use app\common\model\Approve;
 use app\common\model\ApproveCopy;
 use app\common\model\ApproveApplyGoods;
 use app\common\model\ApproveMaintain;
+use app\common\model\ApproveMaintainUserLog;
 use app\common\model\ApproveStockGoods;
 use app\common\model\ApproveEvectionPeerUser;
 use app\common\model\ApproveInfo;
@@ -1163,7 +1164,7 @@ class ApproveInfoService
     public static function make($id, $params, $user, $type)
     {
         $userid = $user['userid'];
-        $info = ApproveInfo::field('id,user_id,module,status,reason')
+        $info = ApproveInfo::field('id,module,user_id,status,reason,maintain_user_id')
             ->where('is_deleted', CommonConstant::IS_DELETED_0)
             ->find($id);
         if (!$info) {
@@ -1205,11 +1206,21 @@ class ApproveInfoService
                 }
                 // TODO 没有判断评价状态
 
-                // 更新维修信息
-                $params['comment_status'] = CommonConstant::IS_WHO_1;
+                Db::startTrans();
                 try {
-                    ApproveMaintain::where('info_id', $info->id)->update($params);
+                    // 添加评价记录
+                    $data = $params;
+                    $data['info_id'] = $id;
+                    $data['user_id'] = $info->maintain_user_id;
+                    ApproveMaintainUserLog::create($data);
+
+                    // 更新维修信息
+                    $params['comment_status'] = CommonConstant::IS_WHO_1;
+                    ApproveMaintain::where('info_id', $id)->update($params);
+
+                    Db::commit();
                 } catch (Exception $e) {
+                    Db::rollback();
                     except('出现错误:' . $e->getMessage());
                 }
                 break;

+ 1 - 1
vendor/zoujingli/think-library/src/Controller.php

@@ -352,7 +352,7 @@ abstract class Controller extends \stdClass
         } else {
             $result = ['list' => $data->select()];
         }
-        if ($this->display) {
+        if (false !== $this->callback('_page_filter', $result['list']) && $this->display) {
             return $this->fetch('', $result);
         } else {
             return $result;