Sfoglia il codice sorgente

修改bug,提交代码

Xiahai 6 mesi fa
parent
commit
a1a399cd56

+ 31 - 25
addons/qingdongams/controller/WebAftermarket.php

@@ -20,6 +20,7 @@ class WebAftermarket extends WebIndexApi
      * @var \addons\qingdongams\model\Aftermarket
      */
     protected $model;
+
     public function __construct()
     {
         parent::__construct();
@@ -28,12 +29,13 @@ class WebAftermarket extends WebIndexApi
     }
 
     // 获取分类
-    public function typeList(){
-        $pid = input('pid',0);
+    public function typeList()
+    {
+        $pid = input('pid', 0);
         $where['pid'] = $pid;
         $model = new AftermarketType();
         $list = collection($model->order('id desc')->where($where)->field('id,name,pid')->select())->toArray();
-        $this->success('',$list);
+        $this->success('', $list);
     }
 
     //文章列表
@@ -42,27 +44,28 @@ class WebAftermarket extends WebIndexApi
         $limit = input("limit/d", 10);
         $params = $this->request->post();
         $where = [];
-        if(isset($params['type_ids']) && $params['type_ids']){
-            $where['type_ids'] = ['like','%,'.$params['type_ids'].',%'];
+        if (isset($params['type_ids']) && $params['type_ids']) {
+            $where['type_ids'] = ['like', '%,' . $params['type_ids'] . ',%'];
         }
-        if(isset($params['name']) && $params['name']){
-            $where['title'] = ['like','%'.$params['name'].'%'];
+        if (isset($params['name']) && $params['name']) {
+            $where['title'] = ['like', '%' . $params['name'] . '%'];
         }
         $comments = $this->model->where($where)->paginate($limit);
         $this->success('请求成功', $comments);
     }
 
-    public function detailArt(){
+    public function detailArt()
+    {
         $id = input('id');
-        if(!$id){
+        if (!$id) {
             $this->error('文章id呢?');
         }
         $id = input("id");
-        if(!isset($id) || !$id){
+        if (!isset($id) || !$id) {
             $this->error('参数缺失');
         }
         // 文章详情
-        $detail = AftermarketModel::where('id',$id)->field('id,create_staff_id,product_ids,type_ids,title,content,img,desc,method,click_number,comment_num,createtime')->find();
+        $detail = AftermarketModel::where('id', $id)->field('id,create_staff_id,product_ids,type_ids,title,content,img,desc,method,click_number,comment_num,createtime')->find();
         // 详情
         $comments = Comment::where([
             'relation_type' => 'article',
@@ -77,37 +80,40 @@ class WebAftermarket extends WebIndexApi
      * 文章浏览次数
      * @throws \think\Exception
      */
-    public function viewArticle(){
+    public function viewArticle()
+    {
         $id = input('id');
-        if(!$id){
+        if (!$id) {
             $this->error('文章id呢?');
         }
         $articleModel = new AftermarketModel();
         $row = $articleModel->get($id);
-        if(!$row){
+        if (!$row) {
             $this->error('文章不存在');
         }
-        if($articleModel->where(['id'=>$id])->setInc('click_number')){
+        if ($articleModel->where(['id' => $id])->setInc('click_number')) {
             $this->success('成功');
-        }else{
+        } else {
             $this->error('失败');
         }
     }
+
     //客户端配置
-    public function user_config(){
-        $data = AdminConfig::where(array('type'=>'user'))->column('field,value');
+    public function user_config()
+    {
+        $data = AdminConfig::where(array('type' => 'user'))->column('field,value');
         $data['user_name'] = $data['user_name'];
-        if(!empty($this->personInfo['customer_id'])){
-            $info=Customer::where(array('id'=>$this->personInfo['customer_id']))->find();
-            $data['user_name'] = isset($info['name'])? $info['name']:$data['user_name'];
+        if (!empty($this->personInfo['customer_id'])) {
+            $info = Customer::where(array('id' => $this->personInfo['customer_id']))->find();
+            $data['user_name'] = isset($info['name']) ? $info['name'] : $data['user_name'];
         }
 
-        $data['user_phone'] = $data['user_phone']??'';
+        $data['user_phone'] = $data['user_phone'] ?? '';
         $data['user_email'] = $data['user_email'] ?? '';
-        $data['user_logo'] = isset($data['user_logo'])? cdnurl($data['user_logo'],true) : '';
+        $data['user_logo'] = isset($data['user_logo']) ? cdnurl($data['user_logo'], true) : '';
         $data['user_address'] = $data['user_address'] ?? '';
         $data['user_lat'] = $data['user_lat'] ?? '';
-        $data['user_lag'] = $data['user_lag'] ??'';
-        $this->success('',$data);
+        $data['user_lag'] = $data['user_lag'] ?? '';
+        $this->success('', $data);
     }
 }

+ 4 - 1
addons/qingdongams/model/Staff.php

@@ -359,7 +359,10 @@ class Staff extends Model
                 || isset($changed['email']) || isset($changed['img'])) {
                 $params = [];
                 if (isset($changed['mobile'])) {
-                    $params['username'] = $changed['mobile'];
+                    $params['mobile'] = $changed['mobile'];
+                }
+                if (isset($changed['username'])) {
+                    $params['username']= $changed['username'];
                 }
                 if (isset($changed['name'])) {
                     $params['nickname'] = $changed['name'];

+ 171 - 148
addons/qingdongams/model/Workorder.php

@@ -2,6 +2,7 @@
 
 namespace addons\qingdongams\model;
 
+use app\admin\model\Admin;
 use think\Db;
 use think\Exception;
 use think\Model;
@@ -14,7 +15,7 @@ class Workorder extends Model
 {
     use SoftDelete;
 
-    protected $name  = 'qingdongams_workorder';
+    protected $name = 'qingdongams_workorder';
     // 开启自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名
@@ -49,28 +50,28 @@ class Workorder extends Model
         if (empty($value)) {
             return [];
         }
-        $value=json_decode($value, true);
-        if(empty($value)){
+        $value = json_decode($value, true);
+        if (empty($value)) {
             return [];
         }
-        foreach ($value as $k=>$v){
-          if(empty($v['content'])){
+        foreach ($value as $k => $v) {
+            if (empty($v['content'])) {
 //                continue;
             }
-            foreach ($v['content'] as $kc=>$vc){
-                if(empty($vc['autograph_url'])){
+            foreach ($v['content'] as $kc => $vc) {
+                if (empty($vc['autograph_url'])) {
                     continue;
                 }
-                $autograph_url=explode(',',$vc['autograph_url']);
-                $autograph=[];
-                foreach ($autograph_url as $url){
-                    $autograph[]=  ['id'=>$vc['autograph_url'],'url'=>cdnurl(File::getUrl($url),true)];
+                $autograph_url = explode(',', $vc['autograph_url']);
+                $autograph = [];
+                foreach ($autograph_url as $url) {
+                    $autograph[] = ['id' => $vc['autograph_url'], 'url' => cdnurl(File::getUrl($url), true)];
                 }
-                $vc['autograph']=$autograph;
+                $vc['autograph'] = $autograph;
 
-                $v['content'][$kc]=$vc;
+                $v['content'][$kc] = $vc;
             }
-            $value[$k]=$v;
+            $value[$k] = $v;
         }
         return $value;
     }
@@ -118,15 +119,15 @@ class Workorder extends Model
         $data = [];
         foreach ($value as $v) {
             $cp = CustomerProduct::where(['id' => ['in', $v['customer_product_id']]])->with(['product'])->find();
-            if(empty($cp)){
+            if (empty($cp)) {
                 continue;
             }
-            $parts_id = explode(',', $v['parts_id']??'');
-            if($cp['product_id']){
+            $parts_id = explode(',', $v['parts_id'] ?? '');
+            if ($cp['product_id']) {
                 $parts = Parts::where('', 'exp', Db::raw('FIND_IN_SET(' . $cp['product_id'] . ',product_id)'))->select();
                 $parts = collection($parts)->toArray();
-            }else{
-                $parts=[];
+            } else {
+                $parts = [];
             }
 
             foreach ($parts as $k => $p) {
@@ -210,10 +211,11 @@ class Workorder extends Model
 
         return $result;
     }
+
     //回执附件 receipt_file_ids
     public function getReceiptFileIdsAttr($value)
     {
-        if(empty($value)){
+        if (empty($value)) {
             return $value;
         }
         $files = explode(',', $value);
@@ -238,7 +240,7 @@ class Workorder extends Model
         }
         $data = [];
         foreach ($value as $v) {
-            if(!isset($v['product_id'])){
+            if (!isset($v['product_id'])) {
                 continue;
             }
             $p = Product::where(['id' => $v['product_id']])->field('id,name,num,img,type_id')->find();
@@ -270,7 +272,7 @@ class Workorder extends Model
     //获取评价附件
     public function getAutographUrlAttr($value)
     {
-        if(empty($value)){
+        if (empty($value)) {
             return '';
         }
         return cdnurl(File::getUrl($value), true);
@@ -370,14 +372,14 @@ class Workorder extends Model
                 unset($params[$name]);
                 continue;
             }
-            if(empty($params[$name])){
+            if (empty($params[$name])) {
                 unset($params[$name]);
                 continue;
             }
         }
         $staff = Staff::info();
 
-        $params['dep_id']=$params['owner_dep_id'];
+        $params['dep_id'] = $params['owner_dep_id'];
         if (!empty($staff)) {
             $params['create_staff_id'] = $staff->id;
         }
@@ -402,7 +404,7 @@ class Workorder extends Model
         if (isset($params['product']) && $params['product']) {
             //添加产品
             $product = $params['product'];
-            if (is_array($product)){
+            if (is_array($product)) {
                 $params['product'] = json_encode($product);
             }
             if ($params['workorder_type'] == '产品发货') {
@@ -429,9 +431,13 @@ class Workorder extends Model
 
         }
         $params['product_part'] = $params['product_part'] ?? [];
-        if(is_array($params['product_part'])){
+        if (is_array($params['product_part'])) {
             $params['product_part'] = json_encode($params['product_part'] ?? []);
         }
+
+        // 添加可查看员工id
+        $params['show_staff_id'] = $params['owner_staff_id'] ?? '';
+
         $workorderM = new self;
         // 调用当前模型对应的User验证器类进行数据验证
         $result = $workorderM->allowField(true)->save($params);
@@ -442,7 +448,6 @@ class Workorder extends Model
         }
 
 
-
         $otherModel = new WorkorderOther();
         if ($otherModel->save(['id' => $lastId, 'other' => json_encode($other, JSON_UNESCAPED_UNICODE)]) === false) {
             // 验证失败 输出错误信息
@@ -453,28 +458,27 @@ class Workorder extends Model
         }
 
 
-
         //创建下次执行的巡检时间
-        if(isset($params['check_up']) && $params['check_up']==1){
-            $time_data['check_up']=$params['check_up'];
-            $time_data['time_up']=$params['time_up'];
+        if (isset($params['check_up']) && $params['check_up'] == 1) {
+            $time_data['check_up'] = $params['check_up'];
+            $time_data['time_up'] = $params['time_up'];
             // $time_data['m']=$params['m'];
             // $time_data['d']=$params['d'];
             // $time_data['h']=$params['h'];
             // $time_data['i']=$params['i'];
             // $time_data['week']=$params['week'];
             // $w_time=WorkorderInspection::getTime($time_data);
-            $w_time=strtotime($params['jh_start_time']);
-            $n_time=WorkorderInspection::getNextTime($w_time,$time_data);
-            $WorkorderInspection=new WorkorderInspection();
-            if ( $WorkorderInspection->save([
-                'type'=>$params['time_up'],
-                'work_id'=>$lastId,
-                'executetime'=>$w_time,
-                'next_executetime'=>$n_time,
-                'createtime'=>time(),
-                'updatetime'=>time()
-            ])  === false){
+            $w_time = strtotime($params['jh_start_time']);
+            $n_time = WorkorderInspection::getNextTime($w_time, $time_data);
+            $WorkorderInspection = new WorkorderInspection();
+            if ($WorkorderInspection->save([
+                    'type' => $params['time_up'],
+                    'work_id' => $lastId,
+                    'executetime' => $w_time,
+                    'next_executetime' => $n_time,
+                    'createtime' => time(),
+                    'updatetime' => time()
+                ]) === false) {
                 throw new Exception($WorkorderInspection->getError());
             }
         }
@@ -486,7 +490,7 @@ class Workorder extends Model
         $paramsSign['files'] = $files ?? '';
         $paramsSign['relation_process'] = '创建工单';
         //创建跟进记录
-        if(isset($params['customer_id']) && $params['customer_id']){
+        if (isset($params['customer_id']) && $params['customer_id']) {
             StaffSignIn::quickSignIn($params['customer_id'], $content, $paramsSign);
         }
 
@@ -494,42 +498,43 @@ class Workorder extends Model
     }
 
 
-    public static function inspection(){
+    public static function inspection()
+    {
         // //查询所以的巡检计划
         $workorderM = new self;
-        $WorkorderInspection=new WorkorderInspection();
-        $w_time=time()+3600*24*config('site.order_tq_time');
-        $list=WorkorderInspection::where(array('status'=>0))->field("id,type,work_id,executetime,next_executetime,status")->select();
-        foreach($list as $key=>$val){
+        $WorkorderInspection = new WorkorderInspection();
+        $w_time = time() + 3600 * 24 * config('site.order_tq_time');
+        $list = WorkorderInspection::where(array('status' => 0))->field("id,type,work_id,executetime,next_executetime,status")->select();
+        foreach ($list as $key => $val) {
             //判断当前时间是否可以创建巡检订单
-            if($w_time>$val['executetime']){
+            if ($w_time > $val['executetime']) {
                 //执行创建新的巡检工单
-                $info=$workorderM->where(array('id'=>$val['work_id']))->find()->toArray();
+                $info = $workorderM->where(array('id' => $val['work_id']))->find()->toArray();
                 unset($info['id']);
                 unset($info['show_staff_data']);
-                $info['title']=$info['title']."[巡检计划]";
-                $info['createtime']=time();
-                $info['start_time']=$w_time;
-                $info['end_time']=config('site.xjjh_time')*3600+time();
-                $status=$workorderM->save($info);
-                if($status){
+                $info['title'] = $info['title'] . "[巡检计划]";
+                $info['createtime'] = time();
+                $info['start_time'] = $w_time;
+                $info['end_time'] = config('site.xjjh_time') * 3600 + time();
+                $status = $workorderM->save($info);
+                if ($status) {
                     //更新执行状态创建下一次执行
-                    if($WorkorderInspection->where(array('id'=>$val['id']))->update(['status'=>1]) && $val['next_executetime']){
-                        $time_data['check_up']=$info['check_up'];
-                        $time_data['time_up']=$info['time_up'];
+                    if ($WorkorderInspection->where(array('id' => $val['id']))->update(['status' => 1]) && $val['next_executetime']) {
+                        $time_data['check_up'] = $info['check_up'];
+                        $time_data['time_up'] = $info['time_up'];
                         // $time_data['m']=$info['m'];
                         // $time_data['d']=$info['d'];
                         // $time_data['h']=$info['h'];
                         // $time_data['i']=$info['i'];
                         // $time_data['week']=$info['week'];
-                        $n_time=WorkorderInspection::getNextTime($val['next_executetime'],$time_data);
+                        $n_time = WorkorderInspection::getNextTime($val['next_executetime'], $time_data);
                         $WorkorderInspection->save([
-                            'type'=>$info['time_up'],
-                            'work_id'=>$val['work_id'],
-                            'executetime'=>$val['next_executetime'],
-                            'next_executetime'=>$n_time,
-                            'createtime'=>time(),
-                            'updatetime'=>time()
+                            'type' => $info['time_up'],
+                            'work_id' => $val['work_id'],
+                            'executetime' => $val['next_executetime'],
+                            'next_executetime' => $n_time,
+                            'createtime' => time(),
+                            'updatetime' => time()
                         ]);
                     }
 
@@ -538,61 +543,76 @@ class Workorder extends Model
         }
     }
 
-    public static function wanderorder(){
-         //指定员工
-         $where['status']=1; //没有处理
-         $workorderM = new self;
-         $infoList=$workorderM->where($where)->order("id desc")->field("id,owner_staff_id,is_notice,create_staff_id,workorder_number,title,createtime,workorder_type,dep_id,updatetime")->select();
-         $time=time();
-
-         $allout_time=0;
-         $all_num=0;
-         foreach($infoList as $info){
-            $yglist =Staff::getYkList($info['dep_id']);
-            $all_num=count($yglist);
-            $cs_time=$info['updatetime']+ config('site.csorder')*60;
-            $allout_time=strtotime($info['createtime'])+ config('site.csorder')*60*$all_num;
-            
-             if($time>$allout_time && $info['is_notice']==0){
-                 //查询部门总人数  ,人数乘以每单的超时时间得出总的超时时间,如果总的超时时间过点,仍然没有进行派单处理。则通知管理员
-                     $noticeParams = [
-                        'event' => 'timeout_order',
-                        'params' => array (
+    public static function wanderorder()
+    {
+        //指定员工
+        $where['status'] = 1; //没有处理
+        $workorderM = new self;
+        $infoList = $workorderM->where($where)->order("id desc")->field("id,owner_staff_id,is_notice,create_staff_id,workorder_number,title,createtime,workorder_type,dep_id,updatetime")->select();
+        $time = time();
+
+        $allout_time = 0;
+        $all_num = 0;
+        foreach ($infoList as $info) {
+            $yglist = Staff::getYkList($info['dep_id']);
+            $all_num = count($yglist);
+            $cs_time = $info['updatetime'] + config('site.csorder') * 60;
+            $allout_time = strtotime($info['createtime']) + config('site.csorder') * 60 * $all_num;
+
+            if ($time > $allout_time && $info['is_notice'] == 0) {
+                //查询部门总人数  ,人数乘以每单的超时时间得出总的超时时间,如果总的超时时间过点,仍然没有进行派单处理。则通知管理员
+                $noticeParams = [
+                    'event' => 'timeout_order',
+                    'params' => array(
                         'receiver_admin_ids' => '',
                         'receiver_admin_group_ids' => '6',
-                        'order_id' =>$info['id'],
+                        'order_id' => $info['id'],
                         'orderno' => $info['workorder_number'],
                         'title' => $info['title'],
                         'type' => $info['workorder_type'],
-                   )];
-                
-                 \Think\Hook::listen('send_notice',$noticeParams); 
-                 self::where(['id' => $info['id']])->update(['is_notice'=>1]) ;
-                }
-            if($time>$cs_time){
+                    )];
+
+                \Think\Hook::listen('send_notice', $noticeParams);
+                self::where(['id' => $info['id']])->update(['is_notice' => 1]);
+            }
+            if ($time > $cs_time) {
                 //更换员工
-                foreach($yglist as $key=>$val){
-                    if($val['id']==$info['owner_staff_id']){
+                foreach ($yglist as $key => $val) {
+                    if ($val['id'] == $info['owner_staff_id']) {
                         //分配下一个员工
-                        if(isset($yglist[$key+1]['id'])){
-                            $owner_staff_id=$yglist[$key+1]['id'];
-                        }else{
-                            $owner_staff_id=$yglist[0]['id'];
+                        if (isset($yglist[$key + 1]['id'])) {
+                            $owner_staff_id = $yglist[$key + 1]['id'];
+                        } else {
+                            $owner_staff_id = $yglist[0]['id'];
                         }
                     }
                 }
-                $update['owner_staff_id']=$owner_staff_id;
-                $update['updatetime']=time();
-                self::where(['id' => $info['id']])->update($update) ;
+
+                // 查找对应员工的admin账号id,发送对应消息
+                $staff = Staff::where(['id' => $owner_staff_id])->find();
+                $noticeParams = [
+                    'event' => 'timeout_order',
+                    'params' => array(
+                        'receiver_admin_ids' => '',
+                        'receiver_admin_group_ids' => $staff->admin_id,
+                        'order_id' => $info['id'],
+                        'orderno' => $info['workorder_number'],
+                        'title' => $info['title'],
+                        'type' => $info['workorder_type'],
+                    )];
+                \Think\Hook::listen('send_notice', $noticeParams);
+
+                $update['owner_staff_id'] = $owner_staff_id;
+                $update['updatetime'] = time();
+                self::where(['id' => $info['id']])->update($update);
                 echo "ok";
-            }else{
+            } else {
                 echo "no time order";
             }
 
         }
 
 
-
     }
 
     //创建工单
@@ -624,19 +644,19 @@ class Workorder extends Model
         }
         $params['parts'] = json_encode($parts);
         $params['status'] = 1;
-        if($params['customer_product_id']){
-            $customer_product_ids=explode(',',$params['customer_product_id']);
-            $product_part=[];
-            foreach ($customer_product_ids as $ids){
-                $product_part[]=['customer_product_id'=>$ids,'parts_id'=>''];
+        if ($params['customer_product_id']) {
+            $customer_product_ids = explode(',', $params['customer_product_id']);
+            $product_part = [];
+            foreach ($customer_product_ids as $ids) {
+                $product_part[] = ['customer_product_id' => $ids, 'parts_id' => ''];
             }
-            $params['product_part'] =$product_part;
+            $params['product_part'] = $product_part;
         }
         $params['product_part'] = json_encode($params['product_part'] ?? []);
 
         // //指定员工
         // $yglist =Staff::getYkList();
-      
+
         $workorderM = new self;
         // //查询最后一条分配的员工
         // $worker_yg_id = $workorderM->order("id desc")->value("owner_staff_id");
@@ -648,8 +668,8 @@ class Workorder extends Model
         // }else{
         //     $owner_staff_id=0;
         // }
-        
-       
+
+
         // foreach($yglist as $key=>$val){
         //     if($val['id']==$worker_yg_id){
         //         //分配下一个员工
@@ -669,7 +689,7 @@ class Workorder extends Model
         }
 //        $params['create_staff_id'] = 1;
 //        $params['owner_staff_id'] = $owner_staff_id;
-       
+
         // 调用当前模型对应的User验证器类进行数据验证
         $result = $workorderM->allowField(true)->save($params);
         $lastId = $workorderM->getLastInsID();
@@ -747,7 +767,7 @@ class Workorder extends Model
         Event::where(['relation_type' => 'workorder', 'relation_id' => $params['id']])
             ->update(['status' => 1]);
         $row = self::get($params['id']);
-        $content = '开始了工单<br>备注:'.$params['desc']??'';
+        $content = '开始了工单<br>备注:' . $params['desc'] ?? '';
         $params['relation_type'] = StaffSignIn::WORKORDER_TYPE;
         $params['relation_id'] = $row['id'];
         $params['relation_process'] = '开始工单';
@@ -814,7 +834,7 @@ class Workorder extends Model
                 $other[$name] = $val;
                 unset($params[$name]);
             }
-            if(empty($val)){
+            if (empty($val)) {
                 unset($params[$name]);
             }
         }
@@ -830,7 +850,7 @@ class Workorder extends Model
         if (isset($params['product']) && $params['product']) {
             $product = $params['product'];
 
-            if (is_array($product)){
+            if (is_array($product)) {
                 $params['product'] = json_encode($product);
             }
             if ($row->workorder_type == '产品发货') {
@@ -860,8 +880,8 @@ class Workorder extends Model
                 $params['customer_product_id'] = implode(',', $customerProductIds);
             }
         }
-        if(isset($params['appointment_time'])){
-            $params['appointment_time']=$params['appointment_time']?:NULL;
+        if (isset($params['appointment_time'])) {
+            $params['appointment_time'] = $params['appointment_time'] ?: NULL;
         }
         $params['product_part'] = json_encode($params['product_part'] ?? []);
         if ($row->workorder_type == '返厂维修') {
@@ -954,12 +974,12 @@ class Workorder extends Model
      * @update_date 2021/7/9 更新时间
      * @author zhangwei
      */
-    public static function transferWorkorder($id,$dep_id, $staff_id, $desc='')
+    public static function transferWorkorder($id, $dep_id, $staff_id, $desc = '')
     {
-        $workorder=self::get($id);
+        $workorder = self::get($id);
 
         $result = self::where(['id' => $id])
-            ->update(['dep_id' => $dep_id,'owner_staff_id' => $staff_id, 'status' => 1]);
+            ->update(['dep_id' => $dep_id, 'owner_staff_id' => $staff_id, 'status' => 1]);
         if (false === $result) {
             // 验证失败 输出错误信息
             throw new Exception('修改信息错误');
@@ -972,7 +992,7 @@ class Workorder extends Model
         Event::where(['relation_type' => 'workorder', 'relation_id' => $id])->update(['staff_id' => $staff_id]);
 
         $row = self::get($id);
-        $content = '将工单转派给[部门:'.$depinfo['name'].'][' . $transferStaff['name'] . ']' . '原因:' . $desc;
+        $content = '将工单转派给[部门:' . $depinfo['name'] . '][' . $transferStaff['name'] . ']' . '原因:' . $desc;
         $params['relation_type'] = StaffSignIn::WORKORDER_TYPE;
         $params['relation_id'] = $id;
         $params['relation_process'] = '转派工单';
@@ -1001,7 +1021,7 @@ class Workorder extends Model
             'stock_up_time' => time(),
         ];
         if (isset($params['end_mileage']) && $params['end_mileage']) {
-            $params['end_mileage']=intval($params['end_mileage']);
+            $params['end_mileage'] = intval($params['end_mileage']);
             if ($params['end_mileage'] <= $workorder['start_mileage']) {
                 throw new Exception('结束公里数不能小于起始公里数');
             }
@@ -1045,7 +1065,7 @@ class Workorder extends Model
         }
 
         $row = self::get($id);
-        $content = '已到达客户位置<br/>备注:'.$desc;
+        $content = '已到达客户位置<br/>备注:' . $desc;
         $params['relation_type'] = StaffSignIn::WORKORDER_TYPE;
         $params['relation_id'] = $row['id'];
         $params['file_ids'] = $params['file_ids'] ?? '';
@@ -1115,7 +1135,7 @@ class Workorder extends Model
         Event::where(['relation_type' => 'workorder', 'relation_id' => $id])->update(['status' => 3]);
 
         $row = self::get($id);
-        $content = $workorder['workorder_type'].'任务终止,备注:' . $desc;
+        $content = $workorder['workorder_type'] . '任务终止,备注:' . $desc;
         $params['relation_type'] = StaffSignIn::WORKORDER_TYPE;
         $params['relation_id'] = $row['id'];
         $params['relation_process'] = '任务终止';
@@ -1126,6 +1146,7 @@ class Workorder extends Model
             $staff->name . '任务终止《' . $row->title . '》,请您及时审阅');
         return true;
     }
+
     //回访工单
     public static function visitWorkorder($params)
     {
@@ -1245,7 +1266,7 @@ class Workorder extends Model
         $params['relation_type'] = StaffSignIn::WORKORDER_TYPE;
         $params['relation_id'] = $row['id'];
         $params['relation_process'] = '签字';
-        $params['file_ids'] =$url;
+        $params['file_ids'] = $url;
         //创建跟进记录
         StaffSignIn::quickSignIn($row['customer_id'], $content, $params);
 
@@ -1266,11 +1287,11 @@ class Workorder extends Model
         $update = [
             'status' => 2,//进行中
             'process' => 3,//录入零件 待录入费用
-            'train_content' => json_encode($params['train_content'] ?? [],JSON_UNESCAPED_UNICODE),
+            'train_content' => json_encode($params['train_content'] ?? [], JSON_UNESCAPED_UNICODE),
             'end_time' => time()
         ];
-        if($desc){
-            $update['results']=$desc;
+        if ($desc) {
+            $update['results'] = $desc;
         }
         $use_parts = $params['use_parts'] ?? [];
         $pay_service = $params['pay_service'] ?? [];
@@ -1281,7 +1302,7 @@ class Workorder extends Model
 
         $use_parts = $new_use_parts;
         if ($row['parts'] && $use_parts) {//计算剩余零件
-            $parts=$row['parts'];
+            $parts = $row['parts'];
             $parts_key = [];
             foreach ($parts as $v) {
                 $parts_key[$v['id']] = $v['number'];
@@ -1323,7 +1344,7 @@ class Workorder extends Model
             $update['process'] = 9;
             $update['status'] = 3;//已完成
         } elseif ($row['workorder_type'] == '电话售后') {
-            if(empty($use_parts)){//不需要发送配件 直接完成
+            if (empty($use_parts)) {//不需要发送配件 直接完成
                 $update['process'] = 9;
                 $update['status'] = 3;//已完成
             }
@@ -1366,7 +1387,7 @@ class Workorder extends Model
             $content = '完成了工单;' . '<br>处理结果:' . $res;
         } elseif ($row['workorder_type'] == '上门安装') {
             $res = $row['resolved_results'];
-            if($res == 1){//安装成功
+            if ($res == 1) {//安装成功
                 CustomerProduct::where(['id' => ['in', $row['customer_product_id']]])->update([
                     'status' => 3
                 ]);
@@ -1385,9 +1406,9 @@ class Workorder extends Model
         //创建跟进记录
         StaffSignIn::quickSignIn($row['customer_id'], $content, $params);
         //发送通知
-        Message::addMessage(Message::WORKORDER_TYPE, $id,$row->owner_staff_id,$staff->id,$staff->name . '《' . $row->title . '》任务已完成,请您继续操作');
+        Message::addMessage(Message::WORKORDER_TYPE, $id, $row->owner_staff_id, $staff->id, $staff->name . '《' . $row->title . '》任务已完成,请您继续操作');
 //发送通知
-        if($update['status'] == 3){
+        if ($update['status'] == 3) {
             self::setComplete($row['id']);
         }
         return true;
@@ -1494,7 +1515,7 @@ class Workorder extends Model
         $update['collection_deposit'] = $params['collection_deposit'] ?? '';//
         $update['collection_account'] = $params['collection_account'] ?? '';
         $update['collection_name'] = $params['collection_name'] ?? '';//
-        $update['is_charge']=$params['is_charge']??1;//是否收费 1收费 2不收费
+        $update['is_charge'] = $params['is_charge'] ?? 1;//是否收费 1收费 2不收费
         $update['use_parts'] = [];
 
         $use_parts = $params['use_parts'] ?? [];
@@ -1521,9 +1542,9 @@ class Workorder extends Model
         $update['check_status'] = 1;
         if ($flow['status'] == 1) {//固定审批
             //发送审批通知
-            Flow::sendStepRecord($flow,Flow::WORKORDER_STATUS, $id);
+            Flow::sendStepRecord($flow, Flow::WORKORDER_STATUS, $id);
         } else {//发起人自选 依次审批
-            $staff_id   = explode(',', $params['flow_staff_ids'])[0];
+            $staff_id = explode(',', $params['flow_staff_ids'])[0];
             if ($staff_id) {
                 ExamineRecord::addExaminse(ExamineRecord::WORKORDER_TYPE, $id, $staff_id);
             }
@@ -1561,8 +1582,8 @@ class Workorder extends Model
         $data['relation_process'] = '确认收款';
         //创建跟进记录
         StaffSignIn::quickSignIn($row['customer_id'], $content, $data);
-        $staff=Staff::info();
-        Message::setRead(Message::WORKORDER_RECEIVABLES,$workorder_id,$staff->id);
+        $staff = Staff::info();
+        Message::setRead(Message::WORKORDER_RECEIVABLES, $workorder_id, $staff->id);
         return true;
     }
 
@@ -1631,10 +1652,11 @@ class Workorder extends Model
 
         return true;
     }
+
     //添加品质异常单
     public static function addProgress($params)
     {
-        $staff=Staff::info();
+        $staff = Staff::info();
         //填写进度
         $model = new WorkorderProgress();
         $params['create_staff_id'] = $staff->id;
@@ -1672,11 +1694,12 @@ class Workorder extends Model
         StaffSignIn::quickSignIn($row['customer_id'], $content, $params);
         return true;
     }
+
     //取消测试/继续测试
     public static function continueTest($id, $is_continue)
     {
         $workorder = self::where(['id' => $id])->find();
-        if(empty($workorder)){
+        if (empty($workorder)) {
             return false;
         }
         if ($is_continue == 1) {//继续维修
@@ -1698,7 +1721,7 @@ class Workorder extends Model
             $messageContent = $staff->name . '《' . $workorder['title'] . '》评估继续维修,请您及时审阅';
             $toStaff = [$workorder['create_staff_id'], $workorder['owner_staff_id']];
             $toStaff = implode(',', $toStaff);
-            Message::addMessage(Message::WORKORDER_TYPE, $id,  $workorder['owner_staff_id'], $staff->id, $messageContent);
+            Message::addMessage(Message::WORKORDER_TYPE, $id, $workorder['owner_staff_id'], $staff->id, $messageContent);
 
         } elseif ($is_continue == 9) {//取消维修
             $data['process'] = 9;
@@ -1737,8 +1760,8 @@ class Workorder extends Model
     //工单完成
     public static function setComplete($workorder_id)
     {
-        $staff=Staff::info();
-        $row=self::get($workorder_id);
+        $staff = Staff::info();
+        $row = self::get($workorder_id);
         //日程完成
         Event::where(['relation_type' => 'workorder', 'relation_id' => $workorder_id])
             ->update(['status' => 2]);
@@ -1746,9 +1769,9 @@ class Workorder extends Model
             //回访客户通知
             Message::addMessage(Message::WORKORDER_TYPE, $row['id'], $row['create_staff_id'], $staff->id, '《' . $row->title . '》工单已完成,请您尽快回访客户!');
         }
-        if($row['is_pay'] == 1){
+        if ($row['is_pay'] == 1) {
             //发送通知
-            Message::addMessage(Message::WORKORDER_RECEIVABLES, $workorder_id,$row['create_staff_id'],$staff->id, '《' . $row->title . '》任务已完成,请您及时确认回款情况!');
+            Message::addMessage(Message::WORKORDER_RECEIVABLES, $workorder_id, $row['create_staff_id'], $staff->id, '《' . $row->title . '》任务已完成,请您及时确认回款情况!');
         }
         return true;
     }
@@ -1756,6 +1779,6 @@ class Workorder extends Model
     //获取回访工单类型
     public static function getVisitType()
     {
-        return ['上门安装', '上门维修','配件安装'];
+        return ['上门安装', '上门维修', '配件安装'];
     }
 }

+ 46 - 41
application/admin/controller/qingdongams/contract/Record.php

@@ -1,6 +1,7 @@
 <?php
 
 namespace app\admin\controller\qingdongams\contract;
+
 use addons\qingdongams\model\Contract;
 use addons\qingdongams\model\Field;
 use addons\qingdongams\model\File;
@@ -16,8 +17,10 @@ use think\Exception;
  * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
  * @desc 售后微信:qingdong_crm
  */
-class Record extends Base {
-    public function _initialize() {
+class Record extends Base
+{
+    public function _initialize()
+    {
         parent::_initialize();
         $this->model = new RecordModel();
     }
@@ -26,81 +29,82 @@ class Record extends Base {
     /**
      * 跟进列表
      */
-    public function index() {
+    public function index()
+    {
         $this->request->filter(['strip_tags']);
-        $need = input('need','');
+        $need = input('need', '');
         if ($this->request->isAjax()) {
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
             //0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进
-            $type = input('type',0);
-            switch($type){
+            $type = input('type', 0);
+            switch ($type) {
                 case 1:
                     $staff = Staff::info();
-                    $wheres['create_staff_id'] =  $staff->id;
+                    $wheres['create_staff_id'] = $staff->id;
                     break;
                 case 2:
-                    $wheres['create_staff_id'] =  array('in',Staff::getLowerStaffId());
+                    $wheres['create_staff_id'] = array('in', Staff::getLowerStaffId());
                     break;
                 case 3:
                     $start = date('Y-m-d 00:00:00');
                     $end = date('Y-m-d 23:59:59');
-                    $record = collection(RecordModel::where(array('relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
+                    $record = collection(RecordModel::where(array('relation_type' => 3, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
                     $relationId = [];
-                    foreach($record as $k=>$v){
-                        $whereRe['id'] = array('gt',$v['id']);
+                    foreach ($record as $k => $v) {
+                        $whereRe['id'] = array('gt', $v['id']);
                         $whereRe['relation_id'] = $v['relation_id'];
                         $recordData = RecordModel::where($whereRe)->count();
-                        if($recordData == 0){
+                        if ($recordData == 0) {
                             $relationId[] = $v['id'];
                         }
 
                     }
-                    $wheres['id'] =  array('in',$relationId);
+                    $wheres['id'] = array('in', $relationId);
                     $staff = Staff::info();
-                    $wheres['create_staff_id'] =  $staff->id;
+                    $wheres['create_staff_id'] = $staff->id;
                     break;
                 case 4:
                     $start = date('Y-m-d 00:00:00');
                     $end = date('Y-m-d 23:59:59');
-                    $record = collection(RecordModel::where(array('relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
+                    $record = collection(RecordModel::where(array('relation_type' => 3, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
                     $relationId = [];
-                    foreach($record as $k=>$v){
-                        $whereRe['id'] = array('gt',$v['id']);
+                    foreach ($record as $k => $v) {
+                        $whereRe['id'] = array('gt', $v['id']);
                         $whereRe['relation_id'] = $v['relation_id'];
                         $recordData = RecordModel::where($whereRe)->count();
-                        if($recordData >=1){
+                        if ($recordData >= 1) {
                             $relationId[] = $v['id'];
                         }
 
                     }
-                    $wheres['id'] =  array('in',$relationId);
+                    $wheres['id'] = array('in', $relationId);
                     $staff = Staff::info();
-                    $wheres['create_staff_id'] =  $staff->id;
+                    $wheres['create_staff_id'] = $staff->id;
                     break;
                 default:
-                    $wheres['create_staff_id'] =  array('in',Staff::getMyStaffIds());
+                    $wheres['create_staff_id'] = array('in', Staff::getMyStaffIds());
                     break;
 
             }
             $wheres['relation_type'] = 3;
-            if(isset($need) && $need =='contract'){
+            if (isset($need) && $need == 'contract') {
                 $staff = Staff::info();
-                $wheres['create_staff_id'] =  $staff->id;
+                $wheres['create_staff_id'] = $staff->id;
                 $wheres['status'] = 0;
                 $wheres['follow_type'] = ['neq', '其它'];
-                $wheres['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59')));
+                $wheres['next_time'] = array(array('egt', date('Y-m-d 00:00:00')), array('lt', date('Y-m-d 23:59:59')));
                 $infolist = $this->model->where($wheres)->column('relation_id');
-                if($infolist){
-                    $whereExit['relation_id'] = array('in',$infolist);
-                    $whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59'));
+                if ($infolist) {
+                    $whereExit['relation_id'] = array('in', $infolist);
+                    $whereExit['next_time'] = array('gt', date('Y-m-d 23:59:59'));
                     $recordIds = $this->model->where($whereExit)->column('id');
-                    if($recordIds){
-                        $wheres['id'] = array('in',$recordIds);
+                    if ($recordIds) {
+                        $wheres['id'] = array('in', $recordIds);
                     }
                 }
             }
-            $list   = $this->model->where($where)->where($wheres)->with(['staff','contract'])->order($sort, $order)->paginate($limit);
-            $row    = $list->items();
+            $list = $this->model->where($where)->where($wheres)->with(['staff', 'contract'])->order($sort, $order)->paginate($limit);
+            $row = $list->items();
             $result = array("total" => $list->total(), "rows" => $row);
 
             return json($result);
@@ -112,16 +116,17 @@ class Record extends Base {
     /**
      * 添加跟进
      */
-    public function add($ids = null) {
-        $relation_type=input('relation_type',3);
+    public function add($ids = null)
+    {
+        $relation_type = input('relation_type', 3);
         if ($this->request->isPost()) {
             $params = $this->request->post('row/a');
             // 表单验证
             if (($result = $this->qingdongamsValidate($params, 'Record', 'create')) !== true) {
                 $this->error($result);
             }
-            if(!empty($params['files'])){
-                $params['files']=File::getId($params['files']);
+            if (!empty($params['files'])) {
+                $params['files'] = File::getId($params['files']);
             }
             Db::startTrans();
             try {
@@ -137,13 +142,13 @@ class Record extends Base {
             $this->error('创建失败');
         }
 
-        $staff=Staff::where([])->column('name','id');
-        if($ids){
-            $contracts=Contract::where(['id'=>$ids])->column('id,name');
-        }else{
-            $contracts=Contract::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->column('id,name');
+        $staff = Staff::where([])->column('name', 'id');
+        if ($ids) {
+            $contracts = Contract::where(['id' => $ids])->column('id,name');
+        } else {
+            $contracts = Contract::where(['owner_staff_id' => ['in', Staff::getMyStaffIds()]])->column('id,name');
         }
-        $follow= Field::getField('客户状态');
+        $follow = Field::getField('客户状态');
         $this->assign('ids', $ids);
         $this->assign('relation_type', $relation_type);
         $this->assign('contracts', $contracts);

+ 239 - 231
application/admin/controller/qingdongams/customer/Contacts.php

@@ -26,114 +26,118 @@ use think\Exception;
  * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
  * @desc 售后微信:qingdong_crm
  */
-class Contacts extends Base {
-	protected $relationSearch = true;
-	protected $searchFields   = 'id,username,nickname';
-	/**
-	 * @var \addons\qingdongams\model\Contacts
-	 */
-	protected $model = null;
-
-
-	public function _initialize() {
-		parent::_initialize();
-		$this->model = new \addons\qingdongams\model\Contacts;
-	}
-
-
-	/**
-	 * 查看
-	 */
-	public function index() {
-		//设置过滤方法
-		$this->request->filter(['strip_tags', 'trim']);
-		if ($this->request->isAjax()) {
-			//如果发送的来源是Selectpage,则转发到Selectpage
-			if ($this->request->request('keyField')) {
-				return $this->selectpage();
-			}
+class Contacts extends Base
+{
+    protected $relationSearch = true;
+    protected $searchFields = 'id,username,nickname';
+    /**
+     * @var \addons\qingdongams\model\Contacts
+     */
+    protected $model = null;
+
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \addons\qingdongams\model\Contacts;
+    }
+
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
             //0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的
-            $type = input('type',0);
-			list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-            switch($type){
+            $type = input('type', 0);
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+            switch ($type) {
                 case 1:
                     $staff = Staff::info();
-                    $wheres['owner_staff_id'] =  $staff->id;
+                    $wheres['owner_staff_id'] = $staff->id;
                     break;
                 case 2:
-                    $wheres['owner_staff_id'] =  array('in',Staff::getLowerStaffId());
+                    $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
                     break;
                 case 3:
                     $start = date('Y-m-d 00:00:00');
                     $end = date('Y-m-d 23:59:59');
-                    $record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
+                    $record = collection(Record::where(array('relation_type' => 2, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
                     $relationId = [];
-                    foreach($record as $k=>$v){
-                        $whereRe['id'] = array('gt',$v['id']);
+                    foreach ($record as $k => $v) {
+                        $whereRe['id'] = array('gt', $v['id']);
                         $whereRe['relation_id'] = $v['relation_id'];
                         $recordData = Record::where($whereRe)->count();
-                        if($recordData == 0){
+                        if ($recordData == 0) {
                             $relationId[] = $v['relation_id'];
                         }
 
                     }
-                    $wheres['id'] =  array('in',$relationId);
+                    $wheres['id'] = array('in', $relationId);
                     $staff = Staff::info();
-                    $wheres['owner_staff_id'] =  $staff->id;
+                    $wheres['owner_staff_id'] = $staff->id;
                     break;
                 case 4:
                     $start = date('Y-m-d 00:00:00');
                     $end = date('Y-m-d 23:59:59');
-                    $record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
+                    $record = collection(Record::where(array('relation_type' => 2, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
                     $relationId = [];
-                    foreach($record as $k=>$v){
-                        $whereRe['id'] = array('gt',$v['id']);
+                    foreach ($record as $k => $v) {
+                        $whereRe['id'] = array('gt', $v['id']);
                         $whereRe['relation_id'] = $v['relation_id'];
                         $recordData = Record::where($whereRe)->count();
-                        if($recordData >=1){
+                        if ($recordData >= 1) {
                             $relationId[] = $v['relation_id'];
                         }
 
                     }
-                    $wheres['id'] =  array('in',$relationId);
+                    $wheres['id'] = array('in', $relationId);
                     $staff = Staff::info();
-                    $wheres['owner_staff_id'] =  $staff->id;
+                    $wheres['owner_staff_id'] = $staff->id;
                     break;
                 case 5:
-                    $record = collection(Record::where(array('relation_type'=>2,'next_time'=>array('neq','')))->column('relation_id'))->toArray();
-                    $wheres['id'] =  array('not in',$record);
+                    $record = collection(Record::where(array('relation_type' => 2, 'next_time' => array('neq', '')))->column('relation_id'))->toArray();
+                    $wheres['id'] = array('not in', $record);
                     $staff = Staff::info();
-                    $wheres['owner_staff_id'] =  $staff->id;
+                    $wheres['owner_staff_id'] = $staff->id;
                     break;
                 default:
-                    $wheres['owner_staff_id'] =  array('in',Staff::getMyStaffIds());
+                    $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
                     break;
 
             }
 
-			$list = $this->model->with(['ownerStaff'])
+            $list = $this->model->with(['ownerStaff'])
                 ->where($wheres)
                 ->where($where)->with(['customer'])->order($sort, $order)->paginate($limit);
 
-			$result = array("total" => $list->total(), "rows" => $list->items());
+            $result = array("total" => $list->total(), "rows" => $list->items());
 
-			return json($result);
-		}
+            return json($result);
+        }
 
         $field = FormField::getFields(FormField::CONTACTS_TYPE);
         $this->assignconfig('fields', $field);
-		return $this->view->fetch();
-	}
-
-
-	/**
-	 * 添加
-	 */
-	public function add() {
-		if ($this->request->isPost()) {
-			$params = $this->request->post("row/a");
-			if ($params) {
-				$params = $this->preExcludeFields($params);
+        return $this->view->fetch();
+    }
+
+
+    /**
+     * 添加
+     */
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
                 // 表单验证
                 if (($result = $this->qingdongamsValidate($params, 'Contacts', 'create')) !== true) {
                     $this->error($result);
@@ -143,183 +147,187 @@ class Contacts extends Base {
                 if ($result !== true) {
                     $this->error($result);
                 }
-				$result = false;
-				Db::startTrans();
-				try {
-                    $is_linkman=AdminConfig::getConfigValue('is_linkman',AdminConfig::TYPE_SEAS);
+                $result = false;
+                Db::startTrans();
+                try {
+                    $is_linkman = AdminConfig::getConfigValue('is_linkman', AdminConfig::TYPE_SEAS);
                     //联系人手机号是否允许重复
-                    if($is_linkman == 1){//不同客户的联系人是否允许重复
-                        $contactsFind = $this->model->where(array('customer_id'=>$params['customer_id'],'mobile'=>$params['mobile']))->find();
-                        if($contactsFind){
+                    if ($is_linkman == 1) {//不同客户的联系人是否允许重复
+                        $contactsFind = $this->model->where(array('customer_id' => $params['customer_id'], 'mobile' => $params['mobile']))->find();
+                        if ($contactsFind) {
                             throw new Exception('手机号已存在');
                         }
-                    }else{
-                        $contactsFind = $this->model->where(array('mobile'=>$params['mobile']))->find();
-                        if($contactsFind){
+                    } else {
+                        $contactsFind = $this->model->where(array('mobile' => $params['mobile']))->find();
+                        if ($contactsFind) {
                             throw new Exception('手机号已存在');
                         }
                     }
 
-                    if(isset($params['email'])){
-                        $contactsFind = $this->model->where(array('customer_id'=>$params['customer_id'],'email'=>$params['email']))->find();
-                        if($contactsFind){
+                    if (isset($params['email'])) {
+                        $contactsFind = $this->model->where(array('customer_id' => $params['customer_id'], 'email' => $params['email']))->find();
+                        if ($contactsFind) {
                             throw new Exception('邮箱已存在');
                         }
                     }
                     $params = Form::updateFormParams(Form::CONTACTS_TYPE, $params);
 
-					$result             = $this->model::createContacts($params);
-					Db::commit();
-				} catch (Exception $e) {
-					Db::rollback();
-					$this->error($e->getMessage());
-				}
-				if ($result !== false) {
-					$this->success();
-				} else {
-					$this->error(__('No rows were inserted'));
-				}
-			}
-			$this->error(__('Parameter %s can not be empty', ''));
-		}
-		$staffs = Customer::getList();
-        $customer_id=input('customer_id');
-        $customer= Customer::get($customer_id);
-
-		$this->assign('staffs', $staffs);
-		$this->assign('customer_id', input('customer_id'));
-		$this->assign('customer', $customer);
-		$this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE));
-
-
-		return $this->view->fetch();
-	}
-
-
-	/**
-	 * 修改
-	 */
-	public function edit($ids = null) {
-		$row = $this->model->get($ids);
-		if ($this->request->isPost()) {
-			$params = $this->request->post("row/a");
-			if ($params) {
-				$params = $this->preExcludeFields($params);
+                    $result = $this->model::createContacts($params);
+                    Db::commit();
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were inserted'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $staffs = Customer::getList();
+        $customer_id = input('customer_id');
+        $customer = Customer::get($customer_id);
+
+        $this->assign('staffs', $staffs);
+        $this->assign('customer_id', input('customer_id'));
+        $this->assign('customer', $customer);
+        $this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE));
+
+
+        return $this->view->fetch();
+    }
+
+
+    /**
+     * 修改
+     */
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
                 // 表单验证
                 if (($result = $this->qingdongamsValidate($params, 'Contacts', 'create')) !== true) {
                     $this->error($result);
                 }
 
-                $result = FormField::checkFields(FormField::CONTACTS_TYPE, $params,$ids);
+                $result = FormField::checkFields(FormField::CONTACTS_TYPE, $params, $ids);
                 if ($result !== true) {
                     $this->error($result);
                 }
-				$result = false;
-				Db::startTrans();
-				try {
-                    $is_linkman=AdminConfig::getConfigValue('is_linkman',AdminConfig::TYPE_SEAS);
-                    if($is_linkman == 1){//不同客户的联系人是否允许重复
-                        $contactsFind = $this->model->where(array('id'=>['neq',$row['id']],'customer_id'=>$row['customer_id'],'mobile'=>$params['mobile']))->find();
-                        if($contactsFind){
+                $result = false;
+                Db::startTrans();
+                try {
+                    $is_linkman = AdminConfig::getConfigValue('is_linkman', AdminConfig::TYPE_SEAS);
+                    if ($is_linkman == 1) {//不同客户的联系人是否允许重复
+                        $contactsFind = $this->model->where(array('id' => ['neq', $row['id']], 'customer_id' => $row['customer_id'], 'mobile' => $params['mobile']))->find();
+                        if ($contactsFind) {
                             throw new Exception('手机号已存在');
                         }
-                    }else{
-                        $contactsFind = $this->model->where(array('id'=>['neq',$row['id']],'mobile'=>$params['mobile']))->find();
-                        if($contactsFind){
+                    } else {
+                        $contactsFind = $this->model->where(array('id' => ['neq', $row['id']], 'mobile' => $params['mobile']))->find();
+                        if ($contactsFind) {
                             throw new Exception('手机号已存在');
                         }
                     }
-                    if(isset($params['email'])){
-                        $contactsFind = $this->model->where(array('id'=>['neq',$row['id']],'customer_id'=>$row['customer_id'],'email'=>$params['email']))->find();
-                        if($contactsFind){
+                    if (isset($params['email'])) {
+                        $contactsFind = $this->model->where(array('id' => ['neq', $row['id']], 'customer_id' => $row['customer_id'], 'email' => $params['email']))->find();
+                        if ($contactsFind) {
                             throw new Exception('邮箱已存在');
                         }
                     }
                     $params = Form::updateFormParams(Form::CONTACTS_TYPE, $params);
 
-					$params['id']=$ids;
-					$result = $row::updateContacts($params);
-					Db::commit();
-				} catch (Exception $e) {
-					Db::rollback();
-					$this->error($e->getMessage());
-				}
-				if ($result !== false) {
-					$this->success();
-				} else {
-					$this->error(__('No rows were inserted'));
-				}
-			}
-			$this->error(__('Parameter %s can not be empty', ''));
-		}
-		$staffs = \addons\qingdongams\model\Customer::getList();
-		$this->assign('staffs', $staffs);
-
-        $row=$row->toArray();
-        $row=ContactsOther::getOther($row);
-		$this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE,$row));
-		$this->assign('row', $row);
-
-		return $this->view->fetch();
-	}
+                    $params['id'] = $ids;
+                    $result = $row::updateContacts($params);
+                    Db::commit();
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were inserted'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $staffs = \addons\qingdongams\model\Customer::getList();
+        $this->assign('staffs', $staffs);
+
+        $row = $row->toArray();
+        $row = ContactsOther::getOther($row);
+        $this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE, $row));
+        $this->assign('row', $row);
+
+        return $this->view->fetch();
+    }
 
     /**
      * 联系人详情
      */
-	public function detail($ids = null) {
-		$row = $this->model->with(['customer'])->where(['id' => $ids])->find();
-		if(empty($row)){
-			$this->error('信息不存在');
-		}
-		//跟进记录
-		$this->assign('records', Record::getList(Record::CONTACTS_TYPE, $ids));
-		//操作记录
-		$this->assign('operation_log', OperationLog::getList(OperationLog::CONTACTS_TYPE, $ids));
-        $row=$row->toArray();
-        $row=ContactsOther::getOther($row);
-
-
-		$this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE,$row));
-		$this->assign('row', $row);
-		$this->assign('ids', $ids);
+    public function detail($ids = null)
+    {
+        $row = $this->model->with(['customer'])->where(['id' => $ids])->find();
+        if (empty($row)) {
+            $this->error('信息不存在');
+        }
+        //跟进记录
+        $this->assign('records', Record::getList(Record::CONTACTS_TYPE, $ids));
+        //操作记录
+        $this->assign('operation_log', OperationLog::getList(OperationLog::CONTACTS_TYPE, $ids));
+        $row = $row->toArray();
+        $row = ContactsOther::getOther($row);
+
+
+        $this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE, $row));
+        $this->assign('row', $row);
+        $this->assign('ids', $ids);
         $this->assignconfig("idinfo", ['id' => $ids]);
-		return $this->view->fetch();
-	}
+        return $this->view->fetch();
+    }
 
 
     /**
      * 获取附件记录
      */
-	public function get_file($ids = null) {
-		list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-		$list = \addons\qingdongams\model\ContactsFile::where(['contacts_id' => $ids])->with(['file'])->field('file_id')->paginate($limit);
-
-		$result = array("total" => $list->total(), "rows" => $list->items());
-
-		return json($result);
-	}
-
-
-	/**
-	 * 删除
-	 */
-	public function del($ids = "") {
-		if (!$this->request->isPost()) {
-			$this->error(__("Invalid parameters"));
-		}
-		$ids                 = $ids ? $ids : $this->request->post("ids");
-		$row                 = $this->model->get($ids);
-		$this->modelValidate = true;
-		if (!$row) {
-			$this->error(__('No Results were found'));
-		}
-		$map['id'] = $ids;
-		$result    = $this->model->destroy($map);
-		if (!$result) {
-			$this->error('删除失败');
-		}
-		$this->success();
-	}
+    public function get_file($ids = null)
+    {
+        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+        $list = \addons\qingdongams\model\ContactsFile::where(['contacts_id' => $ids])->with(['file'])->field('file_id')->paginate($limit);
+
+        $result = array("total" => $list->total(), "rows" => $list->items());
+
+        return json($result);
+    }
+
+
+    /**
+     * 删除
+     */
+    public function del($ids = "")
+    {
+        if (!$this->request->isPost()) {
+            $this->error(__("Invalid parameters"));
+        }
+        $ids = $ids ? $ids : $this->request->post("ids");
+        $row = $this->model->get($ids);
+        $this->modelValidate = true;
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $map['id'] = $ids;
+        $result = $this->model->destroy($map);
+        if (!$result) {
+            $this->error('删除失败');
+        }
+        $this->success();
+    }
 
     /**
      * 导入客户
@@ -401,7 +409,7 @@ class Contacts extends Base {
             $errorInfo = [];
 
             $fieldnames = FormField::where(['types' => FormField::CONTACTS_TYPE])->column('field', 'name');
-            $customerNames=Customer::where([])->column('id,owner_staff_id','name');
+            $customerNames = Customer::where([])->column('id,owner_staff_id', 'name');
             $fn = [];
             for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
                 $values = [];
@@ -425,14 +433,14 @@ class Contacts extends Base {
                 }
                 $lastid++;
                 $addContacts = ['id' => $lastid];
-                $customer=isset($customerNames[$values[0]])?$customerNames[$values[0]]:0;
-                if(empty($customer)){
+                $customer = isset($customerNames[$values[0]]) ? $customerNames[$values[0]] : 0;
+                if (empty($customer)) {
                     $errorInfo[] = "第{$currentRow}行,客户名称不存在;";
                     continue;
                 }
-                $addContacts['customer_id']=$customer['id'];
-                $addContacts['owner_staff_id']=$customer['owner_staff_id'];
-                $addContacts['create_staff_id']=$customer['owner_staff_id'];
+                $addContacts['customer_id'] = $customer['id'];
+                $addContacts['owner_staff_id'] = $customer['owner_staff_id'];
+                $addContacts['create_staff_id'] = $customer['owner_staff_id'];
                 foreach ($values as $kv => $value) {
                     if (!isset($fn[$kv]) || empty($fn[$kv])) {
                         continue;
@@ -527,66 +535,66 @@ class Contacts extends Base {
             }
         }
         //0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的
-        $type = input('type',0);
+        $type = input('type', 0);
         list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-        switch($type){
+        switch ($type) {
             case 1:
                 $staff = Staff::info();
-                $wheres['owner_staff_id'] =  $staff->id;
+                $wheres['owner_staff_id'] = $staff->id;
                 break;
             case 2:
-                $wheres['owner_staff_id'] =  array('in',Staff::getLowerStaffId());
+                $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
                 break;
             case 3:
                 $start = date('Y-m-d 00:00:00');
                 $end = date('Y-m-d 23:59:59');
-                $record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
+                $record = collection(Record::where(array('relation_type' => 2, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
                 $relationId = [];
-                foreach($record as $k=>$v){
-                    $whereRe['id'] = array('gt',$v['id']);
+                foreach ($record as $k => $v) {
+                    $whereRe['id'] = array('gt', $v['id']);
                     $whereRe['relation_id'] = $v['relation_id'];
                     $recordData = Record::where($whereRe)->count();
-                    if($recordData == 0){
+                    if ($recordData == 0) {
                         $relationId[] = $v['relation_id'];
                     }
 
                 }
-                $wheres['id'] =  array('in',$relationId);
+                $wheres['id'] = array('in', $relationId);
                 $staff = Staff::info();
-                $wheres['owner_staff_id'] =  $staff->id;
+                $wheres['owner_staff_id'] = $staff->id;
                 break;
             case 4:
                 $start = date('Y-m-d 00:00:00');
                 $end = date('Y-m-d 23:59:59');
-                $record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
+                $record = collection(Record::where(array('relation_type' => 2, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
                 $relationId = [];
-                foreach($record as $k=>$v){
-                    $whereRe['id'] = array('gt',$v['id']);
+                foreach ($record as $k => $v) {
+                    $whereRe['id'] = array('gt', $v['id']);
                     $whereRe['relation_id'] = $v['relation_id'];
                     $recordData = Record::where($whereRe)->count();
-                    if($recordData >=1){
+                    if ($recordData >= 1) {
                         $relationId[] = $v['relation_id'];
                     }
 
                 }
-                $wheres['id'] =  array('in',$relationId);
+                $wheres['id'] = array('in', $relationId);
                 $staff = Staff::info();
-                $wheres['owner_staff_id'] =  $staff->id;
+                $wheres['owner_staff_id'] = $staff->id;
                 break;
             case 5:
-                $record = collection(Record::where(array('relation_type'=>2,'next_time'=>array('neq','')))->column('relation_id'))->toArray();
-                $wheres['id'] =  array('not in',$record);
+                $record = collection(Record::where(array('relation_type' => 2, 'next_time' => array('neq', '')))->column('relation_id'))->toArray();
+                $wheres['id'] = array('not in', $record);
                 $staff = Staff::info();
-                $wheres['owner_staff_id'] =  $staff->id;
+                $wheres['owner_staff_id'] = $staff->id;
                 break;
             default:
-                $wheres['owner_staff_id'] =  array('in',Staff::getMyStaffIds());
+                $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
                 break;
 
         }
 
         $list = $this->model->with([
-            'ownerStaff','contactsOther','customer'
+            'ownerStaff', 'contactsOther', 'customer'
         ])->where($where)->where($wheres)->order($sort, $order)->select();
         $list = collection($list)->toArray();
 
@@ -607,9 +615,9 @@ class Contacts extends Base {
             $title[] = $val['config']['label'];
         }
         foreach ($list as $k => $v) {
-            if($v['contacts_other']){//其他客户
-                $other=$v['contacts_other']['otherdata'];
-                $other=json_decode($other,true);
+            if ($v['contacts_other']) {//其他客户
+                $other = $v['contacts_other']['otherdata'];
+                $other = json_decode($other, true);
                 $v = array_merge($v, $other);
             }
             $field = array(
@@ -617,7 +625,7 @@ class Contacts extends Base {
                 $v['customer']['name'],
 
                 $v['owner_staff']['name'],
-                date('Y-m-d H:i:s',$v['createtime']),
+                date('Y-m-d H:i:s', $v['createtime']),
                 $v['next_time']
             );
             foreach ($dataValue as $val) {

+ 39 - 31
application/admin/controller/qingdongams/department/Staff.php

@@ -15,11 +15,13 @@ use app\admin\model\Admin;
 /**
  * 员工管理
  */
-class Staff extends  Base {
+class Staff extends Base
+{
 
-    public function _initialize() {
+    public function _initialize()
+    {
         parent::_initialize();
-        $this->model      = new StaffModel();
+        $this->model = new StaffModel();
 
         $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
         $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
@@ -55,15 +57,16 @@ class Staff extends  Base {
      * 员工列表
      * @return string
      */
-    public function index() {
+    public function index()
+    {
         $this->request->filter(['strip_tags']);
         if ($this->request->isAjax()) {
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
-            $list = $this->model->with(['parent','admin','staffrole'])
+            $list = $this->model->with(['parent', 'admin', 'staffrole'])
                 ->where(['id' => ['neq', 1]])
                 ->where($where)->order($sort, $order)->paginate($limit);
-            $row  = $list->items();
+            $row = $list->items();
 
             $result = array("total" => $list->total(), "rows" => $row);
 
@@ -78,12 +81,13 @@ class Staff extends  Base {
      * 添加员工
      * @return string
      */
-    public function add() {
+    public function add()
+    {
         if ($this->request->isAjax()) {
             $data = $this->request->post('row/a');
             $mobile = $data['mobile'];
             $count = StaffModel::where(['mobile' => $mobile])->count();
-            if($count > 0){
+            if ($count > 0) {
                 $this->error('员工手机号已存在');
             }
 
@@ -92,7 +96,7 @@ class Staff extends  Base {
             $data['salt'] = $newSalt;
             $data['password'] = $newPassword;
             $data['status'] = 1;
-            if(empty($data['img'])){
+            if (empty($data['img'])) {
                 $data['img'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
             }
             Db::startTrans();
@@ -104,10 +108,10 @@ class Staff extends  Base {
                     exception(__('The parent group exceeds permission limit'));
                 }
                 $dataset = [];
-                $data['group_ids'] = implode(',',$group);
+                $data['group_ids'] = implode(',', $group);
                 $result = $this->model->save($data);
                 Db::commit();
-            }catch (Exception $e){
+            } catch (Exception $e) {
                 Db::rollback();
                 $this->error($e->getMessage());
             }
@@ -119,19 +123,19 @@ class Staff extends  Base {
         }
 
         $staffname = StaffModel::where(['id' => ['neq', 1]])->column('id,name');
-        $staffs    = ['' => '请选择'];
+        $staffs = ['' => '请选择'];
         foreach ($staffname as $id => $name) {
             $staffs[$id] = $name;
         }
         $this->view->assign('staffs', $staffs);
 
         $staffname = StaffModel::column('id,name');
-        $staffs    = ['' => '无'];
+        $staffs = ['' => '无'];
         foreach ($staffname as $id => $name) {
             $staffs[$id] = $name;
         }
         $role_list = ['' => '请选择'];
-        $staff_role = StaffRole::column('name','id');
+        $staff_role = StaffRole::column('name', 'id');
         foreach ($staff_role as $key => $value) {
             $role_list[$key] = $value;
         }
@@ -145,7 +149,8 @@ class Staff extends  Base {
      * @param null $ids
      * @return string
      */
-    public function edit($ids = null) {
+    public function edit($ids = null)
+    {
         $map['id'] = $ids;
         if ($this->request->isAjax()) {
             $row = StaffModel::where($map)->find();
@@ -160,11 +165,11 @@ class Staff extends  Base {
                 unset($data['password']);
             }
             $mobile = $data['mobile'];
-            $count = StaffModel::where(['mobile'=>$mobile,'id'=>['neq',$ids]])->count();
-            if($count > 0){
+            $count = StaffModel::where(['mobile' => $mobile, 'id' => ['neq', $ids]])->count();
+            if ($count > 0) {
                 $this->error('员工手机号已存在');
             }
-            if(empty($data['img'])){
+            if (empty($data['img'])) {
                 $data['img'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
             }
             Db::startTrans();
@@ -173,7 +178,7 @@ class Staff extends  Base {
                     // 先移除所有权限
                     model('AuthGroupAccess')->where('uid', $row->admin_id)->delete();
 
-                    $group = $this->request->post("group/a",[]);
+                    $group = $this->request->post("group/a", []);
                     //过滤不允许的组别,避免越权
                     $group = array_intersect($this->childrenGroupIds, $group);
                     if (!$group) {
@@ -191,7 +196,7 @@ class Staff extends  Base {
                 $data['id'] = $map['id'];
                 $result = $this->model->save($data, $map);
                 Db::commit();
-            }catch (Exception $e){
+            } catch (Exception $e) {
                 Db::rollback();
                 $this->error($e->getMessage());
             }
@@ -205,18 +210,18 @@ class Staff extends  Base {
         $this->view->assign("row", $data);
 
         $staffname = StaffModel::where(['id' => ['neq', 1]])->column('id,name');
-        $staffs    = ['' => '请选择'];
+        $staffs = ['' => '请选择'];
         foreach ($staffname as $id => $name) {
             $staffs[$id] = $name;
         }
         $this->view->assign('staffs', $staffs);
 
         $role_list = ['' => '请选择'];
-        $staff_role = StaffRole::column('name','id');
+        $staff_role = StaffRole::column('name', 'id');
         foreach ($staff_role as $key => $value) {
             $role_list[$key] = $value;
         }
-        $this->view->assign('roles',$role_list);
+        $this->view->assign('roles', $role_list);
 
         return $this->view->fetch();
     }
@@ -224,16 +229,17 @@ class Staff extends  Base {
     /**
      * 删除员工
      */
-    public function del($ids = null) {
+    public function del($ids = null)
+    {
         if ($this->request->isAjax()) {
             $map['id'] = array('in', $ids);
             $findinfo = StaffModel::where($map)->select();
-            foreach($findinfo as $k=>$v){
-                if($v['admin_id'] ==1 || $v['id'] == 15){
+            foreach ($findinfo as $k => $v) {
+                if ($v['admin_id'] == 1 || $v['id'] == 15) {
                     $this->error('管理员不可删除');
                 }
             }
-            $result    = StaffModel::destroy($map);
+            $result = StaffModel::destroy($map);
 
             if (!$result) {
                 $this->error('删除失败');
@@ -257,8 +263,9 @@ class Staff extends  Base {
     /**
      * 更新状态禁用账号
      */
-    public function update_status() {
-        $id     = input('ids');
+    public function update_status()
+    {
+        $id = input('ids');
         $status = input('status', 2, 'intval');
 
         $staff = $this->model->where(['id' => $id])->find();
@@ -286,8 +293,9 @@ class Staff extends  Base {
     /**
      * 获取员工角色
      */
-    public function getstaffrole(){
-        $model=new StaffRole();
+    public function getstaffrole()
+    {
+        $model = new StaffRole();
         $result = $model->where([])->field('id,name')->select();
         $searchlist = [];
         foreach ($result as $key => $value) {

+ 46 - 33
application/admin/controller/qingdongams/parts/Parts.php

@@ -22,16 +22,18 @@ use think\Exception;
  * 备件管理
  * @icon fa fa-user
  */
-class Parts extends Base {
+class Parts extends Base
+{
     protected $relationSearch = true;
-    protected $searchFields   = 'id,name,num';
+    protected $searchFields = 'id,name,num,parts.odd_numbers,parts.create_staff.name';
     /**
      * @var \addons\qingdongams\model\Parts
      */
     protected $model = null;
 
 
-    public function _initialize() {
+    public function _initialize()
+    {
         parent::_initialize();
         $this->model = new \addons\qingdongams\model\Parts;
     }
@@ -40,7 +42,8 @@ class Parts extends Base {
     /**
      * 查看
      */
-    public function index() {
+    public function index()
+    {
         //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
         if ($this->request->isAjax()) {
@@ -62,13 +65,14 @@ class Parts extends Base {
     /**
      * 添加
      */
-    public function add() {
+    public function add()
+    {
         if ($this->request->isPost()) {
             $params = $this->request->post("row/a");
             if ($params) {
                 $params = $this->preExcludeFields($params);
 
-                $params['product_id']=implode(',',$params['product_id']);
+                $params['product_id'] = implode(',', $params['product_id']);
                 $result = false;
                 Db::startTrans();
                 try {
@@ -86,19 +90,20 @@ class Parts extends Base {
             }
             $this->error(__('Parameter %s can not be empty', ''));
         }
-        $product=Product::where([])->column('name','id');
+        $product = Product::where([])->column('name', 'id');
 
-        $this->view->assign('product',$product);
+        $this->view->assign('product', $product);
         return $this->view->fetch();
     }
 
     //修改
-    public function edit($ids = null) {
+    public function edit($ids = null)
+    {
         $map['id'] = $ids;
         if ($this->request->isAjax()) {
             $params = $this->request->post('row/a');
             $params = $this->preExcludeFields($params);
-            $params['product_id']=implode(',',$params['product_id']);
+            $params['product_id'] = implode(',', $params['product_id']);
             $result = false;
             Db::startTrans();
             try {
@@ -116,30 +121,32 @@ class Parts extends Base {
         }
         $data = $this->model->where($map)->find()->getData();
         $this->view->assign("row", $data);
-        $product=Product::where([])->column('name','id');
+        $product = Product::where([])->column('name', 'id');
 
-        $this->view->assign('product',$product);
+        $this->view->assign('product', $product);
         return $this->view->fetch();
     }
 
 
-    public function detail($ids=null){
-        $row=$this->model->where(['id'=>$ids])->find();
+    public function detail($ids = null)
+    {
+        $row = $this->model->where(['id' => $ids])->find();
 
-        $this->assign('row',$row);
-        $this->assign('ids',$ids);
+        $this->assign('row', $row);
+        $this->assign('ids', $ids);
         return $this->view->fetch();
     }
 
     /**
      * 删除
      */
-    public function del($ids = "") {
+    public function del($ids = "")
+    {
         if (!$this->request->isPost()) {
             $this->error(__("Invalid parameters"));
         }
-        $ids                 = $ids ? $ids : $this->request->post("ids");
-        $row                 = $this->model->get($ids);
+        $ids = $ids ? $ids : $this->request->post("ids");
+        $row = $this->model->get($ids);
         $this->modelValidate = true;
         if (!$row) {
             $this->error(__('No Results were found'));
@@ -151,7 +158,8 @@ class Parts extends Base {
     /**
      * 出库
      */
-    public function export($ids = null) {
+    public function export($ids = null)
+    {
         if ($this->request->isPost()) {
             $params = $this->request->post("row/a");
             if ($params) {
@@ -189,10 +197,12 @@ class Parts extends Base {
         $this->assign('number', getItemNumber('export'));
         return $this->view->fetch();
     }
+
     /**
      * 入库
      */
-    public function import($ids = null) {
+    public function import($ids = null)
+    {
         if ($this->request->isPost()) {
             $params = $this->request->post("row/a");
             if ($params) {
@@ -233,11 +243,12 @@ class Parts extends Base {
     /**
      * 审批记录
      */
-    public function logs() {
+    public function logs()
+    {
+        $this->relationSearch = true;
         $this->request->filter(['strip_tags']);
 
         if ($this->request->isAjax()) {
-            $this->relationSearch = true;
             list($where, $sort, $order, $offset, $limit) = $this->buildparams(null, null);
 
             $filter = $this->request->get("filter", '');
@@ -253,21 +264,23 @@ class Parts extends Base {
                 $wheres['createtime'] = ['between', [strtotime($time[0]), strtotime($time[1])]];
             }
 
-            $ids=input('ids');
+            $ids = input('ids');
             if ($ids) {
-                $reloads = PartsStockReload::where(['create_staff_id'=>$this->_staff->id])->column('id');
-                $wheres['relation_id'] =['in',$reloads];
+                $reloads = PartsStockReload::where(['create_staff_id' => $this->_staff->id])->column('id');
+                $wheres['relation_id'] = ['in', $reloads];
             }
             $wheres['relation_type'] = 'parts';
-            $list   =  (new ExamineRecord())
+            $model = new ExamineRecord();
+            $list = $model
+                ->with([
+                    'checkStaff',
+                    'parts' => ['createStaff']]
+                )
 //                ->where($where)
                 ->where($wheres)
-                ->with([
-                'checkStaff',
-                'parts' => ['createStaff']])
                 ->order('id', $order)
                 ->paginate($limit);
-            $row    = $list->items();
+            $row = $list->items();
 
             $result = array("total" => $list->total(), "rows" => $row);
 
@@ -306,7 +319,7 @@ class Parts extends Base {
 
     public function log_info($ids = null)
     {
-        $types = input('types','parts');
+        $types = input('types', 'parts');
         $row = PartsStockReload::where(['id' => $ids])->find();
         if ($row['check_status'] == 0 || $row['check_status'] == 1) {
             $row['is_examine'] = ExamineRecord::isExaminse(ExamineRecord::PARTS_TYPE, $ids);
@@ -336,7 +349,7 @@ class Parts extends Base {
                     break;
             }
         }
-        Message::setRead($types,$ids,$this->_staff->id);
+        Message::setRead($types, $ids, $this->_staff->id);
         $this->assign('examin', $examin);
         return $this->view->fetch();
     }

+ 205 - 192
application/admin/controller/qingdongams/workorder/Workorder.php

@@ -16,6 +16,7 @@ use addons\qingdongams\model\Flow;
 use addons\qingdongams\model\Message;
 use addons\qingdongams\model\OperationLog;
 use addons\qingdongams\model\Product;
+use addons\qingdongams\model\StaffRole;
 use addons\qingdongams\model\StaffSignIn;
 use addons\qingdongams\model\WorkorderLogistics;
 use addons\qingdongams\model\WorkorderProgress;
@@ -31,6 +32,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Font;
+
 /**
  * 工单管理
  * @icon fa fa-user
@@ -38,7 +40,7 @@ use PhpOffice\PhpSpreadsheet\Style\Font;
 class Workorder extends Base
 {
     protected $relationSearch = true;
-    protected $searchFields   = 'id,workorder_number,title';
+    protected $searchFields = 'id,workorder_number,title';
     /**
      * @var \addons\qingdongams\model\Workorder
      */
@@ -54,55 +56,56 @@ class Workorder extends Base
 
     }
 
-    public function excel(){
-              // 创建Excel对象
+    public function excel()
+    {
+        // 创建Excel对象
         $spreadsheet = new Spreadsheet();
         $sheet = $spreadsheet->getActiveSheet();
-        $map=[];
-        $wheres=[];
-        $createtime = input('createtime','');
-        if($createtime && $createtime !='null '){
-            $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
-            $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
-            $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
-        }
-        $owner_staff_id = input('owner_staff_id','');
-          
+        $map = [];
+        $wheres = [];
+        $createtime = input('createtime', '');
+        if ($createtime && $createtime != 'null ') {
+            $start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
+            $end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
+            $wheres['createtime'] = array('between', array(strtotime($start), strtotime($end)));
+        }
+        $owner_staff_id = input('owner_staff_id', '');
+
         // dump($owner_staff_id);
-        if($owner_staff_id>0){
+        if ($owner_staff_id > 0) {
             $map['owner_staff_id'] = $owner_staff_id;
         }
         $whereStaff = function ($query) {
             $query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
                 ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
         };
-     
+
         $list = $this->model->where($map)->where($wheres)->where($whereStaff)->with(['customer', 'contacts'])->order('id desc')->select();
 
         // 设置列宽
-            $sheet->getColumnDimension('A')->setWidth(15);
-            $sheet->getColumnDimension('B')->setWidth(20);
-            $sheet->getColumnDimension('C')->setWidth(25);
-            $sheet->getColumnDimension('D')->setWidth(25);
-            $sheet->getColumnDimension('E')->setWidth(25);
-            $sheet->getColumnDimension('F')->setWidth(25);
-            $sheet->getColumnDimension('G')->setWidth(25);
-
-            // 设置标题栏样式
-            $titleStyle = $sheet->getStyle('A1:G1');
-            $titleStyle->getFont()->setBold(true);
-            $titleStyle->getFont()->setSize(14);
-            $titleStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
+        $sheet->getColumnDimension('A')->setWidth(15);
+        $sheet->getColumnDimension('B')->setWidth(20);
+        $sheet->getColumnDimension('C')->setWidth(25);
+        $sheet->getColumnDimension('D')->setWidth(25);
+        $sheet->getColumnDimension('E')->setWidth(25);
+        $sheet->getColumnDimension('F')->setWidth(25);
+        $sheet->getColumnDimension('G')->setWidth(25);
+
+        // 设置标题栏样式
+        $titleStyle = $sheet->getStyle('A1:G1');
+        $titleStyle->getFont()->setBold(true);
+        $titleStyle->getFont()->setSize(14);
+        $titleStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
         // 设置标题栏
-         $sheet->setCellValue('A1', '工单编号');
-         $sheet->setCellValue('B1', '工单标题');
-         $sheet->setCellValue('C1', '工单类型');
-         $sheet->setCellValue('D1', '工单状态');
-         $sheet->setCellValue('E1', '客户名称');
-         $sheet->setCellValue('F1', '联系人');
-         $sheet->setCellValue('G1', '创建时间');
+        $sheet->setCellValue('A1', '工单编号');
+        $sheet->setCellValue('B1', '工单标题');
+        $sheet->setCellValue('C1', '工单类型');
+        $sheet->setCellValue('D1', '工单状态');
+        $sheet->setCellValue('E1', '客户名称');
+        $sheet->setCellValue('F1', '联系人');
+        $sheet->setCellValue('G1', '创建时间');
         //  $sheet->setCellValue('H1', '负责人');
-           // 填充数据
+        // 填充数据
         $row = 2;
         foreach ($list as $item) {
             $sheet->setCellValue('A' . $row, $item['workorder_number']);
@@ -110,25 +113,25 @@ class Workorder extends Base
             $sheet->setCellValue('C' . $row, $item['workorder_type']);
             $sheet->setCellValue('D' . $row, $item['schedule']);
             $sheet->setCellValue('E' . $row, $item['customer']['name'] ?? '-');
-            $sheet->setCellValue('F' . $row, !empty($item['contacts'])? $item['contacts']['name']:'');
+            $sheet->setCellValue('F' . $row, !empty($item['contacts']) ? $item['contacts']['name'] : '');
             $sheet->setCellValue('G' . $row, $item['createtime']);
             // $sheet->setCellValue('H' . $row, $item['age']);
             $row++;
         }
-            // 设置保存路径及文件名
-            $filename = 'data_export.xlsx';
-            $filePath = './' . $filename;
-    
-            // 保存Excel文件
-            $writer = new Xlsx($spreadsheet);
-            $writer->save($filePath);
-    
-            // 下载Excel文件
-            header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
-            header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
-            header('Cache-Control: max-age=0');
-            $writer->save('php://output');
-            exit;
+        // 设置保存路径及文件名
+        $filename = 'data_export.xlsx';
+        $filePath = './' . $filename;
+
+        // 保存Excel文件
+        $writer = new Xlsx($spreadsheet);
+        $writer->save($filePath);
+
+        // 下载Excel文件
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
+        header('Cache-Control: max-age=0');
+        $writer->save('php://output');
+        exit;
     }
 
     /**
@@ -138,33 +141,33 @@ class Workorder extends Base
     {
         //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
-        $need = input('need','','trim');
+        $need = input('need', '', 'trim');
         if ($this->request->isAjax()) {
             //如果发送的来源是Selectpage,则转发到Selectpage
             if ($this->request->request('keyField')) {
                 return $this->selectpage();
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-            $createtime = input('createtime','');
+            $createtime = input('createtime', '');
             $wheres = [];
-            if($need && $need == 'workorder'){
+            if ($need && $need == 'workorder') {
                 $wheres['status'] = 1;
             }
-            if($createtime && $createtime != 'null'){
-                $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
-                $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
-                $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
+            if ($createtime && $createtime != 'null') {
+                $start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
+                $end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
+                $wheres['createtime'] = array('between', array(strtotime($start), strtotime($end)));
             }
             $map = [];
-            $status_index = input('status_index','');
+            $status_index = input('status_index', '');
             // dump($status_index);
-            if($status_index>0){
+            if ($status_index > 0) {
                 $map['status'] = $status_index;
             }
-            $owner_staff_id = input('owner_staff_id','');
-          
+            $owner_staff_id = input('owner_staff_id', '');
+
             // dump($owner_staff_id);
-            if($owner_staff_id>0){
+            if ($owner_staff_id > 0) {
                 $map['owner_staff_id'] = $owner_staff_id;
             }
             $whereStaff = function ($query) {
@@ -172,7 +175,7 @@ class Workorder extends Base
                     ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
             };
             // dump($map);
-            $list = $this->model->with(['customer', 'contacts','ownerStaff'])->where($where)->where($map)->where($wheres)->where($whereStaff)->order('id desc')->paginate($limit);
+            $list = $this->model->with(['customer', 'contacts', 'ownerStaff'])->where($where)->where($map)->where($wheres)->where($whereStaff)->order('id desc')->paginate($limit);
 
             foreach ($list as $value) {
                 if ($value['owner_staff']) {
@@ -198,33 +201,33 @@ class Workorder extends Base
     {
         //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
-        $need = input('need','','trim');
+        $need = input('need', '', 'trim');
         if ($this->request->isAjax()) {
             //如果发送的来源是Selectpage,则转发到Selectpage
             if ($this->request->request('keyField')) {
                 return $this->selectpage();
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-            $createtime = input('createtime','');
+            $createtime = input('createtime', '');
             $wheres = [];
-            if($need && $need == 'workorder'){
+            if ($need && $need == 'workorder') {
                 $wheres['status'] = 1;
             }
-            if($createtime && $createtime !='null '){
-                $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
-                $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
-                $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
+            if ($createtime && $createtime != 'null ') {
+                $start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
+                $end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
+                $wheres['createtime'] = array('between', array(strtotime($start), strtotime($end)));
             }
             $map = [];
-            $status_index = input('status_index','');
+            $status_index = input('status_index', '');
             // dump($status_index);
-            if($status_index>0){
+            if ($status_index > 0) {
                 $map['status'] = $status_index;
             }
-            $owner_staff_id = input('owner_staff_id','');
-          
+            $owner_staff_id = input('owner_staff_id', '');
+
             // dump($owner_staff_id);
-            if($owner_staff_id>0){
+            if ($owner_staff_id > 0) {
                 $map['owner_staff_id'] = $owner_staff_id;
             }
             $whereStaff = function ($query) {
@@ -232,7 +235,7 @@ class Workorder extends Base
                     ->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
             };
             // dump($map);
-            $list = $this->model->where($where)->where($map)->where($wheres)->where($whereStaff)->with(['customer', 'contacts','ownerStaff'])->order('id desc')->paginate(5);
+            $list = $this->model->where($where)->where($map)->where($wheres)->where($whereStaff)->with(['customer', 'contacts', 'ownerStaff'])->order('id desc')->paginate(5);
             $result = array("total" => $list->total(), "rows" => $list->items());
 
             return json($result);
@@ -248,20 +251,20 @@ class Workorder extends Base
 
         if ($this->request->isAjax()) {
             $params = $this->request->post('row/a');
-            if(isset($params['product'])){
-                if (!$params['product'] || $params['product'] =='[]') {
+            if (isset($params['product'])) {
+                if (!$params['product'] || $params['product'] == '[]') {
                     $this->error('请选择产品');
                 }
-            }else if(isset($params['customer_product_id'])){
-                if (!$params['customer_product_id'] || $params['customer_product_id'] =='[]') {
+            } else if (isset($params['customer_product_id'])) {
+                if (!$params['customer_product_id'] || $params['customer_product_id'] == '[]') {
                     $this->error('请选择产品');
                 }
-            }else if(isset($params['product_part'])){
-                if (!$params['product_part'] || $params['product_part'] =='[]') {
+            } else if (isset($params['product_part'])) {
+                if (!$params['product_part'] || $params['product_part'] == '[]') {
                     $this->error('请选择产品');
                 }
-            }else if(isset($params['device_ids'])){
-                if (!$params['device_ids'] || $params['device_ids'] =='[]') {
+            } else if (isset($params['device_ids'])) {
+                if (!$params['device_ids'] || $params['device_ids'] == '[]') {
                     $this->error('请选择设备');
                 }
             }
@@ -276,45 +279,45 @@ class Workorder extends Base
                 $this->error('工单编号已存在');
             }
 //            try {
-                if (isset($params['files'])) {
-                    $params['files'] = File::getId($params['files']);
-                }
-                if (isset($params['file_ids'])) {
-                    $params['file_ids'] = File::getId($params['file_ids']);
-                }
-                if (isset($params['product'])) {
-                    $params['product'] = json_decode($params['product'], true);
-                }
-                if (isset($params['parts'])) {
-                    $params['parts'] = json_decode($params['parts'], true);
-                }
-                if (isset($params['customer_product_id'])) {
-                    $params['customer_product_id'] = json_decode($params['customer_product_id'], true);
-                    $customer_product_id = [];
-                    foreach ($params['customer_product_id'] as $v) {
-                        $customer_product_id[] = $v['customer_product_id'];
-                    }
-                    $params['customer_product_id'] = implode(',', $customer_product_id);
+            if (isset($params['files'])) {
+                $params['files'] = File::getId($params['files']);
+            }
+            if (isset($params['file_ids'])) {
+                $params['file_ids'] = File::getId($params['file_ids']);
+            }
+            if (isset($params['product'])) {
+                $params['product'] = json_decode($params['product'], true);
+            }
+            if (isset($params['parts'])) {
+                $params['parts'] = json_decode($params['parts'], true);
+            }
+            if (isset($params['customer_product_id'])) {
+                $params['customer_product_id'] = json_decode($params['customer_product_id'], true);
+                $customer_product_id = [];
+                foreach ($params['customer_product_id'] as $v) {
+                    $customer_product_id[] = $v['customer_product_id'];
                 }
-                if (isset($params['product_part'])) {
-                    $params['product_part'] = json_decode($params['product_part'], true);
-                    $customer_product_id = [];
-                    foreach ($params['product_part'] as $v){
-                        $customer_product_id[] = $v['customer_product_id'];
-                    }
-                    $params['customer_product_id'] = implode(',', $customer_product_id);
+                $params['customer_product_id'] = implode(',', $customer_product_id);
+            }
+            if (isset($params['product_part'])) {
+                $params['product_part'] = json_decode($params['product_part'], true);
+                $customer_product_id = [];
+                foreach ($params['product_part'] as $v) {
+                    $customer_product_id[] = $v['customer_product_id'];
                 }
+                $params['customer_product_id'] = implode(',', $customer_product_id);
+            }
 
-                if (isset($params['device_ids'])) {
-                    $params['device_ids'] = json_decode($params['device_ids'], true);
-                    $customer_product_id = [];
-                    foreach ($params['device_ids'] as $v){
-                        $customer_product_id[] = $v['customer_product_id'];
-                    }
-                    $params['device_ids'] = implode(',', $customer_product_id);
+            if (isset($params['device_ids'])) {
+                $params['device_ids'] = json_decode($params['device_ids'], true);
+                $customer_product_id = [];
+                foreach ($params['device_ids'] as $v) {
+                    $customer_product_id[] = $v['customer_product_id'];
                 }
-                $result = WorkorderModel::createWorkorder($params);
-                Db::commit();
+                $params['device_ids'] = implode(',', $customer_product_id);
+            }
+            $result = WorkorderModel::createWorkorder($params);
+            Db::commit();
 //            } catch (Exception $e) {
 //                Db::rollback();
 //                $this->error($e->getMessage());
@@ -354,21 +357,21 @@ class Workorder extends Base
     }
 
     //编辑
-    public function edit($ids=null)
+    public function edit($ids = null)
     {
 
         if ($this->request->isAjax()) {
             $params = $this->request->post('row/a');
-            if(isset($params['product'])){
-                if (!$params['product'] || $params['product'] =='[]') {
+            if (isset($params['product'])) {
+                if (!$params['product'] || $params['product'] == '[]') {
                     $this->error('请选择产品');
                 }
-            }else if(isset($params['customer_product_id'])){
-                if (!$params['customer_product_id'] || $params['customer_product_id'] =='[]') {
+            } else if (isset($params['customer_product_id'])) {
+                if (!$params['customer_product_id'] || $params['customer_product_id'] == '[]') {
                     $this->error('请选择产品');
                 }
-            }else if(isset($params['product_part'])){
-                if (!$params['product_part'] || $params['product_part'] =='[]') {
+            } else if (isset($params['product_part'])) {
+                if (!$params['product_part'] || $params['product_part'] == '[]') {
                     $this->error('请选择产品');
                 }
             }
@@ -418,29 +421,29 @@ class Workorder extends Base
             $this->error('工单不存在');
         }
         $workorder = $workorder->toArray();
-        $workorder['customer_product_id']=explode(',',$workorder['customer_product_id']);
-        $customer_product=[];
-        foreach ($workorder['customer_product_id'] as $pid){
-            $cp=CustomerProduct::where(['id'=>$pid])->with(['product'])->find();
-            $cp['customer_product_id']=$pid;
-            $customer_product[]=$cp;
-        }
-        $workorder['customer_product']= $customer_product;
-        $files=[];
+        $workorder['customer_product_id'] = explode(',', $workorder['customer_product_id']);
+        $customer_product = [];
+        foreach ($workorder['customer_product_id'] as $pid) {
+            $cp = CustomerProduct::where(['id' => $pid])->with(['product'])->find();
+            $cp['customer_product_id'] = $pid;
+            $customer_product[] = $cp;
+        }
+        $workorder['customer_product'] = $customer_product;
+        $files = [];
         foreach ($workorder['file'] as $f) {
             $files[] = $f['file_path'];
         }
-        if($workorder['product_part']){
-            $product_part=[];
-            foreach ($workorder['product_part'] as $v){
+        if ($workorder['product_part']) {
+            $product_part = [];
+            foreach ($workorder['product_part'] as $v) {
 
-                $v['customer_product_id']=$v['id'];
-                $product_part[]=$v;
+                $v['customer_product_id'] = $v['id'];
+                $product_part[] = $v;
             }
-            $workorder['product_part']=$product_part;
+            $workorder['product_part'] = $product_part;
         }
-        $workorder['files']=implode(',',$files);
-        $workorder_type=$workorder['workorder_type'];
+        $workorder['files'] = implode(',', $files);
+        $workorder_type = $workorder['workorder_type'];
         $this->assign('row', $workorder);
         $this->assign('workorder_type', $workorder_type);
         $this->assign('staffs', Staff::getList());
@@ -485,10 +488,10 @@ class Workorder extends Base
     //工单详情
     public function detail($ids = null)
     {
-        $types = input('types','workorder');
+        $types = input('types', 'workorder');
         // 基本信息
         $workorder = WorkorderModel::where(['id' => $ids])->with(['createStaff',
-            'contacts', 'customer', 'ownerStaff', 'file', 'getevent', 'visit','createPerson'])->find();
+            'contacts', 'customer', 'ownerStaff', 'file', 'getevent', 'visit', 'createPerson'])->find();
         if (empty($workorder)) {
             $this->error('工单不存在');
         }
@@ -496,14 +499,19 @@ class Workorder extends Base
         if (empty($workorder)) {
             $this->error('信息不存在');
         }
-        if (!in_array($this->_staff->id, explode(',', $workorder['show_staff_id']))
-            && !in_array($workorder['owner_staff_id'], Staff::getLowerStaffId()) && $this->_staff->id != $workorder['create_staff_id']) {
-            $this->error('权限不足,无法查看工单','',403);
+        if ($this->_staff->id != 15) {
+            $role_type = StaffRole::where(['id' => $this->_staff->role])->value('role_type');
+            if ($role_type != 6) {
+                if (!in_array($this->_staff->id, explode(',', $workorder['show_staff_id']))
+                    && !in_array($workorder['owner_staff_id'], Staff::getLowerStaffId()) && $this->_staff->id != $workorder['create_staff_id']) {
+                    $this->error('权限不足,无法查看工单', '', 403);
+                }
+            }
         }
 
         //设备列表
-        if($workorder['device_ids']){
-            $workorder['device_list']=$this->Equipmentdevice->where(array('id'=>array('in',$workorder['device_ids'])))->select();
+        if ($workorder['device_ids']) {
+            $workorder['device_list'] = $this->Equipmentdevice->where(array('id' => array('in', $workorder['device_ids'])))->select();
         }
 
 
@@ -515,26 +523,26 @@ class Workorder extends Base
         }
         if (empty($workorder['contacts'])) {
             $workorder['contacts'] = Contacts::where(['customer_id' => $workorder['customer_id']])->order('is_major desc')->field('id,customer_id,name,mobile,mobilecode,region')->find();
-            
+
         }
         // dump($workorder);
         // if (empty($workorder['kehuinfo'])) {
         //  $workorder['kehuinfo'] = Contacts::where(['id' => $workorder['customer_id']])->order('is_major desc')->field('id,customer_id,name,mobile,mobilecode,region')->find();
 
         // }
-        
+
         if ($workorder['aftermarket_type_ids']) {
             $names = AftermarketType::where(['id' => ['in', explode(',', $workorder['aftermarket_type_ids'])]])->column('name');
             $workorder['aftermarket_type_ids'] = implode(',', $names);
         }
-        
-        
+
+
         $workorder['is_revoke'] = 0;//是否可以撤销
         $workorder['is_operation'] = 0;//是否可以操作
         $workorder['is_operation_visit'] = 0;//操作回访
         $workorder['is_financial'] = 0;//是否财务审核
         $workorder['is_leader'] = 0;//是否可以录入费用
-        if ($workorder['create_staff_id'] == $this->_staff->id || in_array($workorder['create_staff_id'], Staff::getLowerStaffId()) ) {
+        if ($workorder['create_staff_id'] == $this->_staff->id || in_array($workorder['create_staff_id'], Staff::getLowerStaffId())) {
             //是否可以撤销
             $workorder['is_revoke'] = 1;
         }
@@ -553,7 +561,7 @@ class Workorder extends Base
         //操作回访
         $workorder['is_operation_visit'] = 1;
 
-        if ($workorder['status'] == 3 && $workorder['is_pay'] == 1 && $workorder['is_financial_audit'] == 0 ) {
+        if ($workorder['status'] == 3 && $workorder['is_pay'] == 1 && $workorder['is_financial_audit'] == 0) {
             //是否财务审核
             $workorder['is_financial'] = 1;
         }
@@ -614,7 +622,7 @@ class Workorder extends Base
         $model = new WorkorderProgress();
         $staffsProgress = $model->where(['workorder_id' => $ids])->with(['createStaff'])->select();
 
-        $this->assign('staffsProgress',$staffsProgress);
+        $this->assign('staffsProgress', $staffsProgress);
 
         $where = [];
         $where['relation_type'] = 'workorder';
@@ -628,8 +636,8 @@ class Workorder extends Base
         $assist_task = collection($assist_task)->toArray();
 
 
-        $this->assign('examine_record',ExamineRecord::getList(ExamineRecord::WORKORDER_TYPE,$ids));
-        $this->assign('flow',Flow::getstepdetail(Flow::WORKORDER_STATUS, $ids));
+        $this->assign('examine_record', ExamineRecord::getList(ExamineRecord::WORKORDER_TYPE, $ids));
+        $this->assign('flow', Flow::getstepdetail(Flow::WORKORDER_STATUS, $ids));
 
         $this->assign('assist_task', $assist_task);
         $this->assign('logistics', $logistics);
@@ -645,9 +653,10 @@ class Workorder extends Base
     }
 
     //获取费用
-    public function get_consume($ids = null) {
+    public function get_consume($ids = null)
+    {
         list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-        $list   = Consume::where([
+        $list = Consume::where([
             'relation_type' => 'workorder',
             'relation_id' => $ids,
         ])->with(['staff'])->order('id desc')->paginate($limit);
@@ -675,7 +684,7 @@ class Workorder extends Base
 
             Db::startTrans();
             try {
-                WorkorderModel::transferWorkorder($id,$dep_id, $staff_id, $desc);
+                WorkorderModel::transferWorkorder($id, $dep_id, $staff_id, $desc);
                 Db::commit();
             } catch (Exception $e) {
                 Db::rollback();
@@ -764,12 +773,12 @@ class Workorder extends Base
     }
 
     //接受工单
-    public function accept_order($ids=null)
+    public function accept_order($ids = null)
     {
         $params = $this->request->post();
-        if(!$ids){
+        if (!$ids) {
             $params['id'] = isset($params['id']) ? $params['id'] : '';
-        }else{
+        } else {
             $params['id'] = $ids;
         }
         if (empty($params['id'])) {
@@ -835,7 +844,7 @@ class Workorder extends Base
         if (empty($row)) {
             $this->error('工单不存在');
         }
-        $row['customer_product']='';
+        $row['customer_product'] = '';
         if ($row['customer_product_id']) {
             $customer_product_ids = explode(',', $row['customer_product_id']);
             $row['customer_product'] = CustomerProduct::where(['id' => ['in', $customer_product_ids]])->with(['product'])->select();
@@ -1052,8 +1061,10 @@ class Workorder extends Base
         $this->view->assign('row', $row);
         return $this->view->fetch();
     }
+
     //电话工单完成
-    public function complete_mobile($ids=null){
+    public function complete_mobile($ids = null)
+    {
 
         if ($this->request->isAjax()) {
             $params = $this->request->post('row/a');
@@ -1065,10 +1076,10 @@ class Workorder extends Base
             }
             Db::startTrans();
             try {
-                if($params['is_part'] == 1){
-                    $params['use_parts']=[];
-                }else{
-                    $params['use_parts']=json_decode($params['use_parts'],true);
+                if ($params['is_part'] == 1) {
+                    $params['use_parts'] = [];
+                } else {
+                    $params['use_parts'] = json_decode($params['use_parts'], true);
                 }
                 WorkorderModel::completeWorkorder($id, $desc, $params);
                 //协助任务完成
@@ -1089,6 +1100,7 @@ class Workorder extends Base
         $this->view->assign('row', $row);
         return $this->view->fetch();
     }
+
     //工单失败
     public function fail_workorder($ids = null)
     {
@@ -1191,16 +1203,16 @@ class Workorder extends Base
         if ($this->request->isAjax()) {
             $params = $this->request->post('row/a');
             $relation_type = Comment::ASSIST_EVENT_TYPE;
-            if(empty($params['id'])){
+            if (empty($params['id'])) {
                 $this->error('评论ID不能为空');
             }
-            if(empty($params['content'])){
+            if (empty($params['content'])) {
                 $this->error('评论内容不能为空');
             }
             $relation_id = $params['id'];
             $content = $params['content'];
-            $files = $params['file_ids']??'';
-            $files=File::getId($files);
+            $files = $params['file_ids'] ?? '';
+            $files = File::getId($files);
             $staff = Staff::info();
             Comment::addComment($content, $files, $relation_id, $relation_type, $staff->id);
             $this->success('评论成功');
@@ -1306,9 +1318,9 @@ class Workorder extends Base
 
         if ($this->request->isAjax()) {
             $params = $this->request->post('row/a');
-            $params['workorder_id']=$ids;
-            $result=WorkorderModel::addProgress($params);
-            if($result){
+            $params['workorder_id'] = $ids;
+            $result = WorkorderModel::addProgress($params);
+            if ($result) {
                 $this->success('操作成功');
             }
             $this->error('操作失败');
@@ -1475,13 +1487,13 @@ class Workorder extends Base
         $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids])->with(['staff'])->paginate($limit);
         $total = $list->total();
         $stfflist = $list->toArray()['data'];
-        foreach ($stfflist as $k => $value){
-            if ($value['roles'] == 1){
+        foreach ($stfflist as $k => $value) {
+            if ($value['roles'] == 1) {
                 $stfflist[$k]['is_edit'] = '负责人';
-            }else{
-                $stfflist[$k]['is_edit'] = $value['is_edit'] == 1?'读写':'只读';
+            } else {
+                $stfflist[$k]['is_edit'] = $value['is_edit'] == 1 ? '读写' : '只读';
             }
-            $stfflist[$k]['roles'] = $value['roles'] == 1?'负责人':'团队成员';
+            $stfflist[$k]['roles'] = $value['roles'] == 1 ? '负责人' : '团队成员';
         }
         $result = array("total" => $total, "rows" => $stfflist);
 
@@ -1489,7 +1501,8 @@ class Workorder extends Base
     }
 
 
-    public function set_team($ids = null){
+    public function set_team($ids = null)
+    {
         if ($this->request->isPost()) {
             $params = $this->request->post("row/a");
             if ($params) {
@@ -1501,15 +1514,15 @@ class Workorder extends Base
                 if (empty($model)) {
                     $this->error('客户不存在');
                 }
-                foreach ($staff as $k=>$v) {
+                foreach ($staff as $k => $v) {
                     if ($v['roles'] == 1) {//负责人
                         $find = JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE,
                             'relation_id' => $id,
                             'roles' => 1
                         ])->find();
-                        if($v['id'] != $find['staff_id']){
+                        if ($v['id'] != $find['staff_id']) {
                             \addons\qingdongams\model\Workorder::transfer($id, $v['id']);
-                            JointFollow::where(['id'=>$find['id']])->update(['staff_id'=>$v['id']]);
+                            JointFollow::where(['id' => $find['id']])->update(['staff_id' => $v['id']]);
                             $model = \addons\qingdongams\model\Workorder::get($id);
                         }
                         unset($staff[$k]);
@@ -1529,7 +1542,7 @@ class Workorder extends Base
                     'roles' => 1
                 ])->find();
                 foreach ($staff as $v) {
-                    if($v['id'] != $find['staff_id']) {
+                    if ($v['id'] != $find['staff_id']) {
                         $add[] = [
                             'relation_type' => $jointFollow::WORKORDER_TYPE,
                             'relation_id' => $id,
@@ -1546,12 +1559,12 @@ class Workorder extends Base
             }
             $this->error(__('Parameter %s can not be empty', ''));
         }
-        $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids,'roles' => 2])->with(['staff'])->select();
+        $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids, 'roles' => 2])->with(['staff'])->select();
         $staffs = Staff::getList();
-        $principal = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids,'roles' => 1])->with(['staff'])->find();
+        $principal = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids, 'roles' => 1])->with(['staff'])->find();
         $this->assign('staffs', $staffs);
         $this->assign('principal', $principal);
-        $this->assign('id',$ids);
+        $this->assign('id', $ids);
         $this->assign('list', $list);
         return $this->view->fetch();
     }

+ 1 - 1
application/admin/view/qingdongams/customer/equipmentdevice/index.html

@@ -22,7 +22,7 @@
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
                         <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('qingdongams/customer/equipmentdevice/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
-                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qingdongams/customer/equipmentdevice/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+<!--                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qingdongams/customer/equipmentdevice/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
                         <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('qingdongams/customer/equipmentdevice/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
                         
 

+ 3 - 2
application/admin/view/qingdongams/customer/equipmenttype/add.html

@@ -13,7 +13,7 @@
             <input id="c-name" class="form-control" name="row[name]" type="text">
         </div>
     </div>
-    
+
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">型号:</label>
         <div class="col-xs-12 col-sm-8">
@@ -41,7 +41,8 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">出厂时间:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-name" class="form-control" name="row[shijian]" type="text">
+            <input id="c-shijian" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss"
+                   data-use-current="true" name="row[shijian]" type="text" value="{:date('Y-m-d H:i:s')}">
         </div>
     </div>
     <div class="form-group">

+ 1 - 1
application/admin/view/qingdongams/customer/equipmenttype/edit.html

@@ -40,7 +40,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">出厂时间:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-name" class="form-control" name="row[shijian]" type="text" value="{$row.shijian|htmlentities}">
+            <input id="c-shijian" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[shijian]" type="text" value="{:$row.shijian?datetime($row.w_time):''}">
         </div>
     </div>
     <div class="form-group">

+ 1 - 1
application/admin/view/qingdongams/customer/equipmenttype/index.html

@@ -8,7 +8,7 @@
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
                         <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('qingdongams/customer/equipmenttype/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
-                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qingdongams/customer/equipmenttype/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+<!--                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('qingdongams/customer/equipmenttype/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
                         <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('qingdongams/customer/equipmenttype/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
                         
 

+ 2 - 2
application/admin/view/qingdongams/customer/record/add.html

@@ -51,7 +51,7 @@
 
 		</div>
 		{/eq}
-	<!-- <div class="form-group">
+	<div class="form-group">
 		<label class="control-label col-xs-12 col-sm-2">客户状态:</label>
 		<div class="form-group col-sm-8">
 
@@ -62,7 +62,7 @@
 				{/foreach}
 			</select>
 		</div>
-	</div> -->
+	</div>
 	<div class="form-group">
 		<label class="control-label col-xs-12 col-sm-2">提醒谁看:</label>
 		<div class="form-group col-sm-8">

+ 44 - 29
application/admin/view/qingdongams/department/staff/add.html

@@ -1,88 +1,103 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
     {:token()}
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>姓名:</label>
+        <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>姓名:</label>
         <div class="col-xs-12 col-sm-8">
-            <input  data-rule="required" class="form-control" name="row[name]" type="text"  >
+            <input data-rule="required" class="form-control" name="row[name]" type="text">
         </div>
     </div>
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2">员工编号:</label>
+        <label class="control-label col-xs-12 col-sm-2">员工编号:</label>
         <div class="col-xs-12 col-sm-8">
-            <input  class="form-control" name="row[num]" type="text"  >
+            <input class="form-control" name="row[num]" type="text">
         </div>
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>角色:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}
+            {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker',
+            'data-rule'=>'required'])}
         </div>
-        <small style="line-height:34px;" >
+        <small style="line-height:34px;">
             <span style="padding:0px;"></span>
-            <a href="javascript:;" id="myPopover"   data-toggle="popover" data-placement="right" data-trigger="hover" data-template='<div class="popover" role="tooltip">
+            <a href="javascript:;" id="myPopover" data-toggle="popover" data-placement="right" data-trigger="hover"
+               data-template='<div class="popover" role="tooltip">
     <div class="arrow"></div>
     <h3 class="popover-title" style="width:200px;"></h3>
-</div>'  data-original-title="该部门在【员工管理】—【组织架构】处进行配置"><i class="fa fa-question-circle" style="font-size:16px;"></i></a>
+</div>' data-original-title="该部门在【员工管理】—【组织架构】处进行配置"><i class="fa fa-question-circle"
+                                                                         style="font-size:16px;"></i></a>
         </small>
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>部门:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('row[role]', $roles, null, ['class'=>'form-control selectpicker', 'data-rule'=>'required', 'data-live-search'=>'true'])}
+            {:build_select('row[role]', $roles, null, ['class'=>'form-control selectpicker', 'data-rule'=>'required',
+            'data-live-search'=>'true'])}
         </div>
-        <small style="line-height:34px;" >
+        <small style="line-height:34px;">
             <span style="padding:0px;"></span>
-            <a href="javascript:;" id="roles"   data-toggle="popover" data-placement="right" data-trigger="hover" data-template='<div class="popover" role="tooltip">
+            <a href="javascript:;" id="roles" data-toggle="popover" data-placement="right" data-trigger="hover"
+               data-template='<div class="popover" role="tooltip">
     <div class="arrow"></div>
     <h3 class="popover-title" style="width:200px;"></h3>
-</div>'  data-original-title="该角色在【员工管理】—【角色管理】处进行配置此员工数据权限"><i class="fa fa-question-circle" style="font-size:16px;"></i></a>
+</div>' data-original-title="该角色在【员工管理】—【角色管理】处进行配置此员工数据权限"><i class="fa fa-question-circle"
+                                                                                       style="font-size:16px;"></i></a>
         </small>
     </div>
 
     <div class="form-group">
-		<label class="control-label col-xs-12 col-sm-2">直属上级:</label>
-		<div class="col-xs-12 col-sm-8">
-			{:build_select('row[parent_id]', $staffs, null, ['class'=>'form-control selectpicker', 'data-live-search'=>'true'])}
-		</div>
+        <label class="control-label col-xs-12 col-sm-2">直属上级:</label>
+        <div class="col-xs-12 col-sm-8">
+            {:build_select('row[parent_id]', $staffs, null, ['class'=>'form-control selectpicker',
+            'data-live-search'=>'true'])}
+        </div>
     </div>
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>邮箱:</label>
+        <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>邮箱:</label>
         <div class="col-xs-12 col-sm-8">
-            <input class="form-control" name="row[email]" type="text" placeholder="已经存在的邮箱号不可填写" data-rule="required">
+            <input class="form-control" name="row[email]" type="text" placeholder="已经存在的邮箱号不可填写"
+                   data-rule="required">
         </div>
     </div>
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>用户名:</label>
+        <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>用户名:</label>
         <div class="col-xs-12 col-sm-8">
-            <input data-rule="required" class="form-control" name="row[username]" type="text" placeholder="用户登录使用的用户名" >
+            <input data-rule="required" class="form-control" name="row[username]" type="text"
+                   placeholder="用户登录使用的用户名">
         </div>
     </div>
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>手机号码:</label>
+        <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>手机号码:</label>
         <div class="col-xs-12 col-sm-8">
-            <input data-rule="required" class="form-control" name="row[mobile]" type="text" placeholder="已经存在的手机号不可填写" >
+            <input data-rule="required" class="form-control" name="row[mobile]" type="text"
+                   placeholder="已经存在的手机号不可填写">
         </div>
     </div>
     <div class="form-group">
         <label for="c-password" class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>{:__('Password')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-password" data-rule="required|password" class="form-control" name="row[password]" type="text" value=""
-                   placeholder="请输入密码" autocomplete="password" />
+            <input id="c-password" data-rule="required|password" class="form-control" name="row[password]" type="text"
+                   value=""
+                   placeholder="请输入密码" autocomplete="password"/>
         </div>
     </div>
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>岗位:</label>
+        <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>岗位:</label>
         <div class="col-xs-12 col-sm-8">
-            <input  data-rule="required" class="form-control" name="row[post]" type="text"  >
+            <input class="form-control" name="row[post]" type="text">
         </div>
     </div>
     <div class="form-group">
         <label for="c-image" class="control-label col-xs-12 col-sm-2">头像:</label>
         <div class="col-xs-12 col-sm-8">
             <div class="input-group">
-                <input id="c-image" class="form-control" size="35" name="row[img]" type="text" value="/assets/addons/qingdongams/mini/avatar.png">
+                <input id="c-image" class="form-control" size="35" name="row[img]" type="text"
+                       value="/assets/addons/qingdongams/mini/avatar.png">
                 <div class="input-group-addon no-border no-padding">
-                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload"
+                                  data-input-id="c-image"
+                                  data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp"
+                                  data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                 </div>
                 <span class="msg-box n-right"></span>
             </div>
@@ -90,7 +105,7 @@
         </div>
     </div>
     <div class="form-group">
-        <label  class="control-label col-xs-12 col-sm-2">性别:</label>
+        <label class="control-label col-xs-12 col-sm-2">性别:</label>
         <div class="col-xs-12 col-sm-8">
             {:build_radios('row[sex]', ['1'=>__('男'), '2'=>__('女')])}
         </div>

+ 26 - 13
application/admin/view/qingdongams/department/staff/edit.html

@@ -16,14 +16,17 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>角色:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('group[]', $groupdata, $row['group_ids'], ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}
+            {:build_select('group[]', $groupdata, $row['group_ids'], ['class'=>'form-control selectpicker',
+            'data-rule'=>'required'])}
         </div>
-        <small style="line-height:34px;" >
+        <small style="line-height:34px;">
             <span style="padding:0px;"></span>
-            <a href="javascript:;" id="myPopover"   data-toggle="popover" data-placement="right" data-trigger="hover" data-template='<div class="popover" role="tooltip">
+            <a href="javascript:;" id="myPopover" data-toggle="popover" data-placement="right" data-trigger="hover"
+               data-template='<div class="popover" role="tooltip">
     <div class="arrow"></div>
     <h3 class="popover-title" style="width:200px;"></h3>
-</div>'  data-original-title="该部门在【员工管理】—【组织架构】处进行配置"><i class="fa fa-question-circle" style="font-size:16px;"></i></a>
+</div>' data-original-title="该部门在【员工管理】—【组织架构】处进行配置"><i class="fa fa-question-circle"
+                                                                         style="font-size:16px;"></i></a>
         </small>
     </div>
     {/if}
@@ -33,12 +36,14 @@
             {:build_select('row[role]', $roles, $row['role'], ['class'=>'form-control selectpicker',
             'data-rule'=>'required', 'data-live-search'=>'true'])}
         </div>
-        <small style="line-height:34px;" >
+        <small style="line-height:34px;">
             <span style="padding:0px;"></span>
-            <a href="javascript:;" id="roles"   data-toggle="popover" data-placement="right" data-trigger="hover" data-template='<div class="popover" role="tooltip">
+            <a href="javascript:;" id="roles" data-toggle="popover" data-placement="right" data-trigger="hover"
+               data-template='<div class="popover" role="tooltip">
     <div class="arrow"></div>
     <h3 class="popover-title" style="width:200px;"></h3>
-</div>'  data-original-title="该角色在【员工管理】—【角色管理】处进行配置此员工数据权限"><i class="fa fa-question-circle" style="font-size:16px;"></i></a>
+</div>' data-original-title="该角色在【员工管理】—【角色管理】处进行配置此员工数据权限"><i class="fa fa-question-circle"
+                                                                                       style="font-size:16px;"></i></a>
         </small>
     </div>
 
@@ -52,20 +57,28 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>邮箱:</label>
         <div class="col-xs-12  col-sm-8">
-            <input    class="form-control"  name="row[email]" type="text" value="{$row.email}" data-rule="required">
+            <input class="form-control" name="row[email]" type="text" value="{$row.email}" data-rule="required">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>用户名:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input data-rule="required" class="form-control" name="row[username]" type="text"
+                   placeholder="用户登录使用的用户名" value="{$row.username}">
         </div>
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>手机号码:</label>
         <div class="col-xs-12  col-sm-8">
-            <input data-rule="required" name="row[mobile]" class="form-control" type="text" value="{$row.mobile}" >
+            <input data-rule="required" name="row[mobile]" class="form-control" type="text" value="{$row.mobile}">
         </div>
     </div>
 
     <div class="form-group">
-        <label for="c-password" class="control-label col-xs-12 col-sm-2"><span style="color:red;">*</span>{:__('Password')}:</label>
-        <div class="col-xs-12  col-sm-8">
-            <input id="c-password" data-rule="required|password" class="form-control" name="row[password]" type="text" value=""
+        <label for="c-password" class="control-label col-xs-12 col-sm-2">{:__('Password')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-password" class="form-control" name="row[password]" type="text"
+                   value=""
                    placeholder="不修改密码请留空" autocomplete="new-password"/>
         </div>
     </div>
@@ -73,7 +86,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">岗位:</label>
         <div class="col-xs-12  col-sm-8">
-            <input data-rule="required" class="form-control" name="row[post]" type="text" value="{$row.post}">
+            <input class="form-control" name="row[post]" type="text" value="{$row.post}">
         </div>
     </div>
     <div class="form-group">

+ 1 - 1
application/admin/view/qingdongams/parts/parts/index.html

@@ -8,7 +8,7 @@
             <div class="tab-pane fade active in" id="one">
                 <div class="widget-body no-padding">
                     <div id="toolbar" class="toolbar">
-                        {:build_toolbar('refresh,add,edit')}
+                        {:build_toolbar('refresh,add')}
                     </div>
                     <table id="table"
                            class="table table-striped table-bordered table-hover table-nowrap"

+ 1 - 1
application/admin/view/qingdongams/workorder/workorder/detail_template/detail1.html

@@ -67,7 +67,7 @@
 				{if condition="$row.file"}
 				<div class="thumbnail">
 					{foreach name="row.file" item="val"}
-					<img data-tips-image src="{$val.file_path}" alt="">
+					<img data-tips-image src="{$val.file_path}" alt="" class="click-img">
 					{/foreach}
 				</div>
 				{/if}

+ 1 - 1
public/assets/js/backend/qingdongams/department/staff.js

@@ -25,7 +25,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
 				columns           : [
 					[
 						{checkbox : true},
-						{field : 'admin.username', title : __('用户名'), operate: false},
+						{field : 'username', title : __('用户名'), operate: false},
 						{field : 'name', title : __('姓名')},
 						{field : 'img', title : __('头像'), events : Table.api.events.image, formatter : Table.api.formatter.image, operate : false},
 						{field : 'num', title : __('员工编号')},

+ 4 - 2
public/assets/js/backend/qingdongams/parts/parts.js

@@ -164,7 +164,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 							operate: false,
 							searchList: $.getJSON("qingdongams/customer/customer/stafflist")
 						},
-
 						{
 							field: 'parts.odd_numbers',
 							title: '申请编号',
@@ -201,8 +200,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 					]
 				],
 				//启用普通表单搜索
-				commonSearch: true,
+				commonSearch: false,
 				searchFormVisible: true,
+				search: false,
+				showExport: false,
+				showColumn: false,
 			});
 			$(document).on('click', '.show-log_info', function (data) {
 				var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];

+ 7 - 0
public/assets/js/backend/qingdongams/workorder/workorder.js

@@ -627,6 +627,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 					callback: function (value) {
 					},
 				});
+			}).on('click', '.click-img', function () {
+				let url = $(this).attr('src');
+				let s = '<img src="' + url + '"/>';
+				layer.open({
+					content:s,
+					area: ['99%', '98%'], //宽高
+				});
 			});
 			Controller.api.bindevent();
 		},