Michael_xu 4 лет назад
Родитель
Сommit
25706b1136
55 измененных файлов: 3482 добавлений и 1298 удалений
  1. 4
    4
      application/admin/controller/ExamineFlow.php
  2. 54
    28
      application/admin/controller/Field.php
  3. 5
    1
      application/admin/controller/Index.php
  4. 303
    248
      application/admin/logic/FieldGrantLogic.php
  5. 12
    12
      application/admin/logic/PrintingLogic.php
  6. 14
    2
      application/admin/model/ActionRecord.php
  7. 18
    1
      application/admin/model/Common.php
  8. 1
    1
      application/admin/model/ExamineFlow.php
  9. 10
    1
      application/admin/model/ExamineRecord.php
  10. 9
    1
      application/admin/model/ExamineStep.php
  11. 32
    31
      application/admin/model/Excel.php
  12. 570
    178
      application/admin/model/Field.php
  13. 74
    1
      application/admin/model/File.php
  14. 1
    1
      application/admin/model/LoginRecord.php
  15. 171
    0
      application/admin/model/Message.php
  16. 70
    1
      application/admin/model/Scene.php
  17. 17
    5
      application/admin/model/Structure.php
  18. 53
    6
      application/admin/model/User.php
  19. 79
    50
      application/admin/traits/FieldVerificationTrait.php
  20. 203
    137
      application/common.php
  21. 29
    1
      application/common/command/PoolCommand.php
  22. 2
    0
      application/common/command/Team.php
  23. 9
    6
      application/crm/controller/Contract.php
  24. 119
    159
      application/crm/controller/Customer.php
  25. 3
    1
      application/crm/controller/CustomerPool.php
  26. 1
    1
      application/crm/controller/Index.php
  27. 2
    2
      application/crm/controller/Invoice.php
  28. 3
    0
      application/crm/controller/Leads.php
  29. 2
    1
      application/crm/controller/Message.php
  30. 19
    5
      application/crm/controller/Receivables.php
  31. 38
    1
      application/crm/controller/ReceivablesPlan.php
  32. 3
    1
      application/crm/logic/ActivityLogic.php
  33. 52
    61
      application/crm/logic/IndexLogic.php
  34. 128
    52
      application/crm/logic/InvoiceLogic.php
  35. 82
    2
      application/crm/logic/VisitLogic.php
  36. 82
    4
      application/crm/model/Business.php
  37. 84
    4
      application/crm/model/Contacts.php
  38. 101
    9
      application/crm/model/Contract.php
  39. 148
    28
      application/crm/model/Customer.php
  40. 93
    0
      application/crm/model/Invoice.php
  41. 90
    7
      application/crm/model/Leads.php
  42. 84
    4
      application/crm/model/Product.php
  43. 5
    3
      application/crm/model/ProductCategory.php
  44. 130
    51
      application/crm/model/Receivables.php
  45. 323
    145
      application/crm/model/ReceivablesPlan.php
  46. 90
    0
      application/crm/model/Visit.php
  47. 1
    0
      application/oa/controller/Log.php
  48. 1
    1
      application/oa/model/Event.php
  49. 9
    3
      application/oa/model/Log.php
  50. 3
    1
      config/route_crm.php
  51. 2
    2
      config/version.php
  52. 32
    32
      public/sql/5kcrm.sql
  53. 5
    0
      public/sql/update_sql_20210903.sql
  54. 2
    2
      public/static/js/step2.js
  55. 5
    0
      update_sql_20210903.sql

+ 4
- 4
application/admin/controller/ExamineFlow.php Просмотреть файл

274
     {
274
     {
275
         $param = $this->param;
275
         $param = $this->param;
276
         $userInfo = $this->userInfo;
276
         $userInfo = $this->userInfo;
277
-       $data= $this->checkFlow($param,$userInfo);
277
+        $data= $this->checkFlow($param,$userInfo);
278
         return resultArray(['data' => $data]);
278
         return resultArray(['data' => $data]);
279
     }
279
     }
280
     
280
     
287
      * @version     1.0 版本号
287
      * @version     1.0 版本号
288
      * @since       2021/3/15 0015 13:37
288
      * @since       2021/3/15 0015 13:37
289
      */
289
      */
290
-    public function checkFlow($param,$userInfo){
290
+    public function checkFlow($param,$userInfo)
291
+    {
291
         $examineStepModel = model('ExamineStep');
292
         $examineStepModel = model('ExamineStep');
292
         $examineFlowModel = model('ExamineFlow');
293
         $examineFlowModel = model('ExamineFlow');
293
         $check_user_id = $userInfo['id'];
294
         $check_user_id = $userInfo['id'];
294
         $flow_id = $param['flow_id'];
295
         $flow_id = $param['flow_id'];
295
         $types = $param['types'];
296
         $types = $param['types'];
296
         $types_id = $param['types_id'];
297
         $types_id = $param['types_id'];
297
-        $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine'];
298
+        $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
298
         if (!$types || !in_array($types, $typesArr)) {
299
         if (!$types || !in_array($types, $typesArr)) {
299
             return resultArray(['error' => '参数错误']);
300
             return resultArray(['error' => '参数错误']);
300
         }
301
         }
301
-    
302
         if ($flow_id) {
302
         if ($flow_id) {
303
             $examineFlowData = $examineFlowModel->getDataById($param['flow_id']);
303
             $examineFlowData = $examineFlowModel->getDataById($param['flow_id']);
304
             if (!$examineFlowData) {
304
             if (!$examineFlowData) {

+ 54
- 28
application/admin/controller/Field.php Просмотреть файл

145
                 $errorMessage = '数字字段类型的小数配置错误!';
145
                 $errorMessage = '数字字段类型的小数配置错误!';
146
                 break;
146
                 break;
147
             }
147
             }
148
+            # 数组数据转换为字符串保存
149
+            if ($v['form_type'] == 'date_interval') {
150
+               $v['default_value']=trim((string)implode(',',$v['default_value']),'"');
151
+            }
152
+            if( $v['form_type']=='position'){
153
+                    $v['default_value']=json_encode($v['default_value']);
154
+            }
155
+            # 数组数据转换为字符串保存
156
+//            if (!empty($v['fieldExtendList'])) {
157
+//                foreach ($v['fieldExtendList'] as $key=> $value){
158
+//                    if($value['form_type']=='textarea'){
159
+//                        $v['fieldExtendList'][$key]['default_value']=!empty($value['default_value'])?(string)trim("'".$value['default_value']."'",'"'):'';
160
+//                    }
161
+//                }
162
+//            }
148
 
163
 
149
             if ($v['field_id']) {
164
             if ($v['field_id']) {
150
                 if (isset($v['is_deleted']) && $v['is_deleted'] == '1') {
165
                 if (isset($v['is_deleted']) && $v['is_deleted'] == '1') {
164
                 $saveParam[$k]['types_id'] = $types_id;
179
                 $saveParam[$k]['types_id'] = $types_id;
165
             }
180
             }
166
         }
181
         }
167
-
168
         # 必填的字段不可以隐藏
182
         # 必填的字段不可以隐藏
169
         if ($errorMessage) return resultArray(['error' => $errorMessage]);
183
         if ($errorMessage) return resultArray(['error' => $errorMessage]);
170
 
184
 
174
         foreach ($deleteIds AS $key => $value) {
188
         foreach ($deleteIds AS $key => $value) {
175
             if (!in_array($value, $delParam)) $delParam[] = $value;
189
             if (!in_array($value, $delParam)) $delParam[] = $value;
176
         }
190
         }
177
-
178
         # 新增
191
         # 新增
179
         if (!empty($saveParam)) {
192
         if (!empty($saveParam)) {
180
             if (!$data = $fieldModel->createData($types, $saveParam)) {
193
             if (!$data = $fieldModel->createData($types, $saveParam)) {
181
                 $errorMessage[] = $fieldModel->getError();
194
                 $errorMessage[] = $fieldModel->getError();
182
             }
195
             }
183
         }
196
         }
184
-        
185
         # 编辑
197
         # 编辑
186
         if (!empty($updateParam)) {
198
         if (!empty($updateParam)) {
187
             if (!$data = $fieldModel->updateDataById($updateParam, $types)) {
199
             if (!$data = $fieldModel->updateDataById($updateParam, $types)) {
259
         if ($action == 'read' || $action == 'update') {
271
         if ($action == 'read' || $action == 'update') {
260
             //获取详情数据
272
             //获取详情数据
261
             if (($param['action'] == 'update' || $param['action'] == 'read') && $param['action_id']) {
273
             if (($param['action'] == 'update' || $param['action'] == 'read') && $param['action_id']) {
274
+                $model='';
275
+                if($param['action'] == 'update'){
276
+                    $model='update';
277
+                }
262
                 switch ($param['types']) {
278
                 switch ($param['types']) {
263
                     case 'crm_customer' : 
279
                     case 'crm_customer' : 
264
                         $customerModel = new \app\crm\model\Customer();
280
                         $customerModel = new \app\crm\model\Customer();
265
-                        $dataInfo = $customerModel->getDataById(intval($param['action_id']));
281
+                        $dataInfo = $customerModel->getDataById($param['action_id'],'',$model);
266
                         //判断权限
282
                         //判断权限
267
                         $auth_user_ids = $userModel->getUserByPer('crm', 'customer', $param['action']);
283
                         $auth_user_ids = $userModel->getUserByPer('crm', 'customer', $param['action']);
268
                         //读写权限
284
                         //读写权限
278
                         break;
294
                         break;
279
                     case 'crm_leads' : 
295
                     case 'crm_leads' : 
280
                         $leadsModel = new \app\crm\model\Leads();
296
                         $leadsModel = new \app\crm\model\Leads();
281
-                        $dataInfo = $leadsModel->getDataById(intval($param['action_id']));
297
+                        $dataInfo = $leadsModel->getDataById($param['action_id'],'',$model);
282
                         //判断权限
298
                         //判断权限
283
                         $auth_user_ids = $userModel->getUserByPer('crm', 'leads', $param['action']);
299
                         $auth_user_ids = $userModel->getUserByPer('crm', 'leads', $param['action']);
300
+
284
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
301
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
285
                             header('Content-Type:application/json; charset=utf-8');
302
                             header('Content-Type:application/json; charset=utf-8');
286
                             exit(json_encode(['code'=>102,'error'=>'无权操作']));
303
                             exit(json_encode(['code'=>102,'error'=>'无权操作']));
288
                         break;  
305
                         break;  
289
                     case 'crm_contacts' : 
306
                     case 'crm_contacts' : 
290
                         $contactsModel = new \app\crm\model\Contacts();
307
                         $contactsModel = new \app\crm\model\Contacts();
291
-                        $dataInfo = $contactsModel->getDataById(intval($param['action_id']));
308
+                        $dataInfo = $contactsModel->getDataById($param['action_id'],'',$model);
292
                         //判断权限
309
                         //判断权限
293
                         $auth_user_ids = $userModel->getUserByPer('crm', 'contacts', $param['action']);
310
                         $auth_user_ids = $userModel->getUserByPer('crm', 'contacts', $param['action']);
294
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
311
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
298
                         break;
315
                         break;
299
                     case 'crm_business' :
316
                     case 'crm_business' :
300
                         $businessModel = new \app\crm\model\Business();
317
                         $businessModel = new \app\crm\model\Business();
301
-                        $dataInfo = $businessModel->getDataById(intval($param['action_id']));
318
+                        $dataInfo = $businessModel->getDataById($param['action_id'],'',$model);
302
                         //判断权限
319
                         //判断权限
303
                         $auth_user_ids = $userModel->getUserByPer('crm', 'business', $param['action']);
320
                         $auth_user_ids = $userModel->getUserByPer('crm', 'business', $param['action']);
304
                         //读写权限
321
                         //读写权限
311
                         break;
328
                         break;
312
                     case 'crm_contract' : 
329
                     case 'crm_contract' : 
313
                         $contractModel = new \app\crm\model\Contract();
330
                         $contractModel = new \app\crm\model\Contract();
314
-                        $dataInfo = $contractModel->getDataById(intval($param['action_id']));
331
+                        $dataInfo = $contractModel->getDataById($param['action_id'],'',$model);
315
                         //判断权限
332
                         //判断权限
316
                         $auth_user_ids = $userModel->getUserByPer('crm', 'contract', $param['action']);
333
                         $auth_user_ids = $userModel->getUserByPer('crm', 'contract', $param['action']);
317
                         //读写权限
334
                         //读写权限
324
                         break;
341
                         break;
325
                     case 'crm_product' : 
342
                     case 'crm_product' : 
326
                         $productModel = new \app\crm\model\Product();
343
                         $productModel = new \app\crm\model\Product();
327
-                        $dataInfo = $productModel->getDataById(intval($param['action_id']));
344
+                        $dataInfo = $productModel->getDataById($param['action_id'],'',$model);
328
 
345
 
329
                         //判断权限
346
                         //判断权限
330
                         $auth_user_ids = $userModel->getUserByPer('crm', 'product', $param['action']);
347
                         $auth_user_ids = $userModel->getUserByPer('crm', 'product', $param['action']);
335
                         break;
352
                         break;
336
                     case 'crm_receivables' : 
353
                     case 'crm_receivables' : 
337
                         $receivablesModel = new \app\crm\model\Receivables();
354
                         $receivablesModel = new \app\crm\model\Receivables();
338
-                        $dataInfo = $receivablesModel->getDataById(intval($param['action_id']));
355
+                        $dataInfo = $receivablesModel->getDataById($param['action_id'],'',$model);
339
                         //判断权限
356
                         //判断权限
340
                         $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', $param['action']);
357
                         $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', $param['action']);
341
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
358
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
345
                         break;
362
                         break;
346
                     case 'crm_receivables_plan' : 
363
                     case 'crm_receivables_plan' : 
347
                         $receivablesPlanModel = new \app\crm\model\ReceivablesPlan();
364
                         $receivablesPlanModel = new \app\crm\model\ReceivablesPlan();
348
-                        $dataInfo = $receivablesPlanModel->getDataById(intval($param['action_id']));
365
+                        $dataInfo = $receivablesPlanModel->getDataById($param['action_id'],'',$model);
366
+                        //判断权限
367
+                        $auth_user_ids = $userModel->getUserByPer('crm', 'receivables_plan', $param['action']);
368
+                        if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
369
+                            header('Content-Type:application/json; charset=utf-8');
370
+                            exit(json_encode(['code'=>102,'error'=>'无权操作']));
371
+                        }
349
                         break; 
372
                         break; 
350
                     case 'oa_examine' :
373
                     case 'oa_examine' :
351
                         $examineModel = new \app\oa\model\Examine();  
374
                         $examineModel = new \app\oa\model\Examine();  
362
                         break;
385
                         break;
363
                     case 'crm_visit' :
386
                     case 'crm_visit' :
364
                         $visit = new \app\crm\model\Visit();
387
                         $visit = new \app\crm\model\Visit();
365
-                        $dataInfo = $visit->getDataById(intval($param['action_id']));
388
+                        $dataInfo = $visit->getDataById($param['action_id'],'',$model);
366
                         $fieldModel = new \app\admin\model\Field();
389
                         $fieldModel = new \app\admin\model\Field();
367
                         $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
390
                         $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
368
                         foreach ($datetimeField as $key => $val) {
391
                         foreach ($datetimeField as $key => $val) {
379
                         }
402
                         }
380
                         break;
403
                         break;
381
                     case 'crm_invoice' :
404
                     case 'crm_invoice' :
382
-                        $visit = new \app\crm\model\Invoice();
383
-                        $dataInfo = $visit->getDataById(intval($param['action_id']));
405
+                        $Invoice = new \app\crm\model\Invoice();
406
+                        $dataInfo = $Invoice->getDataById($param['action_id'],'',$model);
384
                         $fieldModel = new \app\admin\model\Field();
407
                         $fieldModel = new \app\admin\model\Field();
385
                         $datetimeField = $fieldModel->getFieldByFormType('crm_invoice', 'datetime'); //日期时间类型
408
                         $datetimeField = $fieldModel->getFieldByFormType('crm_invoice', 'datetime'); //日期时间类型
386
                         foreach ($datetimeField as $key => $val) {
409
                         foreach ($datetimeField as $key => $val) {
400
         $param['user_id'] = $user_id;
423
         $param['user_id'] = $user_id;
401
         $action_id = $param['action_id'] ? : '';
424
         $action_id = $param['action_id'] ? : '';
402
         $data = $fieldModel->field($param, $dataInfo) ? : [];
425
         $data = $fieldModel->field($param, $dataInfo) ? : [];
403
-
404
         # 多公海数据详情
426
         # 多公海数据详情
405
         if (!empty($param['pool_id']) && $param['action'] == 'read') {
427
         if (!empty($param['pool_id']) && $param['action'] == 'read') {
406
             $data = $this->setPoolDetailData($data, $param['pool_id'], $param['action_id']);
428
             $data = $this->setPoolDetailData($data, $param['pool_id'], $param['action_id']);
511
                 case 'crm_leads' :
533
                 case 'crm_leads' :
512
                     $leadsModel = new Leads();
534
                     $leadsModel = new Leads();
513
                     $leadsData  = $leadsModel->getSystemInfo($action_id);
535
                     $leadsData  = $leadsModel->getSystemInfo($action_id);
514
-                    $leadsArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
536
+                    $leadsArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
515
 
537
 
516
                     foreach ($leadsData AS $key => $value) {
538
                     foreach ($leadsData AS $key => $value) {
517
-                        if (empty($leadsArray[$key])) continue;
539
+                        if (empty($leadsArray[$key]) ) continue;
518
 
540
 
519
                         $data[] = [
541
                         $data[] = [
520
                             'field'     => $key,
542
                             'field'     => $key,
528
                 case 'crm_customer' :
550
                 case 'crm_customer' :
529
                     $customerModel = new Customer();
551
                     $customerModel = new Customer();
530
                     $customerData  = $customerModel->getSystemInfo($action_id);
552
                     $customerData  = $customerModel->getSystemInfo($action_id);
531
-                    $customerArray = ['obtain_time' => '负责人获取客户时间', 'owner_user_id' => '负责人', 'create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'last_record' => '最后跟进记录', 'deal_status' => '成交状态'];
532
-
553
+                    $customerArray = ['obtain_time' => '负责人获取客户时间', 'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'last_record' => '最后跟进记录', 'deal_status' => '成交状态'];
533
                     foreach ($customerData AS $key => $value) {
554
                     foreach ($customerData AS $key => $value) {
534
                         if (empty($customerArray[$key]) || (!empty($param['pool_id']) && in_array($key, ['obtain_time', 'owner_user_id']))) continue;
555
                         if (empty($customerArray[$key]) || (!empty($param['pool_id']) && in_array($key, ['obtain_time', 'owner_user_id']))) continue;
535
 
556
 
545
                 case 'crm_contacts' :
566
                 case 'crm_contacts' :
546
                     $contactsModel = new Contacts();
567
                     $contactsModel = new Contacts();
547
                     $contactsData  = $contactsModel->getSystemInfo($action_id);
568
                     $contactsData  = $contactsModel->getSystemInfo($action_id);
548
-                    $contactsArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
569
+                    $contactsArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
549
 
570
 
550
                     foreach ($contactsData AS $key => $value) {
571
                     foreach ($contactsData AS $key => $value) {
551
                         if (empty($contactsArray[$key])) continue;
572
                         if (empty($contactsArray[$key])) continue;
562
                 case 'crm_business' :
583
                 case 'crm_business' :
563
                     $businessModel = new Business();
584
                     $businessModel = new Business();
564
                     $businessData  = $businessModel->getSystemInfo($action_id);
585
                     $businessData  = $businessModel->getSystemInfo($action_id);
565
-                    $businessArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
586
+                    $businessArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
566
 
587
 
567
                     foreach ($businessData AS $key => $value) {
588
                     foreach ($businessData AS $key => $value) {
568
                         if (empty($businessArray[$key])) continue;
589
                         if (empty($businessArray[$key])) continue;
579
                 case 'crm_contract' :
600
                 case 'crm_contract' :
580
                     $contractModel = new Contract();
601
                     $contractModel = new Contract();
581
                     $contractData  = $contractModel->getSystemInfo($action_id);
602
                     $contractData  = $contractModel->getSystemInfo($action_id);
582
-                    $contractArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'done_money' => '已收款金额', 'un_money' => '未收款金额'];
603
+                    $contractArray = ['create_user_id' => '创建人','owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'done_money' => '已收款金额', 'un_money' => '未收款金额'];
583
 
604
 
584
                     foreach ($contractData AS $key => $value) {
605
                     foreach ($contractData AS $key => $value) {
585
                         if (empty($contractArray[$key])) continue;
606
                         if (empty($contractArray[$key])) continue;
596
                 case 'crm_receivables' :
617
                 case 'crm_receivables' :
597
                     $receivablesModel = new Receivables();
618
                     $receivablesModel = new Receivables();
598
                     $receivablesData  = $receivablesModel->getSystemInfo($action_id);
619
                     $receivablesData  = $receivablesModel->getSystemInfo($action_id);
599
-                    $receivablesArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间'];
620
+                    $receivablesArray = ['create_user_id' => '创建人','owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间'];
600
 
621
 
601
                     foreach ($receivablesData AS $key => $value) {
622
                     foreach ($receivablesData AS $key => $value) {
602
                         if (empty($receivablesArray[$key])) continue;
623
                         if (empty($receivablesArray[$key])) continue;
613
                 case 'crm_product' :
634
                 case 'crm_product' :
614
                     $productModel = new Product();
635
                     $productModel = new Product();
615
                     $productData  = $productModel->getSystemInfo($action_id);
636
                     $productData  = $productModel->getSystemInfo($action_id);
616
-                    $productArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间'];
637
+                    $productArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间'];
617
 
638
 
618
                     foreach ($productData AS $key => $value) {
639
                     foreach ($productData AS $key => $value) {
619
                         if (empty($productArray[$key])) continue;
640
                         if (empty($productArray[$key])) continue;
630
                 case 'crm_visit' :
651
                 case 'crm_visit' :
631
                     $visitLogic = new VisitLogic();
652
                     $visitLogic = new VisitLogic();
632
                     $visitData  = $visitLogic->getSystemInfo($action_id);
653
                     $visitData  = $visitLogic->getSystemInfo($action_id);
633
-                    $visitArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间'];
654
+                    $visitArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间'];
634
 
655
 
635
                     foreach ($visitData AS $key => $value) {
656
                     foreach ($visitData AS $key => $value) {
636
                         if (empty($visitArray[$key])) continue;
657
                         if (empty($visitArray[$key])) continue;
646
                     break;
667
                     break;
647
                 case 'crm_invoice' :
668
                 case 'crm_invoice' :
648
                     $invoiceData = db('crm_invoice')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('invoice_id', $action_id)->find();
669
                     $invoiceData = db('crm_invoice')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('invoice_id', $action_id)->find();
670
+                    
649
                     $createUserName = db('admin_user')->where('id', $invoiceData['create_user_id'])->value('realname');
671
                     $createUserName = db('admin_user')->where('id', $invoiceData['create_user_id'])->value('realname');
650
-                    $ownerUserName = db('admin_user')->where('id', $invoiceData['owner_user_id'])->value('realname');
651
                     $data[] = ['field' => 'create_user_id', 'name' => '创建人', 'form_type' => 'user', 'value' => $createUserName, 'system' => 1];
672
                     $data[] = ['field' => 'create_user_id', 'name' => '创建人', 'form_type' => 'user', 'value' => $createUserName, 'system' => 1];
652
-                    $data[] = ['field' => 'create_user_id', 'name' => '负责人', 'form_type' => 'user', 'value' => $ownerUserName, 'system' => 1];
653
                     $data[] = ['field' => 'create_time', 'name' => '创建时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['create_time']), 'system' => 1];
673
                     $data[] = ['field' => 'create_time', 'name' => '创建时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['create_time']), 'system' => 1];
654
                     $data[] = ['field' => 'update_time', 'name' => '更新时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['update_time']), 'system' => 1];
674
                     $data[] = ['field' => 'update_time', 'name' => '更新时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['update_time']), 'system' => 1];
675
+                    
676
+                    # zjf   20210726
677
+                    $userModel   = new \app\admin\model\User();
678
+                    $ownerUserInfo = $userModel->getUserById($invoiceData['owner_user_id']);
679
+                    $data[] = ['field' => 'owner_user_id', 'name' => '负责人', 'form_type' => 'user', 'value' => $ownerUserInfo['realname'], 'system' => 1];
680
+                    $data[] = ['field' => 'owner_user_structure_name', 'name' => '所属部门', 'form_type' => 'text', 'value' => $ownerUserInfo['structure_name'], 'system' => 1];
681
+                    
655
             }
682
             }
656
         }
683
         }
657
 
684
 
658
         # 处理自定义字段别名、权限
685
         # 处理自定义字段别名、权限
659
         $data = $fieldModel->resetField($user_id, $param['types'], $param['action'], $data);
686
         $data = $fieldModel->resetField($user_id, $param['types'], $param['action'], $data);
660
-
661
         # 处理自定义字段分组排序
687
         # 处理自定义字段分组排序
662
         if (in_array($param['action'], ['save', 'update', 'relative']) && $format == 2) $data = getFieldGroupOrderData($data);
688
         if (in_array($param['action'], ['save', 'update', 'relative']) && $format == 2) $data = getFieldGroupOrderData($data);
663
 
689
 

+ 5
- 1
application/admin/controller/Index.php Просмотреть файл

63
             if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
63
             if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
64
         }
64
         }
65
         if(in_array($param['types'],['crm_customer','crm_customer_pool','crm_contacts','crm_business','crm_contract','crm_receivables'])){
65
         if(in_array($param['types'],['crm_customer','crm_customer_pool','crm_contacts','crm_business','crm_contract','crm_receivables'])){
66
-            $field=[['field'=>'team_id','name'=>'相关团队','form_type'=>'user','setting'=>[]]];
66
+            $field=[['field'=>'team_id','name'=>'相关团队','form_type'=>'text','setting'=>[]]];
67
             $field_arr=array_merge($field_arr,$field);
67
             $field_arr=array_merge($field_arr,$field);
68
         }
68
         }
69
+        // if($param['types'] == 'jxc_product'){
70
+        //     $field_arr[] = ['field'=>'product_code','name'=>'产品编码','form_type'=>'text','setting'=>[]];
71
+        // }
72
+        // $field_arr[] = ['field'=>'owner_structure','name'=>'所属部门','form_type'=>'structure','setting'=>[]];
69
         return resultArray(['data' => $field_arr]);
73
         return resultArray(['data' => $field_arr]);
70
     }
74
     }
71
 
75
 

+ 303
- 248
application/admin/logic/FieldGrantLogic.php Просмотреть файл

47
             'number', 'visit_time', 'owner_user_id', 'shape', 'customer_id', 'contacts_id', 'contract_id', 'satisfaction',
47
             'number', 'visit_time', 'owner_user_id', 'shape', 'customer_id', 'contacts_id', 'contract_id', 'satisfaction',
48
             'feedback', 'create_user_id', 'create_time', 'update_time'
48
             'feedback', 'create_user_id', 'create_time', 'update_time'
49
         ],
49
         ],
50
+
50
         'invoice' => [
51
         'invoice' => [
51
             'invoice_apple_number', 'customer_id', 'contract_id', 'contract_money', 'invoice_date', 'invoice_money', 'invoice_type', 'remark'
52
             'invoice_apple_number', 'customer_id', 'contract_id', 'contract_money', 'invoice_date', 'invoice_money', 'invoice_type', 'remark'
52
         ],
53
         ],
54
+        'receivables_plan' => [
55
+            'receivables_id','un_money','real_money','real_data', 'num', 'money', 'owner_user_id', 'return_date', 'customer_id', 'remind', 'contract_id', 'create_user_id', 'create_time', 'update_time'
56
+        ]
57
+
53
     ];
58
     ];
54
 
59
 
55
     /**
60
     /**
70
         };
75
         };
71
 
76
 
72
         $count = Db::name('admin_field_grant')->where($where)->count();
77
         $count = Db::name('admin_field_grant')->where($where)->count();
73
-
74
         # 如果该角色下没有字段授权数据则自动添加
78
         # 如果该角色下没有字段授权数据则自动添加
75
         if ($count == 0 && Db::name('admin_group')->where('id', $param['role_id'])->find()) {
79
         if ($count == 0 && Db::name('admin_group')->where('id', $param['role_id'])->find()) {
76
             $this->createCrmFieldGrant($param['role_id']);
80
             $this->createCrmFieldGrant($param['role_id']);
113
         $this->createVisitFieldGrant($roleId);
117
         $this->createVisitFieldGrant($roleId);
114
         # 添加发票字段授权信息
118
         # 添加发票字段授权信息
115
         $this->createInvoiceFieldGrant($roleId);
119
         $this->createInvoiceFieldGrant($roleId);
120
+
121
+        # 添加回款计划字段授权信息
122
+        $this->createReceivablesPlanFieldGrant($roleId);
116
     }
123
     }
117
 
124
 
118
     /**
125
     /**
157
 
164
 
158
         $list = Db::name('admin_field_grant')->where('module', 'crm')->where('role_id', $copyId)->select();
165
         $list = Db::name('admin_field_grant')->where('module', 'crm')->where('role_id', $copyId)->select();
159
 
166
 
160
-        foreach ($list AS $key => $value) {
167
+        foreach ($list as $key => $value) {
161
             $data[] = [
168
             $data[] = [
162
-                'role_id'     => $roleId,
163
-                'module'      => $value['module'],
164
-                'column'      => $value['column'],
165
-                'content'     => $value['content'],
169
+                'role_id' => $roleId,
170
+                'module' => $value['module'],
171
+                'column' => $value['column'],
172
+                'content' => $value['content'],
166
                 'create_time' => time(),
173
                 'create_time' => time(),
167
                 'update_time' => time()
174
                 'update_time' => time()
168
             ];
175
             ];
192
         # 查询自定义字段表
199
         # 查询自定义字段表
193
         $fieldBaseData = [];
200
         $fieldBaseData = [];
194
         $fieldList = Db::name('admin_field')->field(['name', 'field'])->where('types', $types)->select();
201
         $fieldList = Db::name('admin_field')->field(['name', 'field'])->where('types', $types)->select();
195
-        foreach ($fieldList AS $key => $value) {
202
+        foreach ($fieldList as $key => $value) {
196
             # 排除掉固定字段
203
             # 排除掉固定字段
197
             if (in_array($value['field'], $this->except[$typesArray[1]])) continue;
204
             if (in_array($value['field'], $this->except[$typesArray[1]])) continue;
198
 
205
 
203
         $grantList = Db::name('admin_field_grant')->field(['grant_id', 'content'])->where('column', $typesArray[1])->select();
210
         $grantList = Db::name('admin_field_grant')->field(['grant_id', 'content'])->where('column', $typesArray[1])->select();
204
 
211
 
205
         # 处理授权字段的数据更新
212
         # 处理授权字段的数据更新
206
-        foreach ($grantList AS $key => $value) {
207
-            $content   = unserialize($value['content']);
213
+        foreach ($grantList as $key => $value) {
214
+            $content = unserialize($value['content']);
208
             $fieldData = $fieldBaseData;
215
             $fieldData = $fieldBaseData;
209
 
216
 
210
-            foreach ($content AS $k => $v) {
217
+            foreach ($content as $k => $v) {
211
                 # 只处理自定义字段
218
                 # 只处理自定义字段
212
                 if ($v['is_diy'] == 0) continue;
219
                 if ($v['is_diy'] == 0) continue;
213
 
220
 
216
                     unset($content[(int)$k]);
223
                     unset($content[(int)$k]);
217
                 } else {
224
                 } else {
218
                     # 【处理更新:】如果在$fieldData找到,则进行同步更新。
225
                     # 【处理更新:】如果在$fieldData找到,则进行同步更新。
219
-                    $content[$k]['name']  = $fieldData[$v['field']]['name'];
226
+                    $content[$k]['name'] = $fieldData[$v['field']]['name'];
220
                     $content[$k]['field'] = $fieldData[$v['field']]['field'];
227
                     $content[$k]['field'] = $fieldData[$v['field']]['field'];
221
 
228
 
222
                     # 删除$fieldData的数据,方便统计新增的自定义字段。
229
                     # 删除$fieldData的数据,方便统计新增的自定义字段。
227
 
234
 
228
             # 【处理新增】如果$fieldData还有数据,说明是新增的,则进行同步新增。
235
             # 【处理新增】如果$fieldData还有数据,说明是新增的,则进行同步新增。
229
             if (!empty($fieldData)) {
236
             if (!empty($fieldData)) {
230
-                foreach ($fieldData AS $k => $v) {
237
+                foreach ($fieldData as $k => $v) {
231
                     $content[] = [
238
                     $content[] = [
232
-                        'name'            => $v['name'],
233
-                        'field'           => $v['field'],
234
-                        'read'            => 1,
235
-                        'read_operation'  => 1,
236
-                        'write'           => 1,
239
+                        'name' => $v['name'],
240
+                        'field' => $v['field'],
241
+                        'read' => 1,
242
+                        'read_operation' => 1,
243
+                        'write' => 1,
237
                         'write_operation' => 1,
244
                         'write_operation' => 1,
238
-                        'is_diy'          => 1
245
+                        'is_diy' => 1
239
                     ];
246
                     ];
240
                 }
247
                 }
241
             }
248
             }
257
     {
264
     {
258
         # 固定字段
265
         # 固定字段
259
         $content = [
266
         $content = [
260
-            ['field' => 'name',           'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索名称'],
261
-            ['field' => 'email',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
262
-            ['field' => 'source',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索来源'],
263
-            ['field' => 'mobile',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
264
-            ['field' => 'telephone',      'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
265
-            ['field' => 'detail_address', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'],
266
-            ['field' => 'industry',       'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'],
267
-            ['field' => 'level',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'],
268
-            ['field' => 'next_time',      'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
269
-            ['field' => 'remark',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
270
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
271
-            ['field' => 'last_record',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
272
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
273
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
274
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
275
-            ['field' => 'last_time',      'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
267
+            ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索名称'],
268
+            ['field' => 'email', 'maskType' => 0, 'form_type'=>'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
269
+            ['field' => 'source', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索来源'],
270
+            ['field' => 'mobile', 'maskType' => 0, 'read' => 1,'form_type'=>'mobile', 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
271
+            ['field' => 'telephone', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
272
+            ['field' => 'detail_address', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'],
273
+            ['field' => 'industry', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'],
274
+            ['field' => 'level', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'],
275
+            ['field' => 'next_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
276
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
277
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
278
+            ['field' => 'last_record', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
279
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
280
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
281
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
282
+            ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
276
         ];
283
         ];
277
 
284
 
278
         $leadsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_leads')->select();
285
         $leadsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_leads')->select();
279
 
286
 
280
         # 自定义字段
287
         # 自定义字段
281
-        foreach ($leadsList AS $key => $value) {
288
+        foreach ($leadsList as $key => $value) {
282
             if (in_array($value['field'], $this->except['leads'])) continue;
289
             if (in_array($value['field'], $this->except['leads'])) continue;
283
 
290
 
284
             $content[] = [
291
             $content[] = [
285
-                'name'            => $value['name'],
286
-                'field'           => $value['field'],
287
-                'read'            => 1,
288
-                'read_operation'  => 1,
289
-                'write'           => 1,
292
+                'name' => $value['name'],
293
+                'field' => $value['field'],
294
+                'form_type'=>$value['form_type'],
295
+                'read' => 1,
296
+                'read_operation' => 1,
297
+                'write' => 1,
290
                 'write_operation' => 1,
298
                 'write_operation' => 1,
291
-                'is_diy'          => 1
299
+                'is_diy' => 1
292
             ];
300
             ];
293
         }
301
         }
294
-
295
         Db::name('admin_field_grant')->insert([
302
         Db::name('admin_field_grant')->insert([
296
-            'role_id'     => $roleId,
297
-            'module'      => 'crm',
298
-            'column'      => 'leads',
299
-            'content'     => serialize($content),
303
+            'role_id' => $roleId,
304
+            'module' => 'crm',
305
+            'column' => 'leads',
306
+            'content' => serialize($content),
300
             'create_time' => time(),
307
             'create_time' => time(),
301
             'update_time' => time()
308
             'update_time' => time()
302
         ]);
309
         ]);
313
     {
320
     {
314
         # 固定字段
321
         # 固定字段
315
         $content = [
322
         $content = [
316
-            ['field' => 'name',           'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
317
-            ['field' => 'source',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户来源'],
318
-            ['field' => 'mobile',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
319
-            ['field' => 'telephone',      'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
320
-            ['field' => 'website',        'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '网址'],
321
-            ['field' => 'industry',       'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'],
322
-            ['field' => 'level',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'],
323
-            ['field' => 'next_time',      'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
324
-            ['field' => 'remark',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
325
-            ['field' => 'email',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
326
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
327
-            ['field' => 'last_record',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
328
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
329
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
330
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
331
-            ['field' => 'last_time',      'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
332
-            ['field' => 'obtain_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人获取客户时间'],
333
-            ['field' => 'deal_status',    'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '成交状态'],
334
-            ['field' => 'is_lock',        'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '锁定状态'],
335
-            ['field' => 'pool_day',       'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '距进入公海天数'],
323
+            ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
324
+            ['field' => 'source', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户来源'],
325
+            ['field' => 'mobile', 'maskType' => 0,'form_type'=>'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
326
+            ['field' => 'telephone', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
327
+            ['field' => 'website', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '网址'],
328
+            ['field' => 'industry', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'],
329
+            ['field' => 'level', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'],
330
+            ['field' => 'next_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
331
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
332
+            ['field' => 'email', 'maskType' => 0,'form_type'=>'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
333
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
334
+            ['field' => 'last_record', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
335
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
336
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
337
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
338
+            ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
339
+            ['field' => 'obtain_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人获取客户时间'],
340
+            ['field' => 'deal_status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '成交状态'],
341
+            ['field' => 'is_lock', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '锁定状态'],
342
+            ['field' => 'pool_day', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '距进入公海天数'],
336
         ];
343
         ];
337
 
344
 
338
         $customerList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_customer')->select();
345
         $customerList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_customer')->select();
339
 
346
 
340
         # 自定义字段
347
         # 自定义字段
341
-        foreach ($customerList AS $key => $value) {
348
+        foreach ($customerList as $key => $value) {
342
             if (in_array($value['field'], $this->except['customer'])) continue;
349
             if (in_array($value['field'], $this->except['customer'])) continue;
343
 
350
 
344
             $content[] = [
351
             $content[] = [
345
-                'name'            => $value['name'],
346
-                'field'           => $value['field'],
347
-                'read'            => 1,
348
-                'read_operation'  => 1,
349
-                'write'           => 1,
352
+                'name' => $value['name'],
353
+                'field' => $value['field'],
354
+                'read' => 1,
355
+                'read_operation' => 1,
356
+                'write' => 1,
350
                 'write_operation' => 1,
357
                 'write_operation' => 1,
351
-                'is_diy'          => 1
358
+                'is_diy' => 1
352
             ];
359
             ];
353
         }
360
         }
354
 
361
 
355
         Db::name('admin_field_grant')->insert([
362
         Db::name('admin_field_grant')->insert([
356
-            'role_id'     => $roleId,
357
-            'module'      => 'crm',
358
-            'column'      => 'customer',
359
-            'content'     => serialize($content),
363
+            'role_id' => $roleId,
364
+            'module' => 'crm',
365
+            'column' => 'customer',
366
+            'content' => serialize($content),
360
             'create_time' => time(),
367
             'create_time' => time(),
361
             'update_time' => time()
368
             'update_time' => time()
362
         ]);
369
         ]);
373
     {
380
     {
374
         # 固定字段
381
         # 固定字段
375
         $content = [
382
         $content = [
376
-            ['field' => 'name',           'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '姓名'],
377
-            ['field' => 'customer_id',    'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
378
-            ['field' => 'mobile',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
379
-            ['field' => 'telephone',      'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
380
-            ['field' => 'email',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
381
-            ['field' => 'post',           'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '职务'],
382
-            ['field' => 'decision',       'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '是否关键决策人'],
383
-            ['field' => 'detail_address', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'],
384
-            ['field' => 'next_time',      'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
385
-            ['field' => 'remark',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
386
-            ['field' => 'sex',            'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '性别'],
387
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
388
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
389
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
390
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
391
-            ['field' => 'last_time',      'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
383
+            ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '姓名'],
384
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
385
+            ['field' => 'mobile', 'maskType' => 0,'form_type'=>'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
386
+            ['field' => 'telephone', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
387
+            ['field' => 'email', 'maskType' => 0, 'form_type'=>'email','read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
388
+            ['field' => 'post', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '职务'],
389
+            ['field' => 'decision', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '是否关键决策人'],
390
+            ['field' => 'detail_address', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'],
391
+            ['field' => 'next_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
392
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
393
+            ['field' => 'sex', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '性别'],
394
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
395
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
396
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
397
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
398
+            ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
392
         ];
399
         ];
393
 
400
 
394
         $contactsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contacts')->select();
401
         $contactsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contacts')->select();
395
 
402
 
396
         # 自定义字段
403
         # 自定义字段
397
-        foreach ($contactsList AS $key => $value) {
404
+        foreach ($contactsList as $key => $value) {
398
             if (in_array($value['field'], $this->except['contacts'])) continue;
405
             if (in_array($value['field'], $this->except['contacts'])) continue;
399
 
406
 
400
             $content[] = [
407
             $content[] = [
401
-                'name'            => $value['name'],
402
-                'field'           => $value['field'],
403
-                'read'            => 1,
404
-                'read_operation'  => 1,
405
-                'write'           => 1,
408
+                'name' => $value['name'],
409
+                'field' => $value['field'],
410
+                'read' => 1,
411
+                'read_operation' => 1,
412
+                'write' => 1,
406
                 'write_operation' => 1,
413
                 'write_operation' => 1,
407
-                'is_diy'          => 1
414
+                'is_diy' => 1
408
             ];
415
             ];
409
         }
416
         }
410
 
417
 
411
         Db::name('admin_field_grant')->insert([
418
         Db::name('admin_field_grant')->insert([
412
-            'role_id'     => $roleId,
413
-            'module'      => 'crm',
414
-            'column'      => 'contacts',
415
-            'content'     => serialize($content),
419
+            'role_id' => $roleId,
420
+            'module' => 'crm',
421
+            'column' => 'contacts',
422
+            'content' => serialize($content),
416
             'create_time' => time(),
423
             'create_time' => time(),
417
             'update_time' => time()
424
             'update_time' => time()
418
         ]);
425
         ]);
429
     {
436
     {
430
         # 固定字段
437
         # 固定字段
431
         $content = [
438
         $content = [
432
-            ['field' => 'name',           'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'],
433
-            ['field' => 'customer_id',    'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
434
-            ['field' => 'money',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机金额'],
435
-            ['field' => 'deal_date',      'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '预计成交日期'],
436
-            ['field' => 'remark',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
437
-            ['field' => 'status_id',      'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机阶段'],
438
-            ['field' => 'type_id',        'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机状态组'],
439
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
440
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
441
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
442
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
443
-            ['field' => 'last_time',      'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
439
+            ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'],
440
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
441
+            ['field' => 'money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机金额'],
442
+            ['field' => 'deal_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '预计成交日期'],
443
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
444
+            ['field' => 'status_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机阶段'],
445
+            ['field' => 'type_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机状态组'],
446
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
447
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
448
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
449
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
450
+            ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
444
         ];
451
         ];
445
 
452
 
446
         $BusinessList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_business')->select();
453
         $BusinessList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_business')->select();
447
 
454
 
448
         # 自定义字段
455
         # 自定义字段
449
-        foreach ($BusinessList AS $key => $value) {
456
+        foreach ($BusinessList as $key => $value) {
450
             if (in_array($value['field'], $this->except['business'])) continue;
457
             if (in_array($value['field'], $this->except['business'])) continue;
451
 
458
 
452
             $content[] = [
459
             $content[] = [
453
-                'name'            => $value['name'],
454
-                'field'           => $value['field'],
455
-                'read'            => 1,
456
-                'read_operation'  => 1,
457
-                'write'           => 1,
460
+                'name' => $value['name'],
461
+                'field' => $value['field'],
462
+                'read' => 1,
463
+                'read_operation' => 1,
464
+                'write' => 1,
458
                 'write_operation' => 1,
465
                 'write_operation' => 1,
459
-                'is_diy'          => 1
466
+                'is_diy' => 1
460
             ];
467
             ];
461
         }
468
         }
462
 
469
 
463
         Db::name('admin_field_grant')->insert([
470
         Db::name('admin_field_grant')->insert([
464
-            'role_id'     => $roleId,
465
-            'module'      => 'crm',
466
-            'column'      => 'business',
467
-            'content'     => serialize($content),
471
+            'role_id' => $roleId,
472
+            'module' => 'crm',
473
+            'column' => 'business',
474
+            'content' => serialize($content),
468
             'create_time' => time(),
475
             'create_time' => time(),
469
             'update_time' => time()
476
             'update_time' => time()
470
         ]);
477
         ]);
481
     {
488
     {
482
         # 固定字段
489
         # 固定字段
483
         $content = [
490
         $content = [
484
-            ['field' => 'name',           'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同名称'],
485
-            ['field' => 'num',            'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'],
486
-            ['field' => 'customer_id',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
487
-            ['field' => 'business_id',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'],
488
-            ['field' => 'money',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同金额'],
489
-            ['field' => 'order_date',     'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '下单时间'],
490
-            ['field' => 'start_time',     'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同开始时间'],
491
-            ['field' => 'end_time',       'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同结束时间'],
492
-            ['field' => 'contacts_id',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户签约人'],
493
-            ['field' => 'order_user_id',  'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '公司签约人'],
494
-            ['field' => 'remark',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
495
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
496
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
497
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
498
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
499
-            ['field' => 'last_time',      'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
500
-            ['field' => 'last_record',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
501
-            ['field' => 'done_money',     'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '已收款金额'],
502
-            ['field' => 'un_money',       'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '未收款金额'],
503
-            ['field' => 'check_status',   'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'],
491
+            ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同名称'],
492
+            ['field' => 'num', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'],
493
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
494
+            ['field' => 'business_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'],
495
+            ['field' => 'money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同金额'],
496
+            ['field' => 'order_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '下单时间'],
497
+            ['field' => 'start_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同开始时间'],
498
+            ['field' => 'end_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同结束时间'],
499
+            ['field' => 'contacts_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户签约人'],
500
+            ['field' => 'order_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '公司签约人'],
501
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
502
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
503
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
504
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
505
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
506
+            ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
507
+            ['field' => 'last_record', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
508
+            ['field' => 'done_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '已收款金额'],
509
+            ['field' => 'un_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '未收款金额'],
510
+            ['field' => 'check_status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'],
504
         ];
511
         ];
505
 
512
 
506
         $contractList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contract')->select();
513
         $contractList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contract')->select();
507
 
514
 
508
         # 自定义字段
515
         # 自定义字段
509
-        foreach ($contractList AS $key => $value) {
516
+        foreach ($contractList as $key => $value) {
510
             if (in_array($value['field'], $this->except['contract'])) continue;
517
             if (in_array($value['field'], $this->except['contract'])) continue;
511
 
518
 
512
             $content[] = [
519
             $content[] = [
513
-                'name'            => $value['name'],
514
-                'field'           => $value['field'],
515
-                'read'            => 1,
516
-                'read_operation'  => 1,
517
-                'write'           => 1,
520
+                'name' => $value['name'],
521
+                'field' => $value['field'],
522
+                'read' => 1,
523
+                'read_operation' => 1,
524
+                'write' => 1,
518
                 'write_operation' => 1,
525
                 'write_operation' => 1,
519
-                'is_diy'          => 1
526
+                'is_diy' => 1
520
             ];
527
             ];
521
         }
528
         }
522
 
529
 
523
         Db::name('admin_field_grant')->insert([
530
         Db::name('admin_field_grant')->insert([
524
-            'role_id'     => $roleId,
525
-            'module'      => 'crm',
526
-            'column'      => 'contract',
527
-            'content'     => serialize($content),
531
+            'role_id' => $roleId,
532
+            'module' => 'crm',
533
+            'column' => 'contract',
534
+            'content' => serialize($content),
528
             'create_time' => time(),
535
             'create_time' => time(),
529
             'update_time' => time()
536
             'update_time' => time()
530
         ]);
537
         ]);
541
     {
548
     {
542
         # 固定字段
549
         # 固定字段
543
         $content = [
550
         $content = [
544
-            ['field' => 'number',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款编号'],
545
-            ['field' => 'customer_id',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
546
-            ['field' => 'contract_id',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'],
547
-            ['field' => 'plan_id',        'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '期数'],
548
-            ['field' => 'return_time',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款日期'],
549
-            ['field' => 'money',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款金额'],
550
-            ['field' => 'return_type',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款方式'],
551
-            ['field' => 'remark',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
552
-            ['field' => 'contract_money', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'],
553
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
554
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
555
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
556
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
557
-            ['field' => 'check_status',   'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'],
551
+            ['field' => 'number', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款编号'],
552
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
553
+            ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'],
554
+            ['field' => 'plan_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '期数'],
555
+            ['field' => 'return_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款日期'],
556
+            ['field' => 'money', 'maskType' => 0,'form_type'=>'floatnumber', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款金额'],
557
+            ['field' => 'return_type', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款方式'],
558
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
559
+            ['field' => 'contract_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'],
560
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
561
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
562
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
563
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
564
+            ['field' => 'check_status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'],
558
         ];
565
         ];
559
 
566
 
560
         $receivablesList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables')->select();
567
         $receivablesList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables')->select();
561
 
568
 
562
         # 自定义字段
569
         # 自定义字段
563
-        foreach ($receivablesList AS $key => $value) {
570
+        foreach ($receivablesList as $key => $value) {
564
             if (in_array($value['field'], $this->except['receivables'])) continue;
571
             if (in_array($value['field'], $this->except['receivables'])) continue;
565
 
572
 
566
             $content[] = [
573
             $content[] = [
567
-                'name'            => $value['name'],
568
-                'field'           => $value['field'],
569
-                'read'            => 1,
570
-                'read_operation'  => 1,
571
-                'write'           => 1,
574
+                'name' => $value['name'],
575
+                'field' => $value['field'],
576
+                'read' => 1,
577
+                'read_operation' => 1,
578
+                'write' => 1,
572
                 'write_operation' => 1,
579
                 'write_operation' => 1,
573
-                'is_diy'          => 1
580
+                'is_diy' => 1
574
             ];
581
             ];
575
         }
582
         }
576
 
583
 
577
         Db::name('admin_field_grant')->insert([
584
         Db::name('admin_field_grant')->insert([
578
-            'role_id'     => $roleId,
579
-            'module'      => 'crm',
580
-            'column'      => 'receivables',
581
-            'content'     => serialize($content),
585
+            'role_id' => $roleId,
586
+            'module' => 'crm',
587
+            'column' => 'receivables',
588
+            'content' => serialize($content),
582
             'create_time' => time(),
589
             'create_time' => time(),
583
             'update_time' => time()
590
             'update_time' => time()
584
         ]);
591
         ]);
595
     {
602
     {
596
         # 固定字段
603
         # 固定字段
597
         $content = [
604
         $content = [
598
-            ['field' => 'name',           'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品名称'],
599
-            ['field' => 'category_id',    'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品类型'],
600
-            ['field' => 'unit',           'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品单位'],
601
-            ['field' => 'num',            'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品编码'],
602
-            ['field' => 'price',          'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '价格'],
603
-            ['field' => 'description',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品描述'],
604
-            ['field' => 'status',         'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '是否上下架'],
605
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
606
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
607
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
608
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
605
+            ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品名称'],
606
+            ['field' => 'category_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品类型'],
607
+            ['field' => 'unit', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品单位'],
608
+            ['field' => 'num', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品编码'],
609
+            ['field' => 'price', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '价格'],
610
+            ['field' => 'description', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品描述'],
611
+            ['field' => 'status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '是否上下架'],
612
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
613
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
614
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
615
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
609
         ];
616
         ];
610
 
617
 
611
         $productList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_product')->select();
618
         $productList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_product')->select();
612
 
619
 
613
         # 自定义字段
620
         # 自定义字段
614
-        foreach ($productList AS $key => $value) {
621
+        foreach ($productList as $key => $value) {
615
             if (in_array($value['field'], $this->except['product'])) continue;
622
             if (in_array($value['field'], $this->except['product'])) continue;
616
 
623
 
617
             $content[] = [
624
             $content[] = [
618
-                'name'            => $value['name'],
619
-                'field'           => $value['field'],
620
-                'read'            => 1,
621
-                'read_operation'  => 1,
622
-                'write'           => 1,
625
+                'name' => $value['name'],
626
+                'field' => $value['field'],
627
+                'read' => 1,
628
+                'read_operation' => 1,
629
+                'write' => 1,
623
                 'write_operation' => 1,
630
                 'write_operation' => 1,
624
-                'is_diy'          => 1
631
+                'is_diy' => 1
625
             ];
632
             ];
626
         }
633
         }
627
 
634
 
628
         Db::name('admin_field_grant')->insert([
635
         Db::name('admin_field_grant')->insert([
629
-            'role_id'     => $roleId,
630
-            'module'      => 'crm',
631
-            'column'      => 'product',
632
-            'content'     => serialize($content),
636
+            'role_id' => $roleId,
637
+            'module' => 'crm',
638
+            'column' => 'product',
639
+            'content' => serialize($content),
633
             'create_time' => time(),
640
             'create_time' => time(),
634
             'update_time' => time()
641
             'update_time' => time()
635
         ]);
642
         ]);
645
     private function createVisitFieldGrant($roleId)
652
     private function createVisitFieldGrant($roleId)
646
     {
653
     {
647
         $content = [
654
         $content = [
648
-            ['field' => 'number',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访编号'],
649
-            ['field' => 'visit_time',     'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访时间'],
650
-            ['field' => 'owner_user_id',  'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '回访人'],
651
-            ['field' => 'shape',          'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访形式'],
652
-            ['field' => 'customer_id',    'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
653
-            ['field' => 'contacts_id',    'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '联系人'],
654
-            ['field' => 'contract_id',    'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
655
-            ['field' => 'satisfaction',   'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户满意度'],
656
-            ['field' => 'feedback',       'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户反馈'],
657
-            ['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
658
-            ['field' => 'create_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
659
-            ['field' => 'update_time',    'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
655
+            ['field' => 'number', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访编号'],
656
+            ['field' => 'visit_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访时间'],
657
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '回访人'],
658
+            ['field' => 'shape', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访形式'],
659
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
660
+            ['field' => 'contacts_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '联系人'],
661
+            ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
662
+            ['field' => 'satisfaction', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户满意度'],
663
+            ['field' => 'feedback', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户反馈'],
664
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
665
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
666
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
660
         ];
667
         ];
661
 
668
 
662
         $visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_visit')->select();
669
         $visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_visit')->select();
663
 
670
 
664
         # 处理自定义字段
671
         # 处理自定义字段
665
-        foreach ($visitList AS $key => $value) {
672
+        foreach ($visitList as $key => $value) {
666
             if (in_array($value['field'], $this->except['visit'])) continue;
673
             if (in_array($value['field'], $this->except['visit'])) continue;
667
 
674
 
668
             $content[] = [
675
             $content[] = [
669
-                'name'            => $value['name'],
670
-                'field'           => $value['field'],
671
-                'read'            => 1,
672
-                'read_operation'  => 1,
673
-                'write'           => 1,
676
+                'name' => $value['name'],
677
+                'field' => $value['field'],
678
+                'read' => 1,
679
+                'read_operation' => 1,
680
+                'write' => 1,
674
                 'write_operation' => 1,
681
                 'write_operation' => 1,
675
-                'is_diy'          => 1
682
+                'is_diy' => 1
676
             ];
683
             ];
677
         }
684
         }
678
 
685
 
679
         Db::name('admin_field_grant')->insert([
686
         Db::name('admin_field_grant')->insert([
680
-            'role_id'     => $roleId,
681
-            'module'      => 'crm',
682
-            'column'      => 'visit',
683
-            'content'     => serialize($content),
687
+            'role_id' => $roleId,
688
+            'module' => 'crm',
689
+            'column' => 'visit',
690
+            'content' => serialize($content),
684
             'create_time' => time(),
691
             'create_time' => time(),
685
             'update_time' => time()
692
             'update_time' => time()
686
         ]);
693
         ]);
687
     }
694
     }
688
 
695
 
689
     /**
696
     /**
690
-     * 处理回访字段授权信息
697
+     * 处理发票字段授权信息
691
      *
698
      *
692
      * @param $roleId
699
      * @param $roleId
693
      * @author fanqi
700
      * @author fanqi
696
     private function createInvoiceFieldGrant($roleId)
703
     private function createInvoiceFieldGrant($roleId)
697
     {
704
     {
698
         $content = [
705
         $content = [
699
-            ['field' => 'invoice_apple_number', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '发票申请编号'],
700
-            ['field' => 'customer_id',          'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
701
-            ['field' => 'contract_id',          'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
702
-            ['field' => 'contract_money',       'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'],
703
-            ['field' => 'invoice_money',        'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票金额'],
704
-            ['field' => 'invoice_date',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票日期'],
705
-            ['field' => 'invoice_type',         'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票类型'],
706
-            ['field' => 'remark',               'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
706
+            ['field' => 'invoice_apple_number', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '发票申请编号'],
707
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
708
+            ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
709
+            ['field' => 'contract_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'],
710
+            ['field' => 'invoice_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票金额'],
711
+            ['field' => 'invoice_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票日期'],
712
+            ['field' => 'invoice_type', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票类型'],
713
+            ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
707
         ];
714
         ];
708
 
715
 
709
         $invoiceList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_invoice')->select();
716
         $invoiceList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_invoice')->select();
710
 
717
 
711
         # 处理自定义字段
718
         # 处理自定义字段
712
-        foreach ($invoiceList AS $key => $value) {
719
+        foreach ($invoiceList as $key => $value) {
713
             if (in_array($value['field'], $this->except['invoice'])) continue;
720
             if (in_array($value['field'], $this->except['invoice'])) continue;
714
 
721
 
715
             $content[] = [
722
             $content[] = [
716
-                'name'            => $value['name'],
717
-                'field'           => $value['field'],
718
-                'read'            => 1,
719
-                'read_operation'  => 1,
720
-                'write'           => 1,
723
+                'name' => $value['name'],
724
+                'field' => $value['field'],
725
+                'read' => 1,
726
+                'read_operation' => 1,
727
+                'write' => 1,
721
                 'write_operation' => 1,
728
                 'write_operation' => 1,
722
-                'is_diy'          => 1
729
+                'is_diy' => 1
723
             ];
730
             ];
724
         }
731
         }
725
 
732
 
726
         Db::name('admin_field_grant')->insert([
733
         Db::name('admin_field_grant')->insert([
727
-            'role_id'     => $roleId,
728
-            'module'      => 'crm',
729
-            'column'      => 'invoice',
730
-            'content'     => serialize($content),
734
+            'role_id' => $roleId,
735
+            'module' => 'crm',
736
+            'column' => 'invoice',
737
+            'content' => serialize($content),
738
+            'create_time' => time(),
739
+            'update_time' => time()
740
+        ]);
741
+    }
742
+
743
+    /**
744
+     * 处理回款计划字段授权信息
745
+     *
746
+     * @param int $roleId
747
+     * @author fanqi
748
+     * @date 2021-03-22
749
+     */
750
+    private function createReceivablesPlanFieldGrant($roleId)
751
+    {
752
+        $content = [
753
+            ['field' => 'num', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '期数'],
754
+            ['field' => 'money', 'maskType' => 0, 'form_type'=>'floatnumber', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '计划回款金额'],
755
+            ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
756
+            ['field' => 'return_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '计划回款日期'],
757
+            ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
758
+            ['field' => 'remind', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '提前几日提醒'],
759
+            ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
760
+            ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
761
+            ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
762
+            ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
763
+        ];
764
+
765
+        $visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables_plan')->select();
766
+
767
+        # 处理自定义字段
768
+        foreach ($visitList as $key => $value) {
769
+            if (in_array($value['field'], $this->except['receivables_plan'])) continue;
770
+
771
+            $content[] = [
772
+                'name' => $value['name'],
773
+                'field' => $value['field'],
774
+                'read' => 1,
775
+                'read_operation' => 1,
776
+                'write' => 1,
777
+                'write_operation' => 1,
778
+                'is_diy' => 1
779
+            ];
780
+        }
781
+        Db::name('admin_field_grant')->insert([
782
+            'role_id' => $roleId,
783
+            'module' => 'crm',
784
+            'column' => 'receivables_plan',
785
+            'content' => serialize($content),
731
             'create_time' => time(),
786
             'create_time' => time(),
732
             'update_time' => time()
787
             'update_time' => time()
733
         ]);
788
         ]);

+ 12
- 12
application/admin/logic/PrintingLogic.php Просмотреть файл

207
     {
207
     {
208
         $result = [];
208
         $result = [];
209
 
209
 
210
-        $businessList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_business')->select();
210
+        $businessList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_business')->select();
211
 
211
 
212
         # 处理自定义字段
212
         # 处理自定义字段
213
         foreach ($businessList AS $key => $value) {
213
         foreach ($businessList AS $key => $value) {
214
             if ($value['field'] == 'customer_id') continue;
214
             if ($value['field'] == 'customer_id') continue;
215
-
215
+            if ($value['form_type']=='detail_table') continue;
216
             $result[] = [
216
             $result[] = [
217
                 'name'  => $value['name'],
217
                 'name'  => $value['name'],
218
                 'field' => $value['field']
218
                 'field' => $value['field']
240
     {
240
     {
241
         $result = [];
241
         $result = [];
242
 
242
 
243
-        $customerList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_customer')->select();
243
+        $customerList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_customer')->select();
244
 
244
 
245
         # 处理自定义字段
245
         # 处理自定义字段
246
         foreach ($customerList AS $key => $value) {
246
         foreach ($customerList AS $key => $value) {
247
             if (in_array($value['field'], ['next_time'])) continue;
247
             if (in_array($value['field'], ['next_time'])) continue;
248
             if (in_array($type, [5, 6]) && in_array($value['field'], ['deal_status'])) continue;
248
             if (in_array($type, [5, 6]) && in_array($value['field'], ['deal_status'])) continue;
249
-
249
+            if ($value['form_type']=='detail_table') continue;
250
             $result[] = [
250
             $result[] = [
251
                 'name'  => $value['name'],
251
                 'name'  => $value['name'],
252
                 'field' => $value['field']
252
                 'field' => $value['field']
274
     {
274
     {
275
         $result = [];
275
         $result = [];
276
 
276
 
277
-        $productList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_product')->select();
277
+        $productList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_product')->select();
278
 
278
 
279
         # 处理自定义字段
279
         # 处理自定义字段
280
         foreach ($productList AS $key => $value) {
280
         foreach ($productList AS $key => $value) {
281
             if (in_array($value['field'], ['status'])) continue;
281
             if (in_array($value['field'], ['status'])) continue;
282
             if (in_array($type, [5, 6]) && in_array($value['field'], ['description'])) continue;
282
             if (in_array($type, [5, 6]) && in_array($value['field'], ['description'])) continue;
283
-
283
+            if ($value['form_type']=='detail_table') continue;
284
             $result[] = [
284
             $result[] = [
285
                 'name'  => $value['name'],
285
                 'name'  => $value['name'],
286
                 'field' => $value['field']
286
                 'field' => $value['field']
310
     {
310
     {
311
         $result = [];
311
         $result = [];
312
 
312
 
313
-        $contractList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contract')->select();
313
+        $contractList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_contract')->select();
314
 
314
 
315
         # 处理自定义字段
315
         # 处理自定义字段
316
         foreach ($contractList AS $key => $value) {
316
         foreach ($contractList AS $key => $value) {
317
             if (in_array($type, [6, 7]) && in_array($value['field'], ['customer_id'])) continue;
317
             if (in_array($type, [6, 7]) && in_array($value['field'], ['customer_id'])) continue;
318
             if ($type == 7 && in_array($value['field'], ['business_id'])) continue;
318
             if ($type == 7 && in_array($value['field'], ['business_id'])) continue;
319
-
319
+            if ($value['form_type']=='detail_table') continue;
320
             $result[] = [
320
             $result[] = [
321
                 'name'  => $value['name'],
321
                 'name'  => $value['name'],
322
                 'field' => $value['field']
322
                 'field' => $value['field']
347
     {
347
     {
348
         $result = [];
348
         $result = [];
349
 
349
 
350
-        $contactsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contacts')->select();
350
+        $contactsList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_contacts')->select();
351
 
351
 
352
         # 处理自定义字段
352
         # 处理自定义字段
353
         foreach ($contactsList AS $key => $value) {
353
         foreach ($contactsList AS $key => $value) {
354
             if ($value['field'] == 'next_time') continue;
354
             if ($value['field'] == 'next_time') continue;
355
-
355
+            if ($value['form_type']=='detail_table') continue;
356
             $result[] = [
356
             $result[] = [
357
                 'name'  => $value['name'],
357
                 'name'  => $value['name'],
358
                 'field' => $value['field']
358
                 'field' => $value['field']
374
     {
374
     {
375
         $result = [];
375
         $result = [];
376
 
376
 
377
-        $receivablesList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables')->select();
377
+        $receivablesList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_receivables')->select();
378
 
378
 
379
         # 处理自定义字段
379
         # 处理自定义字段
380
         foreach ($receivablesList AS $key => $value) {
380
         foreach ($receivablesList AS $key => $value) {
381
             if (in_array($value['field'], ['contract_id'])) continue;
381
             if (in_array($value['field'], ['contract_id'])) continue;
382
             if (in_array($type, [7]) && in_array($value['field'], ['contract_id'])) continue;
382
             if (in_array($type, [7]) && in_array($value['field'], ['contract_id'])) continue;
383
-
383
+            if ($value['form_type']=='detail_table') continue;
384
             $result[] = [
384
             $result[] = [
385
                 'name'  => $value['name'],
385
                 'name'  => $value['name'],
386
                 'field' => $value['field']
386
                 'field' => $value['field']

+ 14
- 2
application/admin/model/ActionRecord.php Просмотреть файл

16
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
16
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
17
      */
17
      */
18
 	protected $name = 'admin_action_record';
18
 	protected $name = 'admin_action_record';
19
-	public $typesArr = ['crm_leads','crm_customer','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit'];
19
+	public $typesArr = ['crm_leads','crm_customer','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit','jxc_product','jxc_supplier','jxc_purchase','jxc_retreat','jxc_sale','jxc_salereturn','jxc_receipt','jxc_outbound','jxc_payment','jxc_collection','jxc_inventory','jxc_allocation'];
20
 
20
 
21
 	/**
21
 	/**
22
 	 * [getDataList 获取列表]
22
 	 * [getDataList 获取列表]
91
 				break;	
91
 				break;	
92
 			case 'crm_visit' :
92
 			case 'crm_visit' :
93
 				$checkRes = checkPerByAction('crm', 'visit', 'read');
93
 				$checkRes = checkPerByAction('crm', 'visit', 'read');
94
-				break;									
94
+				break;
95
+			case 'jxc_product': $checkRes = checkPerByAction('jxc', 'product', 'read'); break;
96
+            case 'jxc_supplier': $checkRes = checkPerByAction('jxc', 'supplier', 'read'); break;
97
+            case 'jxc_purchase': $checkRes = checkPerByAction('jxc', 'purchase', 'read'); break;
98
+            case 'jxc_retreat': $checkRes = checkPerByAction('jxc', 'retreat', 'read'); break;
99
+            case 'jxc_sale': $checkRes = checkPerByAction('jxc', 'sale', 'read'); break;
100
+            case 'jxc_salereturn': $checkRes = checkPerByAction('jxc', 'salereturn', 'read'); break;
101
+            case 'jxc_receipt': $checkRes = checkPerByAction('jxc', 'receipt', 'read'); break;
102
+            case 'jxc_outbound': $checkRes = checkPerByAction('jxc', 'outbound', 'read'); break;
103
+            case 'jxc_payment': $checkRes = checkPerByAction('jxc', 'payment', 'read'); break;
104
+            case 'jxc_collection': $checkRes = checkPerByAction('jxc', 'collection', 'read'); break;
105
+            case 'jxc_inventory': $checkRes = checkPerByAction('jxc', 'inventory', 'read'); break;
106
+            case 'jxc_allocation': $checkRes = checkPerByAction('jxc', 'allocation', 'read'); break;							
95
 		}
107
 		}
96
 		if ($checkRes !== false) {
108
 		if ($checkRes !== false) {
97
 			return true;
109
 			return true;

+ 18
- 1
application/admin/model/Common.php Просмотреть файл

295
      */
295
      */
296
     public function exportHandle($list, $field_list, $type = '')
296
     public function exportHandle($list, $field_list, $type = '')
297
     {
297
     {
298
-        
299
         foreach ($list as &$val) {
298
         foreach ($list as &$val) {
300
             foreach ($field_list as $field) {
299
             foreach ($field_list as $field) {
300
+                // p($field);
301
                 switch ($field['form_type']) {
301
                 switch ($field['form_type']) {
302
                     case 'user':
302
                     case 'user':
303
                         if (isset($val[$field['field'] . 'name'])) {
303
                         if (isset($val[$field['field'] . 'name'])) {
320
                     case 'contacts':
320
                     case 'contacts':
321
                         $val[$field['field']] = $val[$field['field'] . '_info']['name'];
321
                         $val[$field['field']] = $val[$field['field'] . '_info']['name'];
322
                         break;
322
                         break;
323
+                    case 'boolean_value':
324
+                        if( $val[$field['field']]==0){
325
+                            $val[$field['field']]='否';
326
+                        }else{
327
+                            $val[$field['field']]='是';
328
+                        }
329
+                        break;
330
+                    case 'date_interval' :
331
+                        $val[$field['field']] = implode('_',  $val[$field['field']]);
332
+                        break;
323
                     default :
333
                     default :
324
                         switch ($field['field']) {
334
                         switch ($field['field']) {
325
                             // 商机销售阶段、商机状态组
335
                             // 商机销售阶段、商机状态组
337
                             case 'plan_id' :
347
                             case 'plan_id' :
338
                                 $val[$field['field']] = $val[$field['field'] . '_info'];
348
                                 $val[$field['field']] = $val[$field['field'] . '_info'];
339
                                 break;
349
                                 break;
350
+                            case 'warehouse_isuse' :
351
+                                $val[$field['field']] = $val[$field['field']] == 0 ? '已停用' : '已启用';
352
+                                break;
353
+                            default :
354
+                                if($field['form_type'] == 'text'){
355
+                                    $val[$field['field']] = (string)$val[$field['field']];
356
+                                }
340
                         }
357
                         }
341
                 }
358
                 }
342
             }
359
             }

+ 1
- 1
application/admin/model/ExamineFlow.php Просмотреть файл

22
     protected $createTime = 'create_time';
22
     protected $createTime = 'create_time';
23
     protected $updateTime = 'update_time';
23
     protected $updateTime = 'update_time';
24
 	protected $autoWriteTimestamp = true;
24
 	protected $autoWriteTimestamp = true;
25
-	protected $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine'];
25
+	protected $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
26
 
26
 
27
 	/**
27
 	/**
28
      * [getDataList 审批流程list]
28
      * [getDataList 审批流程list]

+ 10
- 1
application/admin/model/ExamineRecord.php Просмотреть файл

57
         $result = [];
57
         $result = [];
58
         
58
         
59
         # 获取创建者信息(业务审批)
59
         # 获取创建者信息(业务审批)
60
-        if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice'])) {
60
+        if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'])) {
61
             $model      = db($param['types']);
61
             $model      = db($param['types']);
62
             $primaryKey = null;
62
             $primaryKey = null;
63
             if ($param['types'] == 'crm_contract')    $primaryKey = 'contract_id';
63
             if ($param['types'] == 'crm_contract')    $primaryKey = 'contract_id';
64
             if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
64
             if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
65
             if ($param['types'] == 'crm_invoice')     $primaryKey = 'invoice_id';
65
             if ($param['types'] == 'crm_invoice')     $primaryKey = 'invoice_id';
66
 
66
 
67
+            if ($param['types'] == 'jxc_purchase')     $primaryKey = 'purchase_id';
68
+            if ($param['types'] == 'jxc_retreat')     $primaryKey = 'retreat_id';
69
+            if ($param['types'] == 'jxc_sale')     $primaryKey = 'sale_id';
70
+            if ($param['types'] == 'jxc_salereturn')     $primaryKey = 'salereturn_id';
71
+            if ($param['types'] == 'jxc_payment')     $primaryKey = 'payment_note_id';
72
+            if ($param['types'] == 'jxc_collection')     $primaryKey = 'collection_note_id';
73
+            if ($param['types'] == 'jxc_allocation')     $primaryKey = 'allocation_id';
74
+            if ($param['types'] == 'jxc_inventory')     $primaryKey = 'inventory_id';
75
+
67
             $info     = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
76
             $info     = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
68
             $userInfo = $userModel->getUserById($info['owner_user_id']);
77
             $userInfo = $userModel->getUserById($info['owner_user_id']);
69
 
78
 

+ 9
- 1
application/admin/model/ExamineStep.php Просмотреть файл

180
             case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
180
             case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
181
             case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
181
             case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
182
             case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
182
             case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
183
-    	}
183
+            case 'jxc_purchase': $dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
184
+            case 'jxc_retreat': $dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
185
+            case 'jxc_sale': $dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
186
+            case 'jxc_salereturn': $dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
187
+            case 'jxc_payment': $dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
188
+            case 'jxc_collection': $dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
189
+            case 'jxc_inventory': $dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
190
+            case 'jxc_allocation': $dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
191
+        }
184
         $stepInfo = [];
192
         $stepInfo = [];
185
         if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) {
193
         if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) {
186
             //固定审批流
194
             //固定审批流

+ 32
- 31
application/admin/model/Excel.php Просмотреть файл

399
         }
399
         }
400
         
400
         
401
         // 排队中
401
         // 排队中
402
-        if (!$queue->canExec()) {
403
-            return resultArray([
404
-                'data' => [
405
-                    'page' => -2,
406
-                    'export_queue_index' => $export_queue_index,
407
-                    'info' => $queue->error
408
-                ]
409
-            ]);
410
-        }
402
+        // if (!$queue->canExec()) {
403
+        //     return resultArray([
404
+        //         'data' => [
405
+        //             'page' => -2,
406
+        //             'export_queue_index' => $export_queue_index,
407
+        //             'info' => $queue->error
408
+        //         ]
409
+        //     ]);
410
+        // }
411
         
411
         
412
         // 没有临时文件名,代表第一次导出,生成临时文件名称,并写入表头数据
412
         // 没有临时文件名,代表第一次导出,生成临时文件名称,并写入表头数据
413
         if ($temp_file === null) {
413
         if ($temp_file === null) {
468
                         if (is_numeric($val[$rule['field']]) && strlen($val[$rule['field']]) > 15) {
468
                         if (is_numeric($val[$rule['field']]) && strlen($val[$rule['field']]) > 15) {
469
                             $val[$rule['field']] = "\t" . $val[$rule['field']] . "\t";
469
                             $val[$rule['field']] = "\t" . $val[$rule['field']] . "\t";
470
                         }
470
                         }
471
-                        $rows[] = $fieldModel->getValueByFormtype($val[$rule['field']], $rule['form_type']);
471
+                        $rows[] = $fieldModel->getValueByFormtype($val[$rule['field']], $rule['form_type'],$val);
472
                     }
472
                     }
473
                 }
473
                 }
474
                 fputcsv($fp, $rows);
474
                 fputcsv($fp, $rows);
519
             $queue->dequeue();
519
             $queue->dequeue();
520
             return false;
520
             return false;
521
         }
521
         }
522
-        if (!empty($param['pool_id'])) {
523
-            $user_id = $param['create_user_id'];
524
-        } else {
525
-            $user_id = $param['owner_user_id'];
526
-        }
522
+        $user_id = $param['create_user_id'];
527
         // 采用伪队列  允许三人同时导入数据
523
         // 采用伪队列  允许三人同时导入数据
528
         $queue = new Queue(self::IMPORT_QUEUE, 50000000);
524
         $queue = new Queue(self::IMPORT_QUEUE, 50000000);
529
         $import_queue_index = input('import_queue_index');
525
         $import_queue_index = input('import_queue_index');
687
             $fieldModel = new \app\admin\model\Field();
683
             $fieldModel = new \app\admin\model\Field();
688
             $fieldParam['types'] = $types;
684
             $fieldParam['types'] = $types;
689
             $fieldParam['action'] = 'excel';
685
             $fieldParam['action'] = 'excel';
686
+          
690
             if (!empty($param['pool_id'])) {
687
             if (!empty($param['pool_id'])) {
691
                 $list = [];
688
                 $list = [];
692
                 $field_list = db('crm_customer_pool_field_setting')->where(['pool_id' => $param['pool_id'], 'is_hidden' => 0,
689
                 $field_list = db('crm_customer_pool_field_setting')->where(['pool_id' => $param['pool_id'], 'is_hidden' => 0,
765
                     }
762
                     }
766
                 }
763
                 }
767
             }
764
             }
765
+           
768
             // 每次导入条数
766
             // 每次导入条数
769
             $page_size = 100;
767
             $page_size = 100;
770
             
768
             
812
                     'update_time' => time(),
810
                     'update_time' => time(),
813
                 ];
811
                 ];
814
             }
812
             }
813
+         
815
             if ($temp !== count($field_list)) {
814
             if ($temp !== count($field_list)) {
816
                 @unlink($save_path);
815
                 @unlink($save_path);
817
                 $queue->dequeue();
816
                 $queue->dequeue();
920
                         $userId = db('admin_user')->where('realname', $val[2])->value('id');
919
                         $userId = db('admin_user')->where('realname', $val[2])->value('id');
921
                         $data['owner_user_id'] = $userId ?: 0;
920
                         $data['owner_user_id'] = $userId ?: 0;
922
                     }
921
                     }
923
-                    $owner = db('crm_customer_pool')->where(['pool_id' => $param['pool_id']])->value('admin_user_ids');
922
+                    $owner = db('crm_customer_pool')->where(['pool_id' => $param['pool_id']])->value('user_ids');
924
                     $auth = db('admin_access')->where('user_id', $param['create_user_id'])->column('group_id');
923
                     $auth = db('admin_access')->where('user_id', $param['create_user_id'])->column('group_id');
925
                     // 数据重复时
924
                     // 数据重复时
926
                     if ($old_data_id_list) {
925
                     if ($old_data_id_list) {
933
                                 $up_success_count = 0;
932
                                 $up_success_count = 0;
934
                                 foreach ($old_data_id_list as $id) {
933
                                 foreach ($old_data_id_list as $id) {
935
                                     if ($types == 'crm_customer' && !empty($param['pool_id'])) {
934
                                     if ($types == 'crm_customer' && !empty($param['pool_id'])) {
936
-                                        if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && !in_array(1, $auth) && $param['create_user_id'] != 1) {
937
-                                            $temp_error = '当前导入人员对该公海数据,无导入权限';
938
-                                            $error_data_func($val, $temp_error);
939
-                                            break;
940
-                                        } else {
935
+                                        if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && $param['create_user_id'] != 1) {
941
                                             if (!$dataModel->updateDataById($data, $id)) {
936
                                             if (!$dataModel->updateDataById($data, $id)) {
942
                                                 $temp_error = $dataModel->getError();
937
                                                 $temp_error = $dataModel->getError();
943
                                                 if ($temp_error == '无权操作') {
938
                                                 if ($temp_error == '无权操作') {
947
                                                 $dataModel->rollback();
942
                                                 $dataModel->rollback();
948
                                                 break;
943
                                                 break;
949
                                             }
944
                                             }
945
+                                            break;
946
+                                        } else {
947
+                                            $temp_error = '当前导入人员对该公海数据,无导入权限';
948
+                                            $error_data_func($val, $temp_error);
950
                                         }
949
                                         }
951
                                     } else {
950
                                     } else {
952
                                         if (!$dataModel->updateDataById($data, $id)) {
951
                                         if (!$dataModel->updateDataById($data, $id)) {
985
                         }
984
                         }
986
                     } else {
985
                     } else {
987
                         if ($types == 'crm_customer' && !empty($param['pool_id'])) {
986
                         if ($types == 'crm_customer' && !empty($param['pool_id'])) {
988
-                            if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && !in_array(1, $auth) && $param['create_user_id'] != 1) {
989
-                                $temp_error = '当前导入人员对该公海数据,无导入权限';
990
-                                $error_data_func($val, $temp_error);
991
-                            } else {
987
+                            if (!in_array($param['create_user_id'], trim(stringToArray($owner), ','))  && $param['create_user_id'] != 1) {
988
+    
992
                                 $data = array_merge($data, $default_data);
989
                                 $data = array_merge($data, $default_data);
993
                                 $data['excel'] = 1;
990
                                 $data['excel'] = 1;
994
                                 if (!$resData = $dataModel->createData($data)) {
991
                                 if (!$resData = $dataModel->createData($data)) {
995
                                     $error_data_func($val, $dataModel->getError());
992
                                     $error_data_func($val, $dataModel->getError());
996
                                 }
993
                                 }
994
+                            } else {
995
+                                $temp_error = '当前导入人员对该公海数据,无导入权限';
996
+                                $error_data_func($val, $temp_error);
997
                             }
997
                             }
998
                         } else {
998
                         } else {
999
                             $data = array_merge($data, $default_data);
999
                             $data = array_merge($data, $default_data);
2013
             }
2013
             }
2014
             
2014
             
2015
             // 开始行  +2 跳过表头
2015
             // 开始行  +2 跳过表头
2016
-            $start_row = ($page - 1) * $page_size + 2;
2016
+            $start_row = ($page - 1) * $page_size + 3;
2017
             // 结束行
2017
             // 结束行
2018
             $end_row = $start_row + $page_size - 1;
2018
             $end_row = $start_row + $page_size - 1;
2019
             if ($end_row > $max_row) {
2019
             if ($end_row > $max_row) {
2032
             ];
2032
             ];
2033
             // 开始导入数据
2033
             // 开始导入数据
2034
             foreach ($dataList as $val) {
2034
             foreach ($dataList as $val) {
2035
+                $data = [];
2036
+                $empty_count = 0;
2037
+                $not_null_field = [];
2038
+                $fk = 0;
2035
                 foreach ($field_list as $field) {
2039
                 foreach ($field_list as $field) {
2036
                     $temp_value = trim($val[$fk]);
2040
                     $temp_value = trim($val[$fk]);
2037
                     // 特殊字段特殊处理
2041
                     // 特殊字段特殊处理
2038
-                    $temp_value = $this->handleData($temp_value, $field);
2042
+//                    $temp_value = $this->handleData($temp_value, $field);
2039
                     $data[$field['field']] = $temp_value;
2043
                     $data[$field['field']] = $temp_value;
2040
                     if ($temp_value == '') {
2044
                     if ($temp_value == '') {
2041
                         if ($field['is_null']) {
2045
                         if ($field['is_null']) {
2053
                     $error_data_func($val, '空行');
2057
                     $error_data_func($val, '空行');
2054
                     continue;
2058
                     continue;
2055
                 }
2059
                 }
2056
-                $data = [];
2057
-                $fk = 0;
2058
                 $classData = db('work_task_class')->where(['name' => $val[6], 'work_id' => $param['work_id']])->order('class_id', 'asc')->select();
2060
                 $classData = db('work_task_class')->where(['name' => $val[6], 'work_id' => $param['work_id']])->order('class_id', 'asc')->select();
2059
                 $max_order_id = db('work_task_class')->where(['work_id' => $param['work_id'], 'status' => 1])->max('order_id');
2061
                 $max_order_id = db('work_task_class')->where(['work_id' => $param['work_id'], 'status' => 1])->max('order_id');
2060
                 if ($classData[0]['class_id'] != '') {
2062
                 if ($classData[0]['class_id'] != '') {
2071
                     $data['class_id'] = db('work_task_class')->insertGetId($item);
2073
                     $data['class_id'] = db('work_task_class')->insertGetId($item);
2072
                 }
2074
                 }
2073
                 $dataModel = new \app\work\model\Task();
2075
                 $dataModel = new \app\work\model\Task();
2074
-                
2075
                 $data = array_merge($data, $default_data);
2076
                 $data = array_merge($data, $default_data);
2076
                 if (!$resData = $dataModel->createTask($data)) {
2077
                 if (!$resData = $dataModel->createTask($data)) {
2077
                     $error_data_func($val, $dataModel->getError());
2078
                     $error_data_func($val, $dataModel->getError());
2445
                 $this->batchTaskImportData('', $excelData);
2446
                 $this->batchTaskImportData('', $excelData);
2446
             } elseif ($base == 'ActivityImport') {
2447
             } elseif ($base == 'ActivityImport') {
2447
                 $this->ActivityImport('', $excelData);
2448
                 $this->ActivityImport('', $excelData);
2448
-            } else {
2449
+            } elseif($base == 'batchImportData') {
2449
                 $this->batchImportData('', $excelData);
2450
                 $this->batchImportData('', $excelData);
2450
             }
2451
             }
2451
             $data = 0;
2452
             $data = 0;

+ 570
- 178
application/admin/model/Field.php
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 74
- 1
application/admin/model/File.php Просмотреть файл

40
         'crm_invoice',
40
         'crm_invoice',
41
         'crm_activity',
41
         'crm_activity',
42
         'crm_visit',
42
         'crm_visit',
43
-        'crm_receivables'
43
+        'crm_receivables',
44
+        'jxc_product',
45
+        'jxc_supplier',
46
+        'jxc_purchase',
47
+        'jxc_retreat',
48
+        'jxc_sale',
49
+        'jxc_salereturn',
50
+        'jxc_receipt',
51
+        'jxc_outbound',
52
+        'jxc_payment',
53
+        'jxc_collection',
54
+        'jxc_inventory',
55
+        'jxc_allocation'
44
     ];
56
     ];
45
 	
57
 	
46
 	/**
58
 	/**
135
                             case 'crm_activity': $r = db('crm_activity_file'); $r_name = 'activity_id'; break;
147
                             case 'crm_activity': $r = db('crm_activity_file'); $r_name = 'activity_id'; break;
136
                             case 'crm_visit': $r = db('crm_visit_file'); $r_name = 'visit_id'; break;
148
                             case 'crm_visit': $r = db('crm_visit_file'); $r_name = 'visit_id'; break;
137
                             case 'crm_receivables': $r = db('crm_receivables_file'); $r_name = 'receivables_id'; break;
149
                             case 'crm_receivables': $r = db('crm_receivables_file'); $r_name = 'receivables_id'; break;
150
+                            case 'jxc_product': $r = db('jxc_product_file'); $r_name = 'product_id'; break;
151
+                            case 'jxc_supplier': $r = db('jxc_supplier_file'); $r_name = 'supplier_id'; break;
152
+                            case 'jxc_purchase': $r = db('jxc_purchase_file'); $r_name = 'purchase_id'; break;
153
+                            case 'jxc_retreat': $r = db('jxc_retreat_file'); $r_name = 'retreat_id'; break;
154
+                            case 'jxc_sale': $r = db('jxc_sale_file'); $r_name = 'sale_id'; break;
155
+                            case 'jxc_salereturn': $r = db('jxc_salereturn_file'); $r_name = 'salereturn_id'; break;
156
+                            case 'jxc_receipt': $r = db('jxc_receipt_file'); $r_name = 'receipt_id'; break;
157
+                            case 'jxc_outbound': $r = db('jxc_outbound_file'); $r_name = 'outbound_id'; break;
158
+                            case 'jxc_payment': $r = db('jxc_payment_file'); $r_name = 'payment_note_id'; break;
159
+                            case 'jxc_collection': $r = db('jxc_collection_file'); $r_name = 'collection_note_id'; break;
160
+                            case 'jxc_inventory': $r = db('jxc_inventory_file'); $r_name = 'inventory_id'; break;
161
+                            case 'jxc_allocation': $r = db('jxc_allocation_file'); $r_name = 'allocation_id'; break;
138
 		            		default : break;
162
 		            		default : break;
139
 		            	}
163
 		            	}
140
 		            	$rData = [];
164
 		            	$rData = [];
293
             case 'crm_activity' : $r = db('crm_activity_file'); $module = db('crm_activity'); break;
317
             case 'crm_activity' : $r = db('crm_activity_file'); $module = db('crm_activity'); break;
294
             case 'crm_visit' : $r = db('crm_visit_file'); $module = db('crm_visit'); break;
318
             case 'crm_visit' : $r = db('crm_visit_file'); $module = db('crm_visit'); break;
295
             case 'crm_receivables' : $r = db('crm_receivables_file'); $module = db('crm_receivables'); break;
319
             case 'crm_receivables' : $r = db('crm_receivables_file'); $module = db('crm_receivables'); break;
320
+            case 'jxc_product' : $r = db('jxc_product_file'); $module = db('jxc_product'); break;
321
+            case 'jxc_supplier' : $r = db('jxc_supplier_file'); $module = db('jxc_supplier'); break;
322
+            case 'jxc_purchase' : $r = db('jxc_purchase_file'); $module = db('jxc_purchase'); break;
323
+            case 'jxc_retreat' : $r = db('jxc_retreat_file'); $module = db('jxc_retreat'); break;
324
+            case 'jxc_sale' : $r = db('jxc_sale_file'); $module = db('jxc_sale'); break;
325
+            case 'jxc_salereturn' : $r = db('jxc_salereturn_file'); $module = db('jxc_salereturn'); break;
326
+            case 'jxc_receipt' : $r = db('jxc_receipt_file'); $module = db('jxc_receipt'); break;
327
+            case 'jxc_outbound' : $r = db('jxc_outbound_file'); $module = db('jxc_outbound'); break;
328
+            case 'jxc_payment' : $r = db('jxc_payment_file'); $module = db('jxc_payment'); break;
329
+            case 'jxc_collection' : $r = db('jxc_collection_file'); $module = db('jxc_collection'); break;
330
+            case 'jxc_inventory' : $r = db('jxc_inventory_file'); $module = db('jxc_inventory'); break;
331
+            case 'jxc_allocation' : $r = db('jxc_allocation_file'); $module = db('jxc_allocation'); break;
296
 			default : break;
332
 			default : break;
297
 		}
333
 		}
298
 		if ($r) {
334
 		if ($r) {
526
                 case 'crm_receivables' :
562
                 case 'crm_receivables' :
527
                     $r = db('crm_receivables_file');
563
                     $r = db('crm_receivables_file');
528
                     $r_name = 'receivables_id';
564
                     $r_name = 'receivables_id';
565
+
566
+                case 'jxc_product' :
567
+                    $r = db('jxc_product_file');
568
+                    $r_name = 'product_id';
569
+                case 'jxc_supplier' :
570
+                    $r = db('jxc_supplier_file');
571
+                    $r_name = 'supplier_id';
572
+                case 'jxc_purchase' :
573
+                    $r = db('jxc_purchase_file');
574
+                    $r_name = 'purchase_id';
575
+                case 'jxc_retreat' :
576
+                    $r = db('jxc_retreat_file');
577
+                    $r_name = 'retreat_id';
578
+                case 'jxc_sale' :
579
+                    $r = db('jxc_sale_file');
580
+                    $r_name = 'sale_id';
581
+                case 'jxc_salereturn':
582
+                    $r = db('jxc_salereturn_file');
583
+                    $r_name = 'salereturn_id';
584
+                case 'jxc_receipt' :
585
+                    $r = db('jxc_receipt_file');
586
+                    $r_name = 'receipt_id';
587
+                case 'jxc_outbound' :
588
+                    $r = db('jxc_outbound_file');
589
+                    $r_name = 'outbound_id';
590
+                case 'jxc_inventory' :
591
+                    $r = db('jxc_inventory_file');
592
+                    $r_name = 'inventory_id';
593
+                case 'jxc_allocation' :
594
+                    $r = db('jxc_allocation_file');
595
+                    $r_name = 'allocation_id';
596
+                case 'jxc_collection' :
597
+                    $r = db('jxc_collection_file');
598
+                    $r_name = 'collection_note_id';
599
+                case 'jxc_payment' :
600
+                    $r = db('jxc_payment_file');
601
+                    $r_name = 'payment_note_id';
529
         		default : break;
602
         		default : break;
530
         	}
603
         	}
531
         	$rWhere = [];
604
         	$rWhere = [];

+ 1
- 1
application/admin/model/LoginRecord.php Просмотреть файл

74
         $data['address'] = $ip_address['country'];
74
         $data['address'] = $ip_address['country'];
75
 
75
 
76
         // 效果图有这个备注字段,不知道存啥,就把UA记录了一下
76
         // 效果图有这个备注字段,不知道存啥,就把UA记录了一下
77
-        $data['remark'] = $_SERVER['HTTP_USER_AGENT'];
77
+//        $data['remark'] = $_SERVER['HTTP_USER_AGENT'];
78
 
78
 
79
         $this->save($data);
79
         $this->save($data);
80
     }
80
     }

+ 171
- 0
application/admin/model/Message.php Просмотреть файл

169
      * 移除队成员
169
      * 移除队成员
170
      */
170
      */
171
     const TEAM_LEADS = 32;
171
     const TEAM_LEADS = 32;
172
+    /**
173
+     * 采购单待审批
174
+     */
175
+    const PURCHASE_TO_DO = 33;
176
+    /**
177
+     * 采购单审批驳回
178
+     */
179
+    const PURCHASE_REJECT = 34;
180
+    /**
181
+     * 采购单审批通过
182
+     */
183
+    const PURCHASE_PASS = 35;
184
+    /**
185
+     * 采购退货单待审批
186
+     */
187
+    const RETREAT_TO_DO = 36;
188
+    /**
189
+     * 采购退货单审批驳回
190
+     */
191
+    const RETREAT_REJECT = 37;
192
+    /**
193
+     * 采购退货单审批通过
194
+     */
195
+    const RETREAT_PASS = 38;
196
+    /**
197
+     * 销售订单待审批
198
+     */
199
+    const SALE_TO_DO = 39;
200
+    /**
201
+     * 销售订单审批驳回
202
+     */
203
+    const SALE_REJECT = 40;
204
+    /**
205
+     * 销售订单审批通过
206
+     */
207
+    const SALE_PASS = 41;
208
+    /**
209
+     * 销售退货单待审批
210
+     */
211
+    const SALERETURN_TO_DO = 42;
212
+    /**
213
+     * 销售退货单审批驳回
214
+     */
215
+    const SALERETURN_REJECT = 43;
216
+    /**
217
+     * 销售退货单审批通过
218
+     */
219
+    const SALERETURN_PASS = 44;
220
+    /**
221
+     * 回款单待审批
222
+     */
223
+    const COLLECTION_TO_DO = 45;
224
+    /**
225
+     * 回款单审批驳回
226
+     */
227
+    const COLLECTION_REJECT = 46;
228
+    /**
229
+     * 回款单审批通过
230
+     */
231
+    const COLLECTION_PASS = 47;
232
+    /**
233
+     * 付款单待审批
234
+     */
235
+    const PAYMENT_TO_DO = 48;
236
+    /**
237
+     * 付款单审批驳回
238
+     */
239
+    const PAYMENT_REJECT = 49;
240
+    /**
241
+     * 付款单审批通过
242
+     */
243
+    const PAYMENT_PASS = 50;
244
+    /**
245
+     * 调拨待审批
246
+     */
247
+    const ALLOCATION_TO_DO = 51;
248
+    /**
249
+     * 调拨审批驳回
250
+     */
251
+    const ALLOCATION_REJECT = 52;
252
+    /**
253
+     * 调拨审批通过
254
+     */
255
+    const ALLOCATION_PASS = 53;
256
+    /**
257
+     * 盘点待审批
258
+     */
259
+    const INVENTORY_TO_DO = 54;
260
+    /**
261
+     * 盘点审批驳回
262
+     */
263
+    const INVENTORY_REJECT = 55;
264
+    /**
265
+     * 盘点审批通过
266
+     */
267
+    const INVENTORY_PASS = 56;
268
+    
172
     /**
269
     /**
173
      * 消息类型
270
      * 消息类型
174
      *
271
      *
326
             self::BUSINESS_PASS,
423
             self::BUSINESS_PASS,
327
             self::CUSTOMER_PASS,
424
             self::CUSTOMER_PASS,
328
             self::CONTRACT_END,
425
             self::CONTRACT_END,
426
+        ],
427
+        'jxc' => [
428
+            self::PURCHASE_TO_DO,
429
+            self::PURCHASE_REJECT,
430
+            self::PURCHASE_PASS,
431
+            self::RETREAT_TO_DO,
432
+            self::RETREAT_REJECT,
433
+            self::RETREAT_PASS,
434
+            self::SALE_TO_DO,
435
+            self::SALE_REJECT,
436
+            self::SALE_PASS,
437
+            self::SALERETURN_TO_DO,
438
+            self::SALERETURN_REJECT,
439
+            self::SALERETURN_PASS,
440
+            self::COLLECTION_TO_DO,
441
+            self::COLLECTION_REJECT,
442
+            self::COLLECTION_PASS,
443
+            self::PAYMENT_TO_DO,
444
+            self::PAYMENT_REJECT,
445
+            self::PAYMENT_PASS,
446
+            self::ALLOCATION_TO_DO,
447
+            self::ALLOCATION_REJECT,
448
+            self::ALLOCATION_PASS,
449
+            self::INVENTORY_TO_DO,
450
+            self::INVENTORY_REJECT,
451
+            self::INVENTORY_PASS,
329
         ]
452
         ]
330
     ];
453
     ];
331
 
454
 
468
             case self::BUSINESS_PASS:
591
             case self::BUSINESS_PASS:
469
                 return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: '';
592
                 return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: '';
470
 
593
 
594
+            // 采购单
595
+            case self::PURCHASE_TO_DO:
596
+            case self::PURCHASE_REJECT:
597
+            case self::PURCHASE_PASS:
598
+                return PurchaseModel::where(['purchase_id' => $data['action_id']])->value('order_number') ?: '';
599
+
600
+            // 采购退货单
601
+            case self::RETREAT_TO_DO:
602
+            case self::RETREAT_REJECT:
603
+            case self::RETREAT_PASS:
604
+                return RetreatModel::where(['retreat_id' => $data['action_id']])->value('order_number') ?: '';
605
+
606
+            // 销售订单
607
+            case self::SALE_TO_DO:
608
+            case self::SALE_REJECT:
609
+            case self::SALE_PASS:
610
+                return SaleModel::where(['sale_id' => $data['action_id']])->value('order_number') ?: '';
611
+
612
+            // 销售退货单订单
613
+            case self::SALERETURN_TO_DO:
614
+            case self::SALERETURN_REJECT:
615
+            case self::SALERETURN_PASS:
616
+                return SalereturnModel::where(['salereturn_id' => $data['action_id']])->value('order_number') ?: '';
617
+
618
+            // 回款单
619
+            case self::COLLECTION_TO_DO:
620
+            case self::COLLECTION_REJECT:
621
+            case self::COLLECTION_PASS:
622
+                return CollectionModel::where(['collection_note_id' => $data['action_id']])->value('collection_no') ?: '';
623
+
624
+            // 付款单
625
+            case self::PAYMENT_TO_DO:
626
+            case self::PAYMENT_REJECT:
627
+            case self::PAYMENT_PASS:
628
+                return PaymentModel::where(['payment_note_id' => $data['action_id']])->value('payment_no') ?: '';
629
+
630
+            // 调拨
631
+            case self::ALLOCATION_TO_DO:
632
+            case self::ALLOCATION_REJECT:
633
+            case self::ALLOCATION_PASS:
634
+                return PaymentModel::where(['allocation_id' => $data['action_id']])->value('allocation_code') ?: '';
635
+
636
+            // 盘点
637
+            case self::INVENTORY_TO_DO:
638
+            case self::INVENTORY_REJECT:
639
+            case self::INVENTORY_PASS:
640
+                return PaymentModel::where(['inventory_id' => $data['action_id']])->value('inventory_number') ?: '';
641
+
471
         }
642
         }
472
 
643
 
473
         return '';
644
         return '';

+ 70
- 1
application/admin/model/Scene.php Просмотреть файл

21
 	protected $updateTime = false;
21
 	protected $updateTime = false;
22
 	protected $autoWriteTimestamp = true;
22
 	protected $autoWriteTimestamp = true;
23
 
23
 
24
-	private $types_arr = ['crm_leads','crm_customer','crm_customer_pool','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit','crm_invoice']; //支持场景的分类
24
+	private $types_arr = ['crm_leads','crm_customer','crm_customer_pool','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit','crm_invoice', 'jxc_product', 'jxc_supplier', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_receipt', 'jxc_outbound', 'jxc_payment', 'jxc_collection', 'jxc_inventory', 'jxc_allocation']; //支持场景的分类
25
 
25
 
26
 	protected $type = [
26
 	protected $type = [
27
         'data'    =>  'array',
27
         'data'    =>  'array',
467
                 $map['is_end'] = ['condition' => 'is', 'value' => [2], 'form_type' => 'text'];
467
                 $map['is_end'] = ['condition' => 'is', 'value' => [2], 'form_type' => 'text'];
468
                 break;
468
                 break;
469
             case 'star' :
469
             case 'star' :
470
+                # 我的关注
470
                 $where = $this->getStarParam($types, $user_id);
471
                 $where = $this->getStarParam($types, $user_id);
471
                 if (!empty($where)) $map = $where;
472
                 if (!empty($where)) $map = $where;
472
                 break;
473
                 break;
482
                 # 下架的产品
483
                 # 下架的产品
483
                 $map['status'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'status'];
484
                 $map['status'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'status'];
484
                 break;
485
                 break;
486
+            case 'jxc_put_on_shelves' :
487
+                # 上架的产品
488
+                $map['product_ishelf'] = ['condition' => 'is', 'value' => ['上架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'product_ishelf'];
489
+                break;
490
+            case 'jxc_pull_off_shelves' :
491
+                # 下架的产品
492
+                $map['product_ishelf'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'product_ishelf'];
493
+                break;
485
     		default :
494
     		default :
486
                 # 全部
495
                 # 全部
487
     		    $auth_user_ids = '';
496
     		    $auth_user_ids = '';
488
     	}
497
     	}
498
+        if($types=='receivables_plan'){
499
+            switch ($bydata) {
500
+                case 'me' :
501
+                    # 我负责的
502
+                    $auth_user_ids[] = $user_id;
503
+                    break;
504
+                case 'sub' :
505
+                    # 下属负责的
506
+                    $auth_user_ids = getSubUserId(false, 0, $user_id) ? : ['-1'];
507
+                    break;
508
+                case 'all' :
509
+                    # 全部
510
+                    $auth_user_ids = '';
511
+                    break;
512
+                case 'not' :
513
+                    # 全部未回款
514
+                    $map['status'] = ['neq',1];
515
+                    break;
516
+                case 'not_overdue' :
517
+                    # 全部逾期未回款
518
+//                    $map['status'] =array(['neq',1],['neq',4],'or');
519
+                    $map['status'] =['neq',1];
520
+                    $map['return_date'] = ['lt',time()];
521
+                    break;
522
+                case 'not_moth' :
523
+                    # 本月到期未回款
524
+                    $timeAry = ByDateTime('month');
525
+                    $map['status'] =['neq',1];
526
+                    $map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];
527
+                    break;
528
+                case 'not_week' :
529
+                    # 本周到期未回款
530
+                    $timeAry = ByDateTime('week');
531
+                    $map['status'] =['neq',1];
532
+                    $map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];
533
+                    break;
534
+                case 'complete' :
535
+                    # 已回款
536
+                    $map['status'] =['eq',1];
537
+                    break;
538
+                case 'complete_moth' :
539
+                    # 本月已回款
540
+                    $timeAry = ByDateTime('month');
541
+                    $map['status'] =['eq',1];
542
+                    $map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];
489
 
543
 
544
+                    break;
545
+                case 'complete_week' :
546
+                    # 本周已回款
547
+                    $timeAry = ByDateTime('week');
548
+                    $map['status'] =['eq',1];
549
+                    $map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];                    break;
550
+                case 'complete_part' :
551
+                    # 部分已回
552
+                    $map['status'] = ['eq',2];
553
+                    break;
554
+                default :
555
+                    # 全部
556
+                    $auth_user_ids = '';
557
+            }
558
+        }
490
     	$auth_user_ids = $auth_user_ids ? : [];
559
     	$auth_user_ids = $auth_user_ids ? : [];
491
 
560
 
492
     	if ($auth_user_ids) {
561
     	if ($auth_user_ids) {

+ 17
- 5
application/admin/model/Structure.php Просмотреть файл

28
 	{	
28
 	{	
29
 		$cat = new \com\Category('admin_structure', array('id', 'pid', 'name', 'title'));
29
 		$cat = new \com\Category('admin_structure', array('id', 'pid', 'name', 'title'));
30
 		$data = $cat->getList('', 0, 'id');
30
 		$data = $cat->getList('', 0, 'id');
31
+        foreach ($data as $k=>$v){
32
+            $data[$k]['owner_user_name']=foreachData('admin_structure',$v['owner_user_id'])?:null;
33
+            //选择部门传入当前部门权限范围内的员工
34
+            $data[$k]['user_id']=$this->getSubUserByStructrue($v['id']);
35
+        }
31
 		// 若type为tree,则返回树状结构
36
 		// 若type为tree,则返回树状结构
32
 		if ($type == 'tree') {
37
 		if ($type == 'tree') {
33
 			$tree = new \com\Tree();
38
 			$tree = new \com\Tree();
34
 			$data = $tree->list_to_tree($data, 'id', 'pid', 'child', 0, true, array(''));
39
 			$data = $tree->list_to_tree($data, 'id', 'pid', 'child', 0, true, array(''));
35
 		}
40
 		}
36
-		
37
-		foreach ($data as $k=>$v){
38
-		    $data[$k]['owner_user_name']=foreachData('admin_structure',$v['owner_user_id'])?:null;
39
-        }
40
 		return $data;
41
 		return $data;
41
 	}
42
 	}
42
-	
43
+    //获取部门下权限范围内员工
44
+    public function getSubUserByStructrue($param)
45
+    {
46
+        $userModel = model('User');
47
+        $structureList = $userModel->getSubUserByStr($param, 1);
48
+        if ($param) {
49
+            $where['id'] = ['in', $structureList];
50
+        }
51
+        $list = Db::name('AdminUser')->field('id,realname')->where($where)->select();
52
+        $list = $list ?: array();
53
+        return $list;
54
+    }
43
 	/*
55
 	/*
44
 	*根据字符串展示参与部门 use by work
56
 	*根据字符串展示参与部门 use by work
45
 	*add by yykun
57
 	*add by yykun

+ 53
- 6
application/admin/model/User.php Просмотреть файл

80
             'name' => '岗位',
80
             'name' => '岗位',
81
             'form_type' => 'text',
81
             'form_type' => 'text',
82
             'is_null' => 0,
82
             'is_null' => 0,
83
+        ],
84
+        [
85
+            'field' => 'department',
86
+            'name' => '部门',
87
+            'form_type' => 'text',
88
+            'is_null' => 1,
83
         ]
89
         ]
84
     ];
90
     ];
85
     
91
     
274
                 $temp[$val['field']] = $param[$val['field']];
280
                 $temp[$val['field']] = $param[$val['field']];
275
             }
281
             }
276
             $param = $temp;
282
             $param = $temp;
277
-            $param['structure_id'] = 0;
283
+            $department=explode('/',$param['department']);
284
+            $pid=1;
285
+                foreach ($department as $k => $v){
286
+                    $structure=db('admin_structure')->where('name',$v)->find();
287
+                    if(empty($structure)){
288
+                        $id=db('admin_structure')->insertGetId(['name'=>$v,'pid'=>$pid]);
289
+                        $pid=$id;
290
+                    }else{
291
+                        $pid=$structure['id'];
292
+                    }
293
+            }
294
+            $param['structure_id'] = $pid;
278
             if (db('admin_user')->where('username', $param['username'])->find()) {
295
             if (db('admin_user')->where('username', $param['username'])->find()) {
279
                 $this->error = '手机号已存在';
296
                 $this->error = '手机号已存在';
280
                 return false;
297
                 return false;
457
                     }
474
                     }
458
                     $param['realname'] = $name;
475
                     $param['realname'] = $name;
459
                 }
476
                 }
477
+                $department=explode('/',$param['department']);
478
+                $pid=1;
479
+                foreach ($department as $k => $v){
480
+                    $structure=db('admin_structure')->where('name',$v)->find();
481
+                    if(empty($structure)){
482
+                        $id=db('admin_structure')->insertGetId(['name'=>$v,'pid'=>$pid]);
483
+                        $pid=$id;
484
+                    }else{
485
+                        $pid=$structure['id'];
486
+                    }
487
+                }
488
+                $param['structure_id'] = $pid;
460
                 $param['userId']=!empty($param['create_user_id'])?:$param['owner_user_id'];
489
                 $param['userId']=!empty($param['create_user_id'])?:$param['owner_user_id'];
461
                 unset($param['owner_user_id']);
490
                 unset($param['owner_user_id']);
462
                 unset($param['create_user_id']);
491
                 unset($param['create_user_id']);
755
             if ($v['name'] == 'market') {
784
             if ($v['name'] == 'market') {
756
                 $rules[$k]['name'] = 'activityForm';
785
                 $rules[$k]['name'] = 'activityForm';
757
             }
786
             }
787
+            if($v['name'] == 'warehouseProduct'){
788
+                $rules[$k]['name'] = 'warehouseProduct';
789
+            }
758
         }
790
         }
791
+        // p($rules);die();
759
         //菜单管理(弃用)
792
         //菜单管理(弃用)
760
         // $menuMap['status'] = 1;
793
         // $menuMap['status'] = 1;
761
         // $menuMap['rule_id'] = array('in',$newRuleIds);
794
         // $menuMap['rule_id'] = array('in',$newRuleIds);
765
         $tree = new \com\Tree();
798
         $tree = new \com\Tree();
766
         //处理规则成树状
799
         //处理规则成树状
767
         $rulesList = $tree->list_to_tree($rules, 'id', 'pid', 'child', 0, true, array('pid'));
800
         $rulesList = $tree->list_to_tree($rules, 'id', 'pid', 'child', 0, true, array('pid'));
801
+
768
         //权限数组
802
         //权限数组
769
         $authList = rulesListToArray($rulesList, $newRuleIds);
803
         $authList = rulesListToArray($rulesList, $newRuleIds);
770
         //应用控制
804
         //应用控制
817
         if (in_array('calendar', $adminConfig)) {
851
         if (in_array('calendar', $adminConfig)) {
818
             $authList['oa']['calendar'] = (object)[];
852
             $authList['oa']['calendar'] = (object)[];
819
         }
853
         }
854
+        # 进销存
855
+        if (in_array('jxc', $adminConfig)) {
856
+            $authList['jxc']['field'] = (object)[];
857
+            $authList['jxc']['params'] = (object)[];
858
+        }
820
         # 公海权限
859
         # 公海权限
821
         $structureId = db('admin_user')->where('id', $u_id)->value('structure_id');
860
         $structureId = db('admin_user')->where('id', $u_id)->value('structure_id');
822
         $poolStatus = db('crm_customer_pool')->where('status', 1)->where(function ($requery) use ($u_id, $structureId, $adminTypes) {
861
         $poolStatus = db('crm_customer_pool')->where('status', 1)->where(function ($requery) use ($u_id, $structureId, $adminTypes) {
825
             if (!in_array(1, $adminTypes)) $requery->whereOr('department_ids', 'like', '%,' . $structureId . ',%');
864
             if (!in_array(1, $adminTypes)) $requery->whereOr('department_ids', 'like', '%,' . $structureId . ',%');
826
         })->value('pool_id');
865
         })->value('pool_id');
827
         if (!empty($poolStatus)) $authList['crm']['pool'] = ['index' => true];
866
         if (!empty($poolStatus)) $authList['crm']['pool'] = ['index' => true];
828
-        
867
+
829
         $ret['authList'] = $this->resetAuthorityFiled($authList);
868
         $ret['authList'] = $this->resetAuthorityFiled($authList);
869
+
830
         $res['manage'] = $rules;
870
         $res['manage'] = $rules;
831
         return $ret;
871
         return $ret;
832
     }
872
     }
988
         
1028
         
989
         $authList['email'] = (object)[];
1029
         $authList['email'] = (object)[];
990
         $authList['hrm'] = (object)[];
1030
         $authList['hrm'] = (object)[];
991
-        $authList['jxc'] = (object)[];
1031
+        // $authList['jxc'] = (object)[];
1032
+        # jxc
1033
+        $authList['manage']['jxc']['field'] = true;
1034
+        $authList['manage']['jxc']['params'] = true;
1035
+        
992
         $authList['knowledge'] = (object)[];
1036
         $authList['knowledge'] = (object)[];
993
         
1037
         
994
         return $authList;
1038
         return $authList;
1084
      */
1128
      */
1085
     public function getSubUserByStr($structure_id, $type = 1)
1129
     public function getSubUserByStr($structure_id, $type = 1)
1086
     {
1130
     {
1131
+        // p($structure_id);die;
1087
         $allStrIds = (array)$structure_id;
1132
         $allStrIds = (array)$structure_id;
1088
         if ($type == 2) {
1133
         if ($type == 2) {
1089
             $structureModel = new \app\admin\model\Structure();
1134
             $structureModel = new \app\admin\model\Structure();
1433
         foreach ($ids as $v) {
1478
         foreach ($ids as $v) {
1434
             $data['id'] = $v;
1479
             $data['id'] = $v;
1435
             $data['structure_id'] = $param['structure_id'];
1480
             $data['structure_id'] = $param['structure_id'];
1436
-            $flag = foreachData('', $data);
1481
+            $flag=$this->isUpdate(true)->save($data);
1482
+//            $flag = foreachData('', $data);
1483
+//            p(Db::name('AdminUser')->getLastSql());
1437
         }
1484
         }
1438
-        if ($flag) {
1439
-            return $flag;
1485
+        if ($flag!==false) {
1486
+            return  1;
1440
         } else {
1487
         } else {
1441
             $this->error = '修改失败,请稍后重试';
1488
             $this->error = '修改失败,请稍后重试';
1442
             return false;
1489
             return false;

+ 79
- 50
application/admin/traits/FieldVerificationTrait.php Просмотреть файл

2
 /**
2
 /**
3
  * 字段验证(线索、客户、联系人、商机、合同、回款、回访、产品、办公审批)
3
  * 字段验证(线索、客户、联系人、商机、合同、回款、回访、产品、办公审批)
4
  */
4
  */
5
+
5
 namespace app\admin\traits;
6
 namespace app\admin\traits;
6
 
7
 
7
 trait FieldVerificationTrait
8
 trait FieldVerificationTrait
15
      * @param string $types 自定义表栏目类型:crm_leads、crm_customer ...
16
      * @param string $types 自定义表栏目类型:crm_leads、crm_customer ...
16
      * @param int $dataId 编辑时,相应的模块数据的ID
17
      * @param int $dataId 编辑时,相应的模块数据的ID
17
      * @param int $typesId 自定义表栏目类型ID
18
      * @param int $typesId 自定义表栏目类型ID
18
-     * @author fanqi
19
-     * @since 2021-05-18
20
      * @return string
19
      * @return string
20
+     * @since 2021-05-18
21
+     * @author fanqi
21
      */
22
      */
22
     public function fieldDataValidate($param, $types, $userId, $dataId = 0, $typesId = 0)
23
     public function fieldDataValidate($param, $types, $userId, $dataId = 0, $typesId = 0)
23
     {
24
     {
28
 
29
 
29
         # 查询自定义字段表数据
30
         # 查询自定义字段表数据
30
         $fieldList = $this->getFieldList($types, $typesId);
31
         $fieldList = $this->getFieldList($types, $typesId);
31
-
32
         # 验证
32
         # 验证
33
-        foreach ($fieldList AS $key => $value) {
33
+        foreach ($fieldList as $key => $value) {
34
+
34
             # 字段授权,没有读写权限,跳过验证。
35
             # 字段授权,没有读写权限,跳过验证。
35
             if (!$userLevel && !empty($grantData[$types])) {
36
             if (!$userLevel && !empty($grantData[$types])) {
36
                 $status = getFieldGrantStatus($value['field'], $grantData[$types]);
37
                 $status = getFieldGrantStatus($value['field'], $grantData[$types]);
37
 
38
 
38
                 if (empty($status['read']) || (empty($dataId) && empty($status['write']))) continue;
39
                 if (empty($status['read']) || (empty($dataId) && empty($status['write']))) continue;
39
             }
40
             }
40
-
41
             # 验证非明细表格字段数据
41
             # 验证非明细表格字段数据
42
-            if (!empty($value['is_null']) && !in_array($value['form_type'], ['detail_table', 'boolean_value']) && (isset($param[$value['field']]) && empty($param[$value['field']]))) {
42
+            if ($value['form_type'] != 'detail_table' && !empty($value['is_null']) && !in_array($value['form_type'], ['detail_table', 'boolean_value']) && (isset($param[$value['field']]) && empty($param[$value['field']]))) {
43
+
43
                 $error = $value['name'] . '字段不能为空!';
44
                 $error = $value['name'] . '字段不能为空!';
44
                 break;
45
                 break;
45
             }
46
             }
62
                 break;
63
                 break;
63
             }
64
             }
64
 
65
 
66
+            
65
             # 验证明细表格不能为空
67
             # 验证明细表格不能为空
66
             if (!empty($value['is_null']) && $value['form_type'] == 'detail_table' && isset($param[$value['field']]) && empty($param[$value['field']])) {
68
             if (!empty($value['is_null']) && $value['form_type'] == 'detail_table' && isset($param[$value['field']]) && empty($param[$value['field']])) {
67
                 $error = $value['name'] . '数据不能为空!';
69
                 $error = $value['name'] . '数据不能为空!';
68
             }
70
             }
69
             # 验证明细表格可以为空,明细表格里的字段不能为空的情况。
71
             # 验证明细表格可以为空,明细表格里的字段不能为空的情况。
70
             if ($value['form_type'] == 'detail_table') {
72
             if ($value['form_type'] == 'detail_table') {
71
-                foreach ($param[$value['field']] AS $val) {
72
-                    foreach ($val AS $v) {
73
-                        if (!empty($v['is_null']) && empty($v['is_hidden']) && isset($v['value']) && empty($v['value'])) {
73
+                foreach ($param[$value['field']] as $val) {
74
+                    foreach ($val as $v) {
75
+                        if ($v['form_type']!='boolean_value' && !empty($v['is_null']) && empty($v['is_hidden']) && isset($v['value']) && empty($v['value'])) {
74
                             $error = $value['name'] . '中的' . $v['name'] . '字段不能为空!';
76
                             $error = $value['name'] . '中的' . $v['name'] . '字段不能为空!';
75
                             break;
77
                             break;
76
                         }
78
                         }
77
                     }
79
                     }
78
                 }
80
                 }
79
             }
81
             }
80
-
81
             if (empty($value['is_unique'])) continue;
82
             if (empty($value['is_unique'])) continue;
82
 
83
 
83
             // 人员、部门、文件、手写签名、描述文字、多选、明细表格跳过验证
84
             // 人员、部门、文件、手写签名、描述文字、多选、明细表格跳过验证
84
-            if (in_array($value['form_type'], ['user', 'structure', 'file', 'handwriting_sign', 'desc_text', 'checkbox', 'detail_table'])) continue;
85
-
85
+            if (in_array($value['form_type'], ['file', 'handwriting_sign', 'desc_text', 'checkbox', 'detail_table'])) continue;
86
             $uniqueStatus = false;
86
             $uniqueStatus = false;
87
-
88
             # 验证唯一性
87
             # 验证唯一性
89
             if ($value['form_type'] == 'date_interval' && !empty($param[$value['field']])) {
88
             if ($value['form_type'] == 'date_interval' && !empty($param[$value['field']])) {
90
                 // 日期区间
89
                 // 日期区间
95
             } elseif ($value['form_type'] == 'location' && !empty($param[$value['field']])) {
94
             } elseif ($value['form_type'] == 'location' && !empty($param[$value['field']])) {
96
                 // 定位
95
                 // 定位
97
                 $uniqueStatus = $this->checkDataUniqueForLocation($types, $value['field'], $param[$value['field']], $dataId);
96
                 $uniqueStatus = $this->checkDataUniqueForLocation($types, $value['field'], $param[$value['field']], $dataId);
97
+            } elseif ($value['form_type'] == 'user' && !empty($param[$value['field']])) {
98
+                // 人员
99
+                $uniqueStatus = $this->checkDataUniqueForUser($types, $value['field'], $param[$value['field']], $dataId);
100
+            } elseif ($value['form_type'] == 'structure' && !empty($param[$value['field']])) {
101
+                // 部门
102
+                $uniqueStatus = $this->checkDataUniqueForStructure($types, $value['field'], $param[$value['field']], $dataId);
98
             } else {
103
             } else {
99
                 if (!empty($param[$value['field']])) $uniqueStatus = $this->checkDataUniqueForCommon($types, $value['field'], $param[$value['field']], $dataId);
104
                 if (!empty($param[$value['field']])) $uniqueStatus = $this->checkDataUniqueForCommon($types, $value['field'], $param[$value['field']], $dataId);
105
+
100
             }
106
             }
101
 
107
 
102
             if (!empty($uniqueStatus)) {
108
             if (!empty($uniqueStatus)) {
104
                 break;
110
                 break;
105
             }
111
             }
106
         }
112
         }
107
-
108
         return $error;
113
         return $error;
109
     }
114
     }
110
 
115
 
117
      * @param string $field 字段名称
122
      * @param string $field 字段名称
118
      * @param string $value 字段值
123
      * @param string $value 字段值
119
      * @param int $dataId 更新时,传来的数据ID
124
      * @param int $dataId 更新时,传来的数据ID
120
-     * @author fanqi
121
-     * @since 2021-05-18
122
      * @return float|mixed|string
125
      * @return float|mixed|string
126
+     * @since 2021-05-18
127
+     * @author fanqi
123
      */
128
      */
124
     private function checkDataUniqueForCommon($types, $field, $value, $dataId = 0)
129
     private function checkDataUniqueForCommon($types, $field, $value, $dataId = 0)
125
     {
130
     {
142
      * @param string $field 字段名称
147
      * @param string $field 字段名称
143
      * @param array $value 字段值
148
      * @param array $value 字段值
144
      * @param int $dataId 更新时,传来的数据ID
149
      * @param int $dataId 更新时,传来的数据ID
145
-     * @author fanqi
146
-     * @since 2021-05-18
147
      * @return float|mixed|string
150
      * @return float|mixed|string
151
+     * @since 2021-05-18
152
+     * @author fanqi
148
      */
153
      */
149
     private function checkDataUniqueForDateInterval($types, $field, $value, $dataId = 0)
154
     private function checkDataUniqueForDateInterval($types, $field, $value, $dataId = 0)
150
     {
155
     {
167
      * @param string $field 字段名称
172
      * @param string $field 字段名称
168
      * @param array $value 字段值
173
      * @param array $value 字段值
169
      * @param int $dataId 更新时,传来的数据ID
174
      * @param int $dataId 更新时,传来的数据ID
170
-     * @author fanqi
171
-     * @since 2021-05-18
172
      * @return float|mixed|string
175
      * @return float|mixed|string
176
+     * @since 2021-05-18
177
+     * @author fanqi
173
      */
178
      */
174
     private function checkDataUniqueForPosition($types, $field, $value, $dataId = 0)
179
     private function checkDataUniqueForPosition($types, $field, $value, $dataId = 0)
175
     {
180
     {
192
      * @param string $field 字段名称
197
      * @param string $field 字段名称
193
      * @param array $value 字段值
198
      * @param array $value 字段值
194
      * @param int $dataId 更新时,传来的数据ID
199
      * @param int $dataId 更新时,传来的数据ID
195
-     * @author fanqi
196
-     * @since 2021-05-18
197
      * @return float|mixed|string
200
      * @return float|mixed|string
201
+     * @since 2021-05-18
202
+     * @author fanqi
198
      */
203
      */
199
     private function checkDataUniqueForLocation($types, $field, $value, $dataId = 0)
204
     private function checkDataUniqueForLocation($types, $field, $value, $dataId = 0)
200
     {
205
     {
210
         return db($types)->where($where)->value($primaryKey);
215
         return db($types)->where($where)->value($primaryKey);
211
     }
216
     }
212
 
217
 
213
-//    /**
214
-//     * 验证唯一性(部门)
215
-//     *
216
-//     * @param string $types 栏目类型
217
-//     * @param string $field 字段名称
218
-//     * @param string $value 字段值
219
-//     * @param int $dataId 更新时,传来的数据ID
220
-//     * @author fanqi
221
-//     * @since 2021-05-18
222
-//     * @return float|mixed|string
223
-//     */
224
-//    private function checkDataUniqueForStructure($types, $field, $value, $dataId = 0)
225
-//    {
226
-//        if (empty($value)) return false;
227
-//
228
-//        # 主键
229
-//        $primaryKey = getPrimaryKeyName($types);
230
-//
231
-//        # 查询条件
232
-//        $where[$field] = ',' . $value . ',';
233
-//        if (!empty($dataId)) $where[$primaryKey] = ['neq', $dataId];
234
-//
235
-//        return db($types)->where($where)->value($primaryKey);
236
-//    }
218
+    /**
219
+     * 验证唯一性(部门)
220
+     *
221
+     * @param string $types 栏目类型
222
+     * @param string $field 字段名称
223
+     * @param string $value 字段值
224
+     * @param int $dataId 更新时,传来的数据ID
225
+     * @return float|mixed|string
226
+     * @since 2021-05-18
227
+     * @author fanqi
228
+     */
229
+    private function checkDataUniqueForStructure($types, $field, $value, $dataId = 0)
230
+    {
231
+        if (empty($value)) return false;
232
+
233
+        # 主键
234
+        $primaryKey = getPrimaryKeyName($types);
235
+
236
+        # 查询条件
237
+        $where[$field] = ',' . $value . ',';
238
+        if (!empty($dataId)) $where[$primaryKey] = ['neq', $dataId];
239
+
240
+        return db($types)->where($where)->value($primaryKey);
241
+    }
242
+
243
+    /**
244
+     * @param $types 栏目类型
245
+     * @param $field 字段名称
246
+     * @param $value 字段值
247
+     * @param int $dataId 更新时,传来的数据ID
248
+     * @return false|float|mixed|string|null
249
+     * @since 2021-05-18
250
+     * @author fanqi
251
+     */
252
+    private function checkDataUniqueForUser($types, $field, $value, $dataId = 0)
253
+    {
254
+        if (empty($value)) return false;
255
+
256
+        # 主键
257
+        $primaryKey = getPrimaryKeyName($types);
258
+
259
+        # 查询条件
260
+        $where[$field] = ',' . $value . ',';
261
+        if (!empty($dataId)) $where[$primaryKey] = ['neq', $dataId];
262
+
263
+        return db($types)->where($where)->value($primaryKey);
264
+    }
237
 
265
 
238
     /**
266
     /**
239
      * 自定义字段列表
267
      * 自定义字段列表
240
      *
268
      *
241
      * @param string $types 自定义表栏目类型:crm_leads、crm_customer ...
269
      * @param string $types 自定义表栏目类型:crm_leads、crm_customer ...
242
      * @param int $typesId 自定义表栏目类型ID
270
      * @param int $typesId 自定义表栏目类型ID
243
-     * @author fanqi
244
-     * @since 2021-05-18
245
      * @return bool|\PDOStatement|string|\think\Collection
271
      * @return bool|\PDOStatement|string|\think\Collection
272
+     * @since 2021-05-18
273
+     * @author fanqi
246
      */
274
      */
247
     private function getFieldList($types, $typesId)
275
     private function getFieldList($types, $typesId)
248
     {
276
     {
249
         # 查询条件
277
         # 查询条件
250
         $where = [
278
         $where = [
251
-            'types'     => $types,
252
-            'types_id'  => $typesId,
279
+            'types' => $types,
280
+            'types_id' => $typesId,
253
             'is_hidden' => 0,
281
             'is_hidden' => 0,
254
             'form_type' => ['neq', 'desc_text']
282
             'form_type' => ['neq', 'desc_text']
255
         ];
283
         ];
259
 
287
 
260
         return db('admin_field')->field($fields)->where($where)->select();
288
         return db('admin_field')->field($fields)->where($where)->select();
261
     }
289
     }
290
+
262
 }
291
 }

+ 203
- 137
application/common.php Просмотреть файл

136
     //查询自定义字段模块多选字段类型
136
     //查询自定义字段模块多选字段类型
137
     $check_field_arr = [];
137
     $check_field_arr = [];
138
     //特殊字段
138
     //特殊字段
139
-    
139
+
140
     //过滤系统参数
140
     //过滤系统参数
141
     $unset_arr = ['page', 'limit', 'order_type', 'order_field'];
141
     $unset_arr = ['page', 'limit', 'order_type', 'order_field'];
142
     if (!is_array($array)) {
142
     if (!is_array($array)) {
307
             }
307
             }
308
         }
308
         }
309
     }
309
     }
310
-    
310
+
311
     # 商机阶段为赢单、输单、无效的值保存在is_end中,将status_id改为is_end;
311
     # 商机阶段为赢单、输单、无效的值保存在is_end中,将status_id改为is_end;
312
     if (!empty($where['business.status_id']) && in_array($where['business.status_id'][1], [1, 2, 3])) {
312
     if (!empty($where['business.status_id']) && in_array($where['business.status_id'][1], [1, 2, 3])) {
313
         $where['business.is_end'] = $where['business.status_id'];
313
         $where['business.is_end'] = $where['business.status_id'];
314
         unset($where['business.status_id']);
314
         unset($where['business.status_id']);
315
     }
315
     }
316
-    
316
+
317
     return $where ?: [];
317
     return $where ?: [];
318
 }
318
 }
319
 
319
 
340
         'nextQuarter', 'month', 'lastMonth', 'nextMonth', 'week', 'lastWeek', 'nextWeek', 'today',
340
         'nextQuarter', 'month', 'lastMonth', 'nextMonth', 'week', 'lastWeek', 'nextWeek', 'today',
341
         'yesterday', 'tomorrow', 'previous7day', 'previous30day', 'future7day', 'future30day'
341
         'yesterday', 'tomorrow', 'previous7day', 'previous30day', 'future7day', 'future30day'
342
     ];
342
     ];
343
+
343
     foreach ($param as $key => $value) {
344
     foreach ($param as $key => $value) {
344
         // 过滤不能参与搜索的字段类型
345
         // 过滤不能参与搜索的字段类型
345
         if (!empty($value['form_type']) && in_array($value['form_type'], ['file', 'handwriting_sign', 'desc_text', 'detail_table', 'date_interval'])) continue;
346
         if (!empty($value['form_type']) && in_array($value['form_type'], ['file', 'handwriting_sign', 'desc_text', 'detail_table', 'date_interval'])) continue;
351
         list($c, $key) = advancedQueryParam($c, $key, $value['name']);
352
         list($c, $key) = advancedQueryParam($c, $key, $value['name']);
352
 
353
 
353
         if ($key == 'check_status' && !is_array($value)) $result[$c . $key] = $value;
354
         if ($key == 'check_status' && !is_array($value)) $result[$c . $key] = $value;
354
-        if ($key == 'status_id' && !is_array($value))    $result[$c . $key] = $value;
355
-        if ($key == 'customer_id' && !is_array($value))  $result['customer.' . $key] = $value;
356
-        if ($key == 'contract_id' && !is_array($value))  $result['contract.' . $key] = $value;
357
-        if ($key == 'business_id' && !is_array($value))  $result['business.' . $key] = $value;
358
-        
355
+        if ($key == 'status_id' && !is_array($value)) $result[$c . $key] = $value;
356
+        if ($key == 'customer_id' && !is_array($value)) $result['customer.' . $key] = $value;
357
+        if ($key == 'contract_id' && !is_array($value)) $result['contract.' . $key] = $value;
358
+        if ($key == 'business_id' && !is_array($value)) $result['business.' . $key] = $value;
359
+
359
         // 仪表盘参数
360
         // 仪表盘参数
360
         if (!empty($value['value'][0]) && empty($value['condition'])) {
361
         if (!empty($value['value'][0]) && empty($value['condition'])) {
361
             $value['condition'] = 'is';
362
             $value['condition'] = 'is';
375
             $value['type'] = 'check_status';
376
             $value['type'] = 'check_status';
376
             $value['condition'] = 'is';
377
             $value['condition'] = 'is';
377
         }
378
         }
378
-        
379
-        if (!empty($value['value'][0]) && in_array($value['value'][0], $betweenType)) {
380
-            $value = advancedQueryHandleDate($value);
381
-        }
382
-        
379
+
383
         // 代办事项
380
         // 代办事项
384
         if (isset($value) && !isset($value['condition']) && !isset($value['value']) && !isset($value['form_type'])) {
381
         if (isset($value) && !isset($value['condition']) && !isset($value['value']) && !isset($value['form_type'])) {
385
             $result[$c . $key] = is_array($value) ? $value : ['in', $value];
382
             $result[$c . $key] = is_array($value) ? $value : ['in', $value];
386
             continue;
383
             continue;
387
         }
384
         }
388
-        
385
+
386
+        // 等于(时间段)类型筛选
387
+        if (!empty($value['value'][0]) && in_array($value['value'][0], $betweenType)) {
388
+            $value = advancedQueryHandleDate($value);
389
+        }
390
+
391
+        // 创建人、负责人
392
+        if (in_array($key, ['create_user_id', 'owner_user_id'])) {
393
+            if($value['condition'] == 'contains'){
394
+                $result[$c . $key] = ['in', $value['value']];
395
+            }else if ($value['condition'] == 'notContains') {
396
+               $result[$c . $key] = ['not in', $value['value']];
397
+            }else if ($value['condition'] == 'isNull') {
398
+               $result[$c . $key] = ['eq', ''];
399
+            }else if ($value['condition'] == 'isNotNull') {
400
+               $result[$c . $key] = ['neq', ''];
401
+            }
402
+        }
403
+
389
         // 模块、审核状态、成交状态、产品分类、单行文本、多行文本、网址、手机、邮箱、下拉框、布尔值、多选、定位、创建人、负责人
404
         // 模块、审核状态、成交状态、产品分类、单行文本、多行文本、网址、手机、邮箱、下拉框、布尔值、多选、定位、创建人、负责人
390
-        if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website']) || in_array($key, ['create_user_id', 'owner_user_id'])) {
405
+        if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website','user',])) {
391
             $result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
406
             $result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
392
         }
407
         }
393
-        
408
+
394
         // 日期、日期时间、数字、货币、百分数、下次联系时间
409
         // 日期、日期时间、数字、货币、百分数、下次联系时间
395
         if (isset($value['form_type']) && in_array($value['form_type'], ['date', 'datetime', 'number', 'floatnumber', 'percent', 'next_time'])) {
410
         if (isset($value['form_type']) && in_array($value['form_type'], ['date', 'datetime', 'number', 'floatnumber', 'percent', 'next_time'])) {
396
             $result[$c . $key] = advancedQueryFormatForDate($value);
411
             $result[$c . $key] = advancedQueryFormatForDate($value);
397
         }
412
         }
398
-        
413
+
399
         // 地址(固定字段)、地址(自定义字段)
414
         // 地址(固定字段)、地址(自定义字段)
400
         if (isset($value['form_type']) && in_array($value['form_type'], ['map_address', 'position'])) {
415
         if (isset($value['form_type']) && in_array($value['form_type'], ['map_address', 'position'])) {
401
             $result[$c . $key] = advancedQueryFormatForAddress($value['value'], $value['form_type']);
416
             $result[$c . $key] = advancedQueryFormatForAddress($value['value'], $value['form_type']);
402
         }
417
         }
418
+
403
         // 人员、部门
419
         // 人员、部门
404
         if (isset($value['form_type']) && in_array($value['form_type'], ['user', 'structure', 'single_user']) && !in_array($key, ['create_user_id', 'owner_user_id']) && $value['type'] != 'team_id') {
420
         if (isset($value['form_type']) && in_array($value['form_type'], ['user', 'structure', 'single_user']) && !in_array($key, ['create_user_id', 'owner_user_id']) && $value['type'] != 'team_id') {
405
-            $result[$c . $key] = advancedQueryFormatForPersonnel($value['value'], $value['condition']);
421
+            if ($value['type'] == 'owner_structure') { # 所属部门
422
+                $userIds = db('admin_user')->whereIn('structure_id', implode(',', $value['value']))->column('id');
423
+                $result[$c . 'owner_user_id'] = ['in', $userIds];
424
+            } else {
425
+                $result[$c . $key] = advancedQueryFormatForPersonnel($value['value'], $value['condition']);
426
+            }
406
         }
427
         }
407
-        
408
         // 商机状态组
428
         // 商机状态组
409
         if (isset($value['form_type']) && $value['form_type'] == 'business_type') {
429
         if (isset($value['form_type']) && $value['form_type'] == 'business_type') {
410
             if (!empty($value['type_id'])) $result[$c . 'type_id'] = ['eq', $value['type_id']];
430
             if (!empty($value['type_id'])) $result[$c . 'type_id'] = ['eq', $value['type_id']];
411
             if (!empty($value['status_id']) && in_array($value['status_id'], [1, 2, 3])) $result[$c . 'is_end'] = ['eq', $value['status_id']];
431
             if (!empty($value['status_id']) && in_array($value['status_id'], [1, 2, 3])) $result[$c . 'is_end'] = ['eq', $value['status_id']];
412
             if (!empty($value['status_id']) && !in_array($value['status_id'], [1, 2, 3])) $result[$c . 'status_id'] = ['eq', $value['status_id']];
432
             if (!empty($value['status_id']) && !in_array($value['status_id'], [1, 2, 3])) $result[$c . 'status_id'] = ['eq', $value['status_id']];
413
         }
433
         }
414
-        
434
+
415
         // 回款计划
435
         // 回款计划
416
         if (isset($value['form_type']) && $value['form_type'] == 'receivables_plan' && !empty($value['value'])) {
436
         if (isset($value['form_type']) && $value['form_type'] == 'receivables_plan' && !empty($value['value'])) {
417
             $result[$c . 'plan_id'] = advancedQueryFormatForPlan($value['value']);
437
             $result[$c . 'plan_id'] = advancedQueryFormatForPlan($value['value']);
441
         'business_id' => 'business.',
461
         'business_id' => 'business.',
442
         'contacts_id' => 'contacts.'
462
         'contacts_id' => 'contacts.'
443
     ];
463
     ];
444
-    
464
+
445
     // 处理客户名称、联系人名称、商机名称、合同名称字段
465
     // 处理客户名称、联系人名称、商机名称、合同名称字段
446
     if (in_array($field, ['customer_name', 'contacts_name', 'business_name', 'contract_name']) && $name != '合同编号') {
466
     if (in_array($field, ['customer_name', 'contacts_name', 'business_name', 'contract_name']) && $name != '合同编号') {
447
         $prefix = $prefixChange[$field];
467
         $prefix = $prefixChange[$field];
462
         $prefix = 'contacts.';
482
         $prefix = 'contacts.';
463
         $field = 'name';
483
         $field = 'name';
464
     }
484
     }
465
-    
485
+
466
     return [$prefix, $field];
486
     return [$prefix, $field];
467
 }
487
 }
468
 
488
 
477
 function advancedQueryFormatForPlan($data)
497
 function advancedQueryFormatForPlan($data)
478
 {
498
 {
479
     $result = [];
499
     $result = [];
480
-    
500
+
481
     $planIds = db('crm_receivables_plan')->whereIn('num', $data)->column('plan_id');
501
     $planIds = db('crm_receivables_plan')->whereIn('num', $data)->column('plan_id');
482
-    
502
+
483
     if (!empty($planIds)) $result = ['in', $planIds];
503
     if (!empty($planIds)) $result = ['in', $planIds];
484
-    
504
+
485
     return $result;
505
     return $result;
486
 }
506
 }
487
 
507
 
501
         $data = array_filter(array_column($data[0], 'name'));
521
         $data = array_filter(array_column($data[0], 'name'));
502
         $data = implode(',', $data);
522
         $data = implode(',', $data);
503
     }
523
     }
504
-    
524
+
505
     return ['like', '%' . trim($data) . '%'];
525
     return ['like', '%' . trim($data) . '%'];
506
 }
526
 }
507
 
527
 
517
     // 处理查询条件
537
     // 处理查询条件
518
     if ($condition == 'is') $condition = 'contains';
538
     if ($condition == 'is') $condition = 'contains';
519
     if ($condition == 'isNot') $condition = 'notContains';
539
     if ($condition == 'isNot') $condition = 'notContains';
520
-    
540
+
521
     // 处理查询参数
541
     // 处理查询参数
522
-    $data = advancedQueryDataTransform($data, $condition);
523
-    
542
+    if (in_array($condition, ['contains', 'notContains'])) {
543
+        array_walk($data, function ($value, $key) use (&$data) {
544
+            $data[$key] = '%,' . $value . ',%';
545
+        });
546
+    }
547
+
524
     // 搜索条件
548
     // 搜索条件
525
     return advancedQueryWhere($condition, $data);
549
     return advancedQueryWhere($condition, $data);
526
 }
550
 }
538
     # 转换日期时间类型格式
562
     # 转换日期时间类型格式
539
     if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][0])) $data['value'][0] = strtotime($data['value'][0]);
563
     if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][0])) $data['value'][0] = strtotime($data['value'][0]);
540
     if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][1])) $data['value'][1] = strtotime($data['value'][1]);
564
     if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][1])) $data['value'][1] = strtotime($data['value'][1]);
541
-    
565
+
542
     return advancedQueryWhere($data['condition'], count($data['value']) == 2 ? $data['value'] : $data['value'][0]);
566
     return advancedQueryWhere($data['condition'], count($data['value']) == 2 ? $data['value'] : $data['value'][0]);
543
 }
567
 }
544
 
568
 
557
     // 处理查询方式
581
     // 处理查询方式
558
     if (in_array($formType, ['checkbox']) && $condition == 'is') $condition = 'contains';
582
     if (in_array($formType, ['checkbox']) && $condition == 'is') $condition = 'contains';
559
     if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains';
583
     if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains';
560
-    
584
+
561
     // 处理查询参数
585
     // 处理查询参数
562
-    if (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])) $data = advancedQueryDataTransform($data, $condition);
563
-    
586
+    if(in_array($condition, ['contains', 'notContains']) && in_array($key,['create_user_id','owner_user_id'])){
587
+        $data = advancedQueryDataUserform($data, $condition);
588
+    }elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])){
589
+        $data = advancedQueryDataTransform($data, $condition);
590
+    }
591
+
564
     // 处理回访形式
592
     // 处理回访形式
565
     if (in_array($key, ['shape', 'satisfaction'])) {
593
     if (in_array($key, ['shape', 'satisfaction'])) {
566
         array_walk($data, function ($value, $key) use (&$data) {
594
         array_walk($data, function ($value, $key) use (&$data) {
567
             $data[$key] = $value . "\r";
595
             $data[$key] = $value . "\r";
568
         });
596
         });
569
     }
597
     }
570
-    
598
+
571
     // 处理审核状态
599
     // 处理审核状态
572
     if ($formType == 'check_status') {
600
     if ($formType == 'check_status') {
573
         $data[0] = str_replace('待审核', 0, $data[0]);
601
         $data[0] = str_replace('待审核', 0, $data[0]);
578
         $data[0] = str_replace('未提交', 5, $data[0]);
606
         $data[0] = str_replace('未提交', 5, $data[0]);
579
         $data[0] = str_replace('已作废', 6, $data[0]);
607
         $data[0] = str_replace('已作废', 6, $data[0]);
580
     }
608
     }
581
-    
582
-    return advancedQueryWhere($condition, $data);
609
+
610
+    return advancedQueryWhere($condition, $data,$key);
583
 }
611
 }
584
 
612
 
585
 /**
613
 /**
586
  * 设置搜索条件
614
  * 设置搜索条件
587
  *
615
  *
588
  * @param string $condition 查询方式
616
  * @param string $condition 查询方式
589
- * @param string $data 查询数据
617
+ * @param string|array $data 查询数据
590
  * @return array
618
  * @return array
591
  * @since 2021-05-22
619
  * @since 2021-05-22
592
  * @author fanqi
620
  * @author fanqi
593
  */
621
  */
594
-function advancedQueryWhere($condition, $data)
622
+function advancedQueryWhere($condition, $data, $key='')
595
 {
623
 {
596
     $result = [];
624
     $result = [];
597
-    
625
+
598
     // NULL(0)不存在、IS(1)等于、IS_NOT(2)不等于、CONTAINS(3)包含、NOT_CONTAINS(4)不包含、IS_NULL(5)为空、IS_NOT_NULL(6)不为空
626
     // NULL(0)不存在、IS(1)等于、IS_NOT(2)不等于、CONTAINS(3)包含、NOT_CONTAINS(4)不包含、IS_NULL(5)为空、IS_NOT_NULL(6)不为空
599
     // GT(7)大于、EGT(8)大于等于、LT(9)小于、ELT(10)小于等于、ID(11)通过id、PREFIX(12) 前缀匹配、SUFFIX(13) 后缀匹配、RANGE(14) 数字区间
627
     // GT(7)大于、EGT(8)大于等于、LT(9)小于、ELT(10)小于等于、ID(11)通过id、PREFIX(12) 前缀匹配、SUFFIX(13) 后缀匹配、RANGE(14) 数字区间
600
-    
628
+
601
     if ($condition == "in") $result = ['in', $data];                      // 等于
629
     if ($condition == "in") $result = ['in', $data];                      // 等于
602
     if ($condition == 'is') $result = ['in', $data];                      // 等于
630
     if ($condition == 'is') $result = ['in', $data];                      // 等于
603
     if ($condition == 'isNot') $result = ['notin', $data];                   // 不等于
631
     if ($condition == 'isNot') $result = ['notin', $data];                   // 不等于
613
     if ($condition == 'range') $result = ['between', $data];                 // 处于某个时间段
641
     if ($condition == 'range') $result = ['between', $data];                 // 处于某个时间段
614
     if ($condition == 'isNull') $result = [['eq', ''], ['null'], 'OR'];       // 为空
642
     if ($condition == 'isNull') $result = [['eq', ''], ['null'], 'OR'];       // 为空
615
     if ($condition == 'isNotNull') $result = [['neq', ''], ['not null'], 'AND']; // 不为空
643
     if ($condition == 'isNotNull') $result = [['neq', ''], ['not null'], 'AND']; // 不为空
616
-    
644
+    if ($condition == 'contains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['in', $data];              // 暂定为创建人 负责人 包含
645
+    if ($condition == 'notContains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['notin', $data];          // 暂定为创建人 负责人不包含
617
     return $result;
646
     return $result;
618
 }
647
 }
619
 
648
 
633
             $data[$key] = '%' . $value . '%';
662
             $data[$key] = '%' . $value . '%';
634
         });
663
         });
635
     }
664
     }
636
-    
665
+
637
     if ($condition == 'startWith') {
666
     if ($condition == 'startWith') {
638
         array_walk($data, function ($value, $key) use (&$data) {
667
         array_walk($data, function ($value, $key) use (&$data) {
639
             $data[$key] = $value . '%';
668
             $data[$key] = $value . '%';
640
         });
669
         });
641
     }
670
     }
642
-    
671
+
643
     if ($condition == 'endWith') {
672
     if ($condition == 'endWith') {
644
         array_walk($data, function ($value, $key) use (&$data) {
673
         array_walk($data, function ($value, $key) use (&$data) {
645
             $data[$key] = '%' . $value;
674
             $data[$key] = '%' . $value;
646
         });
675
         });
647
     }
676
     }
648
-    
677
+
649
     return $data;
678
     return $data;
650
 }
679
 }
651
 
680
 
681
+/**
682
+ * 处理要查询的数据 包含不包含条件 数据为数字专用
683
+ *
684
+ * @param array $data 要查询的数据
685
+ * @param string $condition 查询方式
686
+ * @return mixed
687
+ * @author: alvin guogaobo
688
+ * @version: 11.1.0
689
+ * Date: 2021/9/2 14:44
690
+ */
691
+function advancedQueryDataUserform($data, $condition){
692
+    if (in_array($condition, ['contains', 'notContains'])) {
693
+        array_walk($data, function ($value, $key) use (&$data) {
694
+            $data[$key] = $value;
695
+        });
696
+    }
697
+    return $data;
698
+}
652
 /**
699
 /**
653
  * 等于(时间段)数据处理
700
  * 等于(时间段)数据处理
654
  *
701
  *
661
 {
708
 {
662
     // 本年度
709
     // 本年度
663
     if ($data['value'][0] == 'year') {
710
     if ($data['value'][0] == 'year') {
664
-        $data['value'][0] = date('Y-m-d 00:00:00');
665
-        $data['value'][1] = date('Y-m-d 23:59:59');
711
+        $arrTime = DataTime::year();
712
+        $data['value'][0] = date('Y-m-d 00:00:00', $arrTime[0]);
713
+        $data['value'][1] = date('Y-m-d 23:59:59', $arrTime[1]);
666
     }
714
     }
667
-    
715
+
668
     // 上一年度
716
     // 上一年度
669
     if ($data['value'][0] == 'lastYear') {
717
     if ($data['value'][0] == 'lastYear') {
670
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 year'));
718
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 year'));
671
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 year'));
719
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 year'));
672
     }
720
     }
673
-    
721
+
674
     // 下一年度
722
     // 下一年度
675
     if ($data['value'][0] == 'nextYear') {
723
     if ($data['value'][0] == 'nextYear') {
676
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 year'));
724
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 year'));
677
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 year'));
725
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 year'));
678
     }
726
     }
679
-    
727
+
680
     // 上半年
728
     // 上半年
681
     if ($data['value'][0] == 'firstHalfYear') {
729
     if ($data['value'][0] == 'firstHalfYear') {
682
         $data['value'][0] = date('Y-01-01 00:00:00');
730
         $data['value'][0] = date('Y-01-01 00:00:00');
683
         $data['value'][1] = date('Y-06-30 23:59:59');
731
         $data['value'][1] = date('Y-06-30 23:59:59');
684
     }
732
     }
685
-    
733
+
686
     // 下半年
734
     // 下半年
687
     if ($data['value'][0] == 'nextHalfYear') {
735
     if ($data['value'][0] == 'nextHalfYear') {
688
         $data['value'][0] = date('Y-07-01 00:00:00');
736
         $data['value'][0] = date('Y-07-01 00:00:00');
689
         $data['value'][1] = date('Y-12-31 23:59:59');
737
         $data['value'][1] = date('Y-12-31 23:59:59');
690
     }
738
     }
691
-    
739
+
692
     // 本季度
740
     // 本季度
693
     if ($data['value'][0] == 'quarter') {
741
     if ($data['value'][0] == 'quarter') {
694
         $season = ceil((date('n')) / 3);
742
         $season = ceil((date('n')) / 3);
695
         $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
743
         $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
696
         $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
744
         $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
697
     }
745
     }
698
-    
746
+
699
     // 上一季度
747
     // 上一季度
700
     if ($data['value'][0] == 'lastQuarter') {
748
     if ($data['value'][0] == 'lastQuarter') {
701
         $season = ceil((date('n')) / 3) - 1;
749
         $season = ceil((date('n')) / 3) - 1;
702
         $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
750
         $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
703
         $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
751
         $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
704
     }
752
     }
705
-    
753
+
706
     // 下一季度
754
     // 下一季度
707
     if ($data['value'][0] == 'nextQuarter') {
755
     if ($data['value'][0] == 'nextQuarter') {
708
         $season = ceil((date('n')) / 3);
756
         $season = ceil((date('n')) / 3);
709
         $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 + 1, 1, date('Y')));
757
         $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 + 1, 1, date('Y')));
710
         $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3 + 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
758
         $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3 + 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
711
     }
759
     }
712
-    
760
+
713
     // 本月
761
     // 本月
714
     if ($data['value'][0] == 'month') {
762
     if ($data['value'][0] == 'month') {
715
         $data['value'][0] = date('Y-m-01 00:00:00');
763
         $data['value'][0] = date('Y-m-01 00:00:00');
716
         $data['value'][1] = date('Y-m-31 23:59:59');
764
         $data['value'][1] = date('Y-m-31 23:59:59');
717
     }
765
     }
718
-    
766
+
719
     // 上月
767
     // 上月
720
     if ($data['value'][0] == 'lastMonth') {
768
     if ($data['value'][0] == 'lastMonth') {
721
         $data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '-1 month'));
769
         $data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '-1 month'));
722
         $data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '-1 month'));
770
         $data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '-1 month'));
723
     }
771
     }
724
-    
772
+
725
     // 下月
773
     // 下月
726
     if ($data['value'][0] == 'nextMonth') {
774
     if ($data['value'][0] == 'nextMonth') {
727
         $data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '+1 month'));
775
         $data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '+1 month'));
728
         $data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '+1 month'));
776
         $data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '+1 month'));
729
     }
777
     }
730
-    
778
+
731
     // 本周
779
     // 本周
732
     if ($data['value'][0] == 'week') {
780
     if ($data['value'][0] == 'week') {
733
         $data['value'][0] = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y')));
781
         $data['value'][0] = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y')));
734
         $data['value'][1] = date('Y-m-d 23:59:59', mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y')));
782
         $data['value'][1] = date('Y-m-d 23:59:59', mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y')));
735
     }
783
     }
736
-    
784
+
737
     // 上周
785
     // 上周
738
     if ($data['value'][0] == 'lastWeek') {
786
     if ($data['value'][0] == 'lastWeek') {
739
         $date = date("Y-m-d");
787
         $date = date("Y-m-d");
743
         $data['value'][0] = date('Y-m-d', strtotime($start . " - 7 days"));
791
         $data['value'][0] = date('Y-m-d', strtotime($start . " - 7 days"));
744
         $data['value'][1] = date('Y-m-d', strtotime($start . " - 1 days"));
792
         $data['value'][1] = date('Y-m-d', strtotime($start . " - 1 days"));
745
     }
793
     }
746
-    
794
+
747
     // 下周
795
     // 下周
748
     if ($data['value'][0] == 'nextWeek') {
796
     if ($data['value'][0] == 'nextWeek') {
749
         $date = date("Y-m-d");
797
         $date = date("Y-m-d");
753
         $data['value'][0] = date('Y-m-d', strtotime($start . " + 7 days"));
801
         $data['value'][0] = date('Y-m-d', strtotime($start . " + 7 days"));
754
         $data['value'][1] = date('Y-m-d', strtotime($start . " + 13 days"));
802
         $data['value'][1] = date('Y-m-d', strtotime($start . " + 13 days"));
755
     }
803
     }
756
-    
804
+
757
     // 今天
805
     // 今天
758
     if ($data['value'][0] == 'today') {
806
     if ($data['value'][0] == 'today') {
759
         $data['value'][0] = date('Y-m-d 00:00:00');
807
         $data['value'][0] = date('Y-m-d 00:00:00');
760
         $data['value'][1] = date('Y-m-d 23:59:59');
808
         $data['value'][1] = date('Y-m-d 23:59:59');
761
     }
809
     }
762
-    
810
+
763
     // 昨天
811
     // 昨天
764
     if ($data['value'][0] == 'yesterday') {
812
     if ($data['value'][0] == 'yesterday') {
765
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 day'));
813
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 day'));
766
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
814
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
767
     }
815
     }
768
-    
816
+
769
     // 明天
817
     // 明天
770
     if ($data['value'][0] == 'tomorrow') {
818
     if ($data['value'][0] == 'tomorrow') {
771
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
819
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
772
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 day'));
820
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 day'));
773
     }
821
     }
774
-    
822
+
775
     // 过去7天
823
     // 过去7天
776
     if ($data['value'][0] == 'previous7day') {
824
     if ($data['value'][0] == 'previous7day') {
777
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-7 day'));
825
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-7 day'));
778
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
826
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
779
     }
827
     }
780
-    
828
+
781
     // 过去30天
829
     // 过去30天
782
     if ($data['value'][0] == 'previous30day') {
830
     if ($data['value'][0] == 'previous30day') {
783
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-30 day'));
831
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-30 day'));
784
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
832
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
785
     }
833
     }
786
-    
834
+
787
     // 未来7天
835
     // 未来7天
788
     if ($data['value'][0] == 'future7day') {
836
     if ($data['value'][0] == 'future7day') {
789
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
837
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
790
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+7 day'));
838
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+7 day'));
791
     }
839
     }
792
-    
840
+
793
     // 未来30天
841
     // 未来30天
794
     if ($data['value'][0] == 'future30day') {
842
     if ($data['value'][0] == 'future30day') {
795
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
843
         $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
796
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+30 day'));
844
         $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+30 day'));
797
     }
845
     }
798
-    
846
+
799
     return $data;
847
     return $data;
800
 }
848
 }
801
 
849
 
904
 function field_arr($value, $condition = '')
952
 function field_arr($value, $condition = '')
905
 {
953
 {
906
     if (is_array($value)) {
954
     if (is_array($value)) {
907
-    
955
+
908
     } else {
956
     } else {
909
         $condition = $condition ?: 'eq';
957
         $condition = $condition ?: 'eq';
910
         $where_arr = ['value' => $value, 'condition' => $condition];
958
         $where_arr = ['value' => $value, 'condition' => $condition];
911
     }
959
     }
912
-    
960
+
913
     return $where_arr;
961
     return $where_arr;
914
 }
962
 }
915
 
963
 
934
     }
982
     }
935
     $userInfo = $cache['userInfo'];
983
     $userInfo = $cache['userInfo'];
936
     $category = $userInfo['id'] == 1 ? '管理员' : '员工';
984
     $category = $userInfo['id'] == 1 ? '管理员' : '员工';
937
-    
985
+
938
     $request = request();
986
     $request = request();
939
     $m = strtolower($request->module());
987
     $m = strtolower($request->module());
940
     $c = strtolower($request->controller());
988
     $c = strtolower($request->controller());
941
     $a = strtolower($request->action());
989
     $a = strtolower($request->action());
942
-    
990
+
943
     $res_action = true;
991
     $res_action = true;
944
     foreach ($idArr as $v) {
992
     foreach ($idArr as $v) {
945
         $data = [];
993
         $data = [];
959
         if (!db('admin_action_log')->insert($data)) {
1007
         if (!db('admin_action_log')->insert($data)) {
960
             $res_action = false;
1008
             $res_action = false;
961
         }
1009
         }
962
-        
1010
+
963
         # 数据操作日志
1011
         # 数据操作日志
964
         db('admin_operation_log')->insert([
1012
         db('admin_operation_log')->insert([
965
             'user_id' => $userInfo['id'],
1013
             'user_id' => $userInfo['id'],
970
             'create_time' => time()
1018
             'create_time' => time()
971
         ]);
1019
         ]);
972
     }
1020
     }
973
-    
1021
+
974
     if ($res_action) {
1022
     if ($res_action) {
975
         return true;
1023
         return true;
976
     } else {
1024
     } else {
1094
         $userInfo = $cache['userInfo'];
1142
         $userInfo = $cache['userInfo'];
1095
         $user_id = $userInfo['id'];
1143
         $user_id = $userInfo['id'];
1096
         $adminTypes = adminGroupTypes($user_id);
1144
         $adminTypes = adminGroupTypes($user_id);
1097
-        
1145
+
1098
         if (in_array(1, $adminTypes)) {
1146
         if (in_array(1, $adminTypes)) {
1099
             $type = 1;
1147
             $type = 1;
1100
         }
1148
         }
1101
     }
1149
     }
1102
     $belowIds = [];
1150
     $belowIds = [];
1103
     if (empty($type)) {
1151
     if (empty($type)) {
1104
-        
1152
+
1105
         if ($user_id) {
1153
         if ($user_id) {
1106
             $belowIds = getSubUser($user_id);
1154
             $belowIds = getSubUser($user_id);
1107
         }
1155
         }
1221
     $m = strtolower($request->module());
1269
     $m = strtolower($request->module());
1222
     $c = strtolower($request->controller());
1270
     $c = strtolower($request->controller());
1223
     $a = strtolower($request->action());
1271
     $a = strtolower($request->action());
1224
-    
1272
+
1225
     $userInfo = [];
1273
     $userInfo = [];
1226
     if ($sysMessage == 0) {
1274
     if ($sysMessage == 0) {
1227
         $header = $request->header();
1275
         $header = $request->header();
1277
     if (!empty($oldData['next_time']) && $oldData['next_time'] != strtotime($oldData['next_time'])) {
1325
     if (!empty($oldData['next_time']) && $oldData['next_time'] != strtotime($oldData['next_time'])) {
1278
         $oldData['next_time'] = strtotime($oldData['next_time']);
1326
         $oldData['next_time'] = strtotime($oldData['next_time']);
1279
     }
1327
     }
1280
-    
1328
+
1281
     if (is_array($oldData) && is_array($newData) && $user_id) {
1329
     if (is_array($oldData) && is_array($newData) && $user_id) {
1282
         $differentData = array_diff_assoc($newData, $oldData);
1330
         $differentData = array_diff_assoc($newData, $oldData);
1283
         $fieldModel = new FieldModel();
1331
         $fieldModel = new FieldModel();
1299
                 $old_value = $oldData[$k] ?: '空';
1347
                 $old_value = $oldData[$k] ?: '空';
1300
                 if ($newFieldArr[$k]['form_type'] == 'datetime') {
1348
                 if ($newFieldArr[$k]['form_type'] == 'datetime') {
1301
                     $new_value = $v ? date('Y-m-d', $v) : '空';
1349
                     $new_value = $v ? date('Y-m-d', $v) : '空';
1302
-                    $old_value = !empty($oldData[$k]) ? date('Y-m-d', $oldData[$k]) : '空';
1350
+                    if (date('Y-m-d H:i:s', strtotime($oldData[$k])) == $oldData[$k]) {
1351
+                        $old_value = !empty($oldData[$k]) ? $oldData[$k] : '空';
1352
+                    } else {
1353
+                        $old_value = !empty($oldData[$k]) ? date('Y-m-d', $oldData[$k]) : '空';
1354
+                    }
1303
                     if (empty($v) && empty($oldData[$k])) continue;
1355
                     if (empty($v) && empty($oldData[$k])) continue;
1304
                 } elseif ($newFieldArr[$k]['form_type'] == 'user') {
1356
                 } elseif ($newFieldArr[$k]['form_type'] == 'user') {
1305
                     $new_value = $v ? implode(',', $userModel->getUserNameByArr(stringToArray($v))) : '';
1357
                     $new_value = $v ? implode(',', $userModel->getUserNameByArr(stringToArray($v))) : '';
1407
     $parmList['sessionId'] = $header['sessionId'];
1459
     $parmList['sessionId'] = $header['sessionId'];
1408
     $authkey = $header['authKey'];
1460
     $authkey = $header['authKey'];
1409
     $clientSign = $parmList['client_sign'];
1461
     $clientSign = $parmList['client_sign'];
1410
-    
1462
+
1411
     if ($clientSign) {
1463
     if ($clientSign) {
1412
         unset($parmList['client_sign']);
1464
         unset($parmList['client_sign']);
1413
         if (count($parmList) > 0) {
1465
         if (count($parmList) > 0) {
1873
 function getFullPath($path)
1925
 function getFullPath($path)
1874
 {
1926
 {
1875
     if ($path) {
1927
     if ($path) {
1876
-        $protocol = strpos(strtolower($_SERVER['HTTP_REFERER']), 'https') === false ? 'http' : 'https';
1928
+        $protocol = strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false ? 'http' : 'https';
1877
         return $protocol . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER["SCRIPT_NAME"], 0, -10) . substr(str_replace(DS, '/', $path), 1);
1929
         return $protocol . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER["SCRIPT_NAME"], 0, -10) . substr(str_replace(DS, '/', $path), 1);
1878
     } else {
1930
     } else {
1879
         return '';
1931
         return '';
2067
     $new_order_id = $order_id;
2119
     $new_order_id = $order_id;
2068
     $max_order_id = db('admin_examine_step')->where(['flow_id' => $flow_id])->max('order_id'); //审批流最大排序ID
2120
     $max_order_id = db('admin_examine_step')->where(['flow_id' => $flow_id])->max('order_id'); //审批流最大排序ID
2069
     $examineStepModel = new \app\admin\model\ExamineStep();
2121
     $examineStepModel = new \app\admin\model\ExamineStep();
2070
-    
2122
+
2071
     $stepInfo = $examineStepModel->getStepByOrder($flow_id, $new_order_id); //审批步骤
2123
     $stepInfo = $examineStepModel->getStepByOrder($flow_id, $new_order_id); //审批步骤
2072
     $next_user_ids = [];
2124
     $next_user_ids = [];
2073
     $is_end = 0; //审批结束
2125
     $is_end = 0; //审批结束
2074
     //固定流程(status 1负责人主管,2指定用户(任意一人),3指定用户(多人会签),4上一级审批人主管)
2126
     //固定流程(status 1负责人主管,2指定用户(任意一人),3指定用户(多人会签),4上一级审批人主管)
2075
-    
2127
+
2076
     //当前步骤审批人user_id
2128
     //当前步骤审批人user_id
2077
     $step_user_ids = $examineStepModel->getUserByStep($stepInfo['step_id'], $user_id);
2129
     $step_user_ids = $examineStepModel->getUserByStep($stepInfo['step_id'], $user_id);
2078
     if ($step_user_ids) {
2130
     if ($step_user_ids) {
2229
 {
2281
 {
2230
     $param = request()->param();
2282
     $param = request()->param();
2231
     $userModel = new UserModel();
2283
     $userModel = new UserModel();
2232
-    
2284
+
2233
     $map_user_ids = [];
2285
     $map_user_ids = [];
2234
     if ($param['user_id']) {
2286
     if ($param['user_id']) {
2235
         $map_user_ids = array($param['user_id']);
2287
         $map_user_ids = array($param['user_id']);
2240
         $where[$field] = array('in', $map_user_ids);
2292
         $where[$field] = array('in', $map_user_ids);
2241
         return;
2293
         return;
2242
     }
2294
     }
2243
-    
2295
+
2244
     $perUserIds = $userModel->getUserByPer($m, $c, $a); //权限范围内userIds
2296
     $perUserIds = $userModel->getUserByPer($m, $c, $a); //权限范围内userIds
2245
     $userIds = array_intersect($map_user_ids, $perUserIds); //数组交集
2297
     $userIds = array_intersect($map_user_ids, $perUserIds); //数组交集
2246
     $where[$field] = array('in', $userIds);
2298
     $where[$field] = array('in', $userIds);
2335
             'error' => '文件路径错误',
2387
             'error' => '文件路径错误',
2336
         ]);
2388
         ]);
2337
     }
2389
     }
2338
-    
2390
+
2339
     $fp = fopen($file, 'r');
2391
     $fp = fopen($file, 'r');
2340
     $size = filesize($file);
2392
     $size = filesize($file);
2341
-    
2393
+
2342
     //下载文件需要的头
2394
     //下载文件需要的头
2343
     header("Content-type: application/octet-stream");
2395
     header("Content-type: application/octet-stream");
2344
     header("Accept-Ranges: bytes");
2396
     header("Accept-Ranges: bytes");
2347
     $file_name = $name != '' ? $name : pathinfo($file, PATHINFO_BASENAME);
2399
     $file_name = $name != '' ? $name : pathinfo($file, PATHINFO_BASENAME);
2348
     // urlencode 处理中文乱码
2400
     // urlencode 处理中文乱码
2349
     header("Content-Disposition:attachment; filename=" . urlencode($file_name));
2401
     header("Content-Disposition:attachment; filename=" . urlencode($file_name));
2350
-    
2402
+
2351
     // 导出数据时  csv office Excel 需要添加bom头
2403
     // 导出数据时  csv office Excel 需要添加bom头
2352
     if (pathinfo($file, PATHINFO_EXTENSION) == 'csv') {
2404
     if (pathinfo($file, PATHINFO_EXTENSION) == 'csv') {
2353
         echo "\xEF\xBB\xBF";    // UTF-8 BOM
2405
         echo "\xEF\xBB\xBF";    // UTF-8 BOM
2354
     }
2406
     }
2355
-    
2407
+
2356
     $fileCount = 0;
2408
     $fileCount = 0;
2357
     $fileUnit = 1024;
2409
     $fileUnit = 1024;
2358
     while (!feof($fp) && $size - $fileCount > 0) {
2410
     while (!feof($fp) && $size - $fileCount > 0) {
2361
         $fileCount += $fileUnit;
2413
         $fileCount += $fileUnit;
2362
     }
2414
     }
2363
     fclose($fp);
2415
     fclose($fp);
2364
-    
2416
+
2365
     // 删除
2417
     // 删除
2366
     if ($del) @unlink($file);
2418
     if ($del) @unlink($file);
2367
     die();
2419
     die();
2382
     if (!file_exists($path)) {
2434
     if (!file_exists($path)) {
2383
         mkdir($path, 0777, true);
2435
         mkdir($path, 0777, true);
2384
     }
2436
     }
2385
-    
2437
+
2386
     $ext = trim($ext, '.');
2438
     $ext = trim($ext, '.');
2387
     do {
2439
     do {
2388
         $temp_file = md5(time() . rand(1000, 9999));
2440
         $temp_file = md5(time() . rand(1000, 9999));
2411
             }
2463
             }
2412
         }
2464
         }
2413
     }
2465
     }
2414
-    
2466
+
2415
     closedir($dh);
2467
     closedir($dh);
2416
     //删除当前文件夹:
2468
     //删除当前文件夹:
2417
     @rmdir($dir);
2469
     @rmdir($dir);
2523
                 break;
2575
                 break;
2524
         }
2576
         }
2525
     }
2577
     }
2526
-    
2578
+
2527
     $between = [$start, $end];
2579
     $between = [$start, $end];
2528
     $list = [];
2580
     $list = [];
2529
     $len = ($end - $start) / 86400;
2581
     $len = ($end - $start) / 86400;
2552
             $start = $item['end_time'] + 1;
2604
             $start = $item['end_time'] + 1;
2553
         }
2605
         }
2554
     }
2606
     }
2555
-    
2607
+
2556
     return [
2608
     return [
2557
         'list' => $list,        // 时间段列表
2609
         'list' => $list,        // 时间段列表
2558
         'time_format' => $time_format,      // 时间格式 mysql 格式化时间戳
2610
         'time_format' => $time_format,      // 时间格式 mysql 格式化时间戳
2585
     $username = config('database.username');
2637
     $username = config('database.username');
2586
     $password = config('database.password');
2638
     $password = config('database.password');
2587
     $dsn = "{$type}:host={$host};dbname={$dbname};port={$port}";
2639
     $dsn = "{$type}:host={$host};dbname={$dbname};port={$port}";
2588
-    
2589
-    
2640
+
2641
+
2590
     if ($file == '') {
2642
     if ($file == '') {
2591
         $save_path = dirname(APP_PATH) . DS . 'data' . DS . date('Ym') . DS;
2643
         $save_path = dirname(APP_PATH) . DS . 'data' . DS . date('Ym') . DS;
2592
         if (!file_exists($save_path) && !mkdir($save_path, '0777', true)) {
2644
         if (!file_exists($save_path) && !mkdir($save_path, '0777', true)) {
2594
         }
2646
         }
2595
         $file = $save_path . date('d_H_i') . '_db_backup' . '.sql';
2647
         $file = $save_path . date('d_H_i') . '_db_backup' . '.sql';
2596
     }
2648
     }
2597
-    
2649
+
2598
     if (file_exists($file)) {
2650
     if (file_exists($file)) {
2599
         return '数据库备份文件已存在(自动备份时间间隔需大于1分钟)。';
2651
         return '数据库备份文件已存在(自动备份时间间隔需大于1分钟)。';
2600
     }
2652
     }
2601
-    
2653
+
2602
     try {
2654
     try {
2603
         $backup = new \com\Mysqldump($dsn, $username, $password);
2655
         $backup = new \com\Mysqldump($dsn, $username, $password);
2604
         $backup->start($file);
2656
         $backup->start($file);
2606
     } catch (\Exception $e) {
2658
     } catch (\Exception $e) {
2607
         return '备份失败,请手动备份。错误原因:' . $e->getMessage();
2659
         return '备份失败,请手动备份。错误原因:' . $e->getMessage();
2608
     }
2660
     }
2609
-    
2661
+
2610
 }
2662
 }
2611
 
2663
 
2612
 /**
2664
 /**
2629
     function isSuperAdministrators($userId)
2681
     function isSuperAdministrators($userId)
2630
     {
2682
     {
2631
         $status = false;
2683
         $status = false;
2632
-        
2684
+
2633
         $apiCommon = new \app\admin\controller\ApiCommon();
2685
         $apiCommon = new \app\admin\controller\ApiCommon();
2634
-        
2686
+
2635
         $userId = !empty($userId) ? $userId : $apiCommon->userInfo['id'];
2687
         $userId = !empty($userId) ? $userId : $apiCommon->userInfo['id'];
2636
-        
2688
+
2637
         $data = db('admin_access')->where('user_id', $userId)->column('group_id');
2689
         $data = db('admin_access')->where('user_id', $userId)->column('group_id');
2638
-        
2690
+
2639
         if ($userId == 1 || in_array(1, $data)) {
2691
         if ($userId == 1 || in_array(1, $data)) {
2640
             $status = true;
2692
             $status = true;
2641
         }
2693
         }
2642
-        
2694
+
2643
         return $status;
2695
         return $status;
2644
     }
2696
     }
2645
 }
2697
 }
2653
     function getFieldGrantData($userId)
2705
     function getFieldGrantData($userId)
2654
     {
2706
     {
2655
         $result = [];
2707
         $result = [];
2656
-        
2708
+
2657
         $apiCommon = new \app\admin\controller\ApiCommon();
2709
         $apiCommon = new \app\admin\controller\ApiCommon();
2658
-        
2710
+
2659
         $userId = !empty($userId) ? $userId : $apiCommon->userInfo['id'];
2711
         $userId = !empty($userId) ? $userId : $apiCommon->userInfo['id'];
2660
-        
2712
+
2661
         $grantData = Db::query("
2713
         $grantData = Db::query("
2662
             SELECT 
2714
             SELECT 
2663
                 `grant`.`module`, `grant`.`column`, `grant`.`content` 
2715
                 `grant`.`module`, `grant`.`column`, `grant`.`content` 
2670
             WHERE 
2722
             WHERE 
2671
                 `access`.`user_id` = 
2723
                 `access`.`user_id` = 
2672
         " . $userId);
2724
         " . $userId);
2673
-        
2725
+
2674
         # 存在多角色多授权的情况
2726
         # 存在多角色多授权的情况
2675
         foreach ($grantData as $key => $value) {
2727
         foreach ($grantData as $key => $value) {
2676
             if (empty($value['module']) || empty($value['column'])) continue;
2728
             if (empty($value['module']) || empty($value['column'])) continue;
2677
-            
2729
+
2678
             $result[$value['module'] . '_' . $value['column']][] = !empty($value['content']) ? unserialize($value['content']) : [];
2730
             $result[$value['module'] . '_' . $value['column']][] = !empty($value['content']) ? unserialize($value['content']) : [];
2679
         }
2731
         }
2680
-        
2732
+
2681
         return $result;
2733
         return $result;
2682
     }
2734
     }
2683
 }
2735
 }
2693
     function getFieldGrantStatus($field, $grantData)
2745
     function getFieldGrantStatus($field, $grantData)
2694
     {
2746
     {
2695
         # 默认状态都是不能查看、不能编辑,通过配置来取最大权限。
2747
         # 默认状态都是不能查看、不能编辑,通过配置来取最大权限。
2696
-        $result = ['read' => 0, 'write' => 0];
2697
-        
2748
+        $result = ['read' => 0, 'write' => 0,'maskType'=>0];
2698
         foreach ($grantData as $key => $value) {
2749
         foreach ($grantData as $key => $value) {
2699
             $fieldBool = false;
2750
             $fieldBool = false;
2700
-            
2751
+
2701
             foreach ($value as $ke => $va) {
2752
             foreach ($value as $ke => $va) {
2702
                 # 多个字段授权,只取最高的读权限
2753
                 # 多个字段授权,只取最高的读权限
2703
                 if ($va['field'] == $field && $result['read'] == 0) {
2754
                 if ($va['field'] == $field && $result['read'] == 0) {
2704
                     $result['read'] = $va['read'] > $result['read'] ? $va['read'] : $result['read'];
2755
                     $result['read'] = $va['read'] > $result['read'] ? $va['read'] : $result['read'];
2705
                 }
2756
                 }
2706
-                
2757
+
2707
                 # 多个字段授权,只取最高的写权限
2758
                 # 多个字段授权,只取最高的写权限
2708
                 if ($va['field'] == $field && $result['write'] == 0) {
2759
                 if ($va['field'] == $field && $result['write'] == 0) {
2709
                     $result['write'] = $va['write'] > $result['write'] ? $va['write'] : $result['write'];
2760
                     $result['write'] = $va['write'] > $result['write'] ? $va['write'] : $result['write'];
2710
                 }
2761
                 }
2711
-                
2762
+                if ($va['field'] == $field && $va['maskType'] != 0) {
2763
+                    $result['maskType'] = !empty($va['maskType'])?$va['maskType']:0;
2764
+                }
2712
                 if ($va['field'] == $field) $fieldBool = true;
2765
                 if ($va['field'] == $field) $fieldBool = true;
2713
             }
2766
             }
2714
-            
2767
+
2715
             # 对于不在权限控制之内的字段,将状态都改为1。
2768
             # 对于不在权限控制之内的字段,将状态都改为1。
2716
             if (!$fieldBool) {
2769
             if (!$fieldBool) {
2770
+
2717
                 $result['read'] = 1;
2771
                 $result['read'] = 1;
2718
                 $result['write'] = 1;
2772
                 $result['write'] = 1;
2773
+
2719
             }
2774
             }
2720
         }
2775
         }
2721
-        
2722
         return $result;
2776
         return $result;
2723
     }
2777
     }
2724
 }
2778
 }
2767
                 $daterange_start_time = strtotime(date('Y-10-01 00:00:00'));
2821
                 $daterange_start_time = strtotime(date('Y-10-01 00:00:00'));
2768
                 $daterange_end_time = strtotime(date("Y-12-31 23:59:59"));
2822
                 $daterange_end_time = strtotime(date("Y-12-31 23:59:59"));
2769
             }
2823
             }
2770
-            
2824
+
2771
             //上季度
2825
             //上季度
2772
             $month = date('m');
2826
             $month = date('m');
2773
             if ($month == 1 || $month == 2 || $month == 3) {
2827
             if ($month == 1 || $month == 2 || $month == 3) {
3007
         $formPositionEmpty = [];
3061
         $formPositionEmpty = [];
3008
         $formPositionExist = [];
3062
         $formPositionExist = [];
3009
         $result = [];
3063
         $result = [];
3010
-        
3011
         // 处理数据,将有位置信息和无位置信息的数据分开存放。
3064
         // 处理数据,将有位置信息和无位置信息的数据分开存放。
3012
         foreach ($data as $key => $value) {
3065
         foreach ($data as $key => $value) {
3013
             if (empty($value['form_position'])) {
3066
             if (empty($value['form_position'])) {
3014
                 $formPositionEmpty[] = $value;
3067
                 $formPositionEmpty[] = $value;
3015
                 continue;
3068
                 continue;
3016
             }
3069
             }
3017
-            
3018
             $formPositionArray = explode(',', $value['form_position']);
3070
             $formPositionArray = explode(',', $value['form_position']);
3019
             $x = (int)$formPositionArray[0];
3071
             $x = (int)$formPositionArray[0];
3020
             $y = (int)$formPositionArray[1];
3072
             $y = (int)$formPositionArray[1];
3021
-            
3073
+
3022
             if (!isset($value['xaxis'])) $value['xaxis'] = $x;
3074
             if (!isset($value['xaxis'])) $value['xaxis'] = $x;
3023
             if (!isset($value['yaxis'])) $value['yaxis'] = $y;
3075
             if (!isset($value['yaxis'])) $value['yaxis'] = $y;
3024
-            
3076
+            if ($value['form_type'] == 'date_interval' && !is_array($value['default_value'])) {
3077
+                $value['default_value'] = !empty($value['default_value']) ? explode(',', $value['default_value']) : [];
3078
+            }
3025
             $formPositionExist[$x][$y] = $value;
3079
             $formPositionExist[$x][$y] = $value;
3080
+
3026
         }
3081
         }
3027
-        
3082
+
3028
         // 排序
3083
         // 排序
3029
         ksort($formPositionExist);
3084
         ksort($formPositionExist);
3030
-        
3031
         // 处理有位置信息的数据
3085
         // 处理有位置信息的数据
3032
         foreach ($formPositionExist as $key => $value) {
3086
         foreach ($formPositionExist as $key => $value) {
3033
             foreach ($value as $k => $v) {
3087
             foreach ($value as $k => $v) {
3034
                 if (!empty($formPositionExist[$key][$k])) $result[$key][$k] = $v;
3088
                 if (!empty($formPositionExist[$key][$k])) $result[$key][$k] = $v;
3089
+
3035
             }
3090
             }
3036
-            
3091
+
3037
             $result[$key] = array_values($result[$key]);
3092
             $result[$key] = array_values($result[$key]);
3038
         }
3093
         }
3039
-        
3040
         // 将无位置信息的数据放置尾端
3094
         // 将无位置信息的数据放置尾端
3041
         foreach ($formPositionEmpty as $key => $value) {
3095
         foreach ($formPositionEmpty as $key => $value) {
3042
             $result[] = [$value];
3096
             $result[] = [$value];
3043
         }
3097
         }
3044
-        
3098
+
3045
         return array_values($result);
3099
         return array_values($result);
3046
     }
3100
     }
3047
 }
3101
 }
3058
     function getPrimaryKeyName($types)
3112
     function getPrimaryKeyName($types)
3059
     {
3113
     {
3060
         $primaryKey = '';
3114
         $primaryKey = '';
3061
-        
3115
+
3062
         if ($types == 'crm_leads') $primaryKey = 'leads_id';
3116
         if ($types == 'crm_leads') $primaryKey = 'leads_id';
3063
         if ($types == 'crm_customer') $primaryKey = 'customer_id';
3117
         if ($types == 'crm_customer') $primaryKey = 'customer_id';
3064
         if ($types == 'crm_contacts') $primaryKey = 'contacts_id';
3118
         if ($types == 'crm_contacts') $primaryKey = 'contacts_id';
3070
         if ($types == 'crm_product') $primaryKey = 'product_id';
3124
         if ($types == 'crm_product') $primaryKey = 'product_id';
3071
         if ($types == 'crm_invoice') $primaryKey = 'invoice_id';
3125
         if ($types == 'crm_invoice') $primaryKey = 'invoice_id';
3072
         if ($types == 'oa_examine') $primaryKey = 'examine_id';
3126
         if ($types == 'oa_examine') $primaryKey = 'examine_id';
3073
-        
3127
+        if ($types == 'jxc_product') $primaryKey = 'product_id';
3128
+        if ($types == 'jxc_supplier') $primaryKey = 'supplier_id';
3129
+        if ($types == 'jxc_purchase') $primaryKey = 'purchase_id';
3130
+        if ($types == 'jxc_retreat') $primaryKey = 'retreat_id';
3131
+        if ($types == 'jxc_sale') $primaryKey = 'sale_id';
3132
+        if ($types == 'jxc_salereturn') $primaryKey = 'salereturn_id';
3133
+        if ($types == 'jxc_receipt') $primaryKey = 'receipt_id';
3134
+        if ($types == 'jxc_outbound') $primaryKey = 'outbound_id';
3135
+        if ($types == 'jxc_payment') $primaryKey = 'payment_note_id';
3136
+        if ($types == 'jxc_collection') $primaryKey = 'collection_note_id';
3137
+        if ($types == 'jxc_inventory') $primaryKey = 'inventory_id';
3138
+        if ($types == 'jxc_allocation') $primaryKey = 'allocation_id';
3139
+
3074
         return $primaryKey;
3140
         return $primaryKey;
3075
     }
3141
     }
3076
-    
3142
+
3077
 }
3143
 }
3078
-function advancedQueryFormatForTeam($requestMap,$db,$db_id)
3144
+function advancedQueryFormatForTeam($requestMap, $db, $db_id)
3079
 {
3145
 {
3080
     // 处理查询条件
3146
     // 处理查询条件
3081
     foreach ($requestMap['team_id']['value'] as $v) {
3147
     foreach ($requestMap['team_id']['value'] as $v) {
3082
         if ($requestMap['team_id']['condition'] == 'contains') {
3148
         if ($requestMap['team_id']['condition'] == 'contains') {
3083
             $date = function ($query) use ($v) {
3149
             $date = function ($query) use ($v) {
3084
-                $query->where('FIND_IN_SET("'.$v.'", ro_user_id)')
3085
-                    ->whereOr('FIND_IN_SET("'.$v.'", rw_user_id)');
3150
+                $query->where('FIND_IN_SET("' . $v . '", ro_user_id)')
3151
+                    ->whereOr('FIND_IN_SET("' . $v . '", rw_user_id)');
3086
             };
3152
             };
3087
         } elseif ($requestMap['team_id']['condition'] == 'notContains') {
3153
         } elseif ($requestMap['team_id']['condition'] == 'notContains') {
3088
             $date = function ($query) use ($v) {
3154
             $date = function ($query) use ($v) {
3089
-                $query->where('FIND_IN_SET("'.$v.'", ro_user_id)')
3090
-                    ->where('FIND_IN_SET("'.$v.'", rw_user_id)');
3155
+                $query->where('FIND_IN_SET("' . $v . '", ro_user_id)')
3156
+                    ->where('FIND_IN_SET("' . $v . '", rw_user_id)');
3091
             };
3157
             };
3092
         } elseif ($requestMap['team_id']['condition'] == 'isNull') {
3158
         } elseif ($requestMap['team_id']['condition'] == 'isNull') {
3093
             $date = function ($query) {
3159
             $date = function ($query) {
3099
                 $query->where('ro_user_id', ['neq', ''])
3165
                 $query->where('ro_user_id', ['neq', ''])
3100
                     ->where('rw_user_id', ['not null']);
3166
                     ->where('rw_user_id', ['not null']);
3101
             };
3167
             };
3102
-            
3168
+
3103
         }
3169
         }
3104
         $part[] = db($db)->where($date)->column($db_id);
3170
         $part[] = db($db)->where($date)->column($db_id);
3105
     }
3171
     }
3106
     $result = [];
3172
     $result = [];
3107
-    array_walk_recursive($part, function($value) use (&$result) {
3173
+    array_walk_recursive($part, function ($value) use (&$result) {
3108
         array_push($result, $value);
3174
         array_push($result, $value);
3109
     });
3175
     });
3110
-    $result=array_unique($result);
3176
+    $result = array_unique($result);
3111
     $partMap['customer.customer_id'] = ['in', trim(arrayToString($result), ',')];
3177
     $partMap['customer.customer_id'] = ['in', trim(arrayToString($result), ',')];
3112
     return $partMap ?: [];
3178
     return $partMap ?: [];
3113
 }
3179
 }

+ 29
- 1
application/common/command/PoolCommand.php Просмотреть файл

112
             }
112
             }
113
         });
113
         });
114
     }
114
     }
115
+    /**
116
+     * 自动入公海操作记录
117
+     * @param $ruleList
118
+     * @param $customerWhere
119
+     *
120
+     * @author      alvin guogaobo
121
+     * @version     1.0 版本号
122
+     * @since       2021/6/3 0003 10:38
123
+     */
124
+//    private function updateInfo($ruleList, $customerWhere)
125
+//    {
126
+//        foreach ($ruleList as $k => $v) {
127
+//            $levels = json_decode($v['level'], true);
128
+//            foreach ($levels as $k1 => $v1) {
129
+//                if (!empty($v1['limit_day'])) {
130
+//                    $time = $v1['limit_day'];
131
+//                } else {
132
+//                    $time = $this->getMinDay($levels);
133
+//                }
134
+//            }
135
+//            foreach ($customerWhere as $val) {
136
+//                if ($v['type'] == 1) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建跟进记录自动进入公海');
137
+//                if ($v['type'] == 2) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建商机自动进入公海');
138
+//                if ($v['type'] == 3) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天未成交自动进入公海');
139
+//
140
+//            }
141
+//        }
142
+//    }
143
+//
115
     
144
     
116
-
117
     
145
     
118
     protected function execute(Input $input, Output $output)
146
     protected function execute(Input $input, Output $output)
119
     {
147
     {

+ 2
- 0
application/common/command/Team.php Просмотреть файл

71
     {
71
     {
72
         $this->timer = Timer::add(1, function () {
72
         $this->timer = Timer::add(1, function () {
73
             # 只在凌晨12点至6点间执行
73
             # 只在凌晨12点至6点间执行
74
+
74
             if ((int)date('H') >= 0 && (int)date('H') < 6) {
75
             if ((int)date('H') >= 0 && (int)date('H') < 6) {
75
             # 团队成员过滤规则
76
             # 团队成员过滤规则
76
             db('crm_team')->where('target_time',0)->delete();
77
             db('crm_team')->where('target_time',0)->delete();
125
                         }
126
                         }
126
                         $upData = db($types)->where([$data_name => $v['target_id']])->update($data);
127
                         $upData = db($types)->where([$data_name => $v['target_id']])->update($data);
127
                         db('crm_team')->where(['target_id' => $v['target_id'], 'types' => $v['types'], 'team_user_id' => ['in', arrayToString($team_user_id)]])->delete();
128
                         db('crm_team')->where(['target_id' => $v['target_id'], 'types' => $v['types'], 'team_user_id' => ['in', arrayToString($team_user_id)]])->delete();
129
+//                        updateActionLog(0, $v['types'], $data, '', '', '自动删除到期员工');
128
                     }
130
                     }
129
                     Db::commit();
131
                     Db::commit();
130
                 } catch (\Exception $e) {
132
                 } catch (\Exception $e) {

+ 9
- 6
application/crm/controller/Contract.php Просмотреть файл

116
                 $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
116
                 $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
117
             } else {
117
             } else {
118
                 # 审批流停用,将状态改为审核通过
118
                 # 审批流停用,将状态改为审核通过
119
-                $param['check_status'] = 2;
119
+                // $param['check_status'] = 2;
120
+
121
+                # 审批流停用,将状态改为正常   zjf 20210727  默认值为7
122
+                $param['check_status'] = 7;
120
             }
123
             }
121
         }
124
         }
122
 
125
 
212
         }
215
         }
213
 
216
 
214
         # 已进行审批,不能编辑
217
         # 已进行审批,不能编辑
215
-        if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) {
218
+        if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6', '7']) && $dataInfo['check_status']!=0) {
216
             return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
219
             return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
217
         }
220
         }
218
 
221
 
260
         $examineFlowWheres['status'] = 1;
263
         $examineFlowWheres['status'] = 1;
261
         $examineFlowWheres['is_deleted'] = 0;
264
         $examineFlowWheres['is_deleted'] = 0;
262
         $contractExamineCount = db('admin_examine_flow')->where($examineFlowWheres)->count();
265
         $contractExamineCount = db('admin_examine_flow')->where($examineFlowWheres)->count();
263
-        # 审核没有开启,更新作废合同的状态
264
-        if ($contractExamineCount == 0 && $dataInfo['check_status'] == 6 && empty($param['is_draft'])) $param['check_status'] = 2;
265
-        # 审核没有开启,更新作废合同的状态
266
-        if ($contractExamineCount == 0 && $dataInfo['check_status'] == 5 && empty($param['is_draft'])) $param['check_status'] = 2;
266
+        # 审核没有开启,更新作废合同的状态      zjf   20210727   改状态为正常   值为7
267
+        if ($contractExamineCount == 0 && $dataInfo['check_status'] == 6 && empty($param['is_draft'])) $param['check_status'] = 7;
268
+        # 审核没有开启,更新作废合同的状态      zjf   20210727   改状态为正常   值为7
269
+        if ($contractExamineCount == 0 && $dataInfo['check_status'] == 5 && empty($param['is_draft'])) $param['check_status'] = 7;
267
         # 审核没有开启,保存为草稿
270
         # 审核没有开启,保存为草稿
268
         if ($contractExamineCount == 0 && !empty($param['is_draft'])) $param['check_status'] = 5;
271
         if ($contractExamineCount == 0 && !empty($param['is_draft'])) $param['check_status'] = 5;
269
 
272
 

+ 119
- 159
application/crm/controller/Customer.php Просмотреть файл

11
 use app\crm\logic\CustomerLogic;
11
 use app\crm\logic\CustomerLogic;
12
 use app\crm\traits\SearchConditionTrait;
12
 use app\crm\traits\SearchConditionTrait;
13
 use app\crm\traits\StarTrait;
13
 use app\crm\traits\StarTrait;
14
+use phpDocumentor\Reflection\Types\False_;
15
+use think\Cache;
14
 use think\Hook;
16
 use think\Hook;
15
 use think\Request;
17
 use think\Request;
16
 use think\Db;
18
 use think\Db;
18
 class Customer extends ApiCommon
20
 class Customer extends ApiCommon
19
 {
21
 {
20
     use StarTrait, SearchConditionTrait;
22
     use StarTrait, SearchConditionTrait;
21
-    
23
+
22
     /**
24
     /**
23
      * 用于判断权限
25
      * 用于判断权限
24
      * @permission 无限制
26
      * @permission 无限制
41
             $this->param = $param;
43
             $this->param = $param;
42
         }
44
         }
43
     }
45
     }
44
-    
46
+
45
     /**
47
     /**
46
      * 客户列表
48
      * 客户列表
47
      * @return
49
      * @return
56
         $data = $customerModel->getDataList($param);
58
         $data = $customerModel->getDataList($param);
57
         return resultArray(['data' => $data]);
59
         return resultArray(['data' => $data]);
58
     }
60
     }
59
-    
61
+
60
     /**
62
     /**
61
      * 客户公海(没有负责人或已经到期)
63
      * 客户公海(没有负责人或已经到期)
62
      * @return
64
      * @return
70
         $data = model('Customer')->getDataList($param);
72
         $data = model('Customer')->getDataList($param);
71
         return resultArray(['data' => $data]);
73
         return resultArray(['data' => $data]);
72
     }
74
     }
73
-    
75
+
74
     /**
76
     /**
75
      * 添加客户
77
      * 添加客户
76
      * @param
78
      * @param
91
             return resultArray(['error' => $customerModel->getError()]);
93
             return resultArray(['error' => $customerModel->getError()]);
92
         }
94
         }
93
     }
95
     }
94
-    
96
+
95
     /**
97
     /**
96
      * 客户详情
98
      * 客户详情
97
      * @param
99
      * @param
101
     public function read()
103
     public function read()
102
     {
104
     {
103
         $customerModel = model('Customer');
105
         $customerModel = model('Customer');
106
+        $cutomerLogic = new CustomerLogic();
104
         $param = $this->param;
107
         $param = $this->param;
105
         $userInfo = $this->userInfo;
108
         $userInfo = $this->userInfo;
106
         $data = $customerModel->getDataById($param['id'], $userInfo['id']);
109
         $data = $customerModel->getDataById($param['id'], $userInfo['id']);
116
         //判断是否客户池数据
119
         //判断是否客户池数据
117
         $wherePool = $customerModel->getWhereByPool();
120
         $wherePool = $customerModel->getWhereByPool();
118
         $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find();
121
         $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find();
119
-        if (!$resPool && !in_array($data['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) {
122
+      if (!$resPool && !in_array($data['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) {
120
             $authData['dataAuth'] = (int)0;
123
             $authData['dataAuth'] = (int)0;
121
             return resultArray(['data' => $authData]);
124
             return resultArray(['data' => $authData]);
122
         }
125
         }
123
         return resultArray(['data' => $data]);
126
         return resultArray(['data' => $data]);
124
     }
127
     }
125
-    
128
+
126
     /**
129
     /**
127
      * 编辑客户
130
      * 编辑客户
128
      * @param
131
      * @param
139
         if (!$data) {
142
         if (!$data) {
140
             return resultArray(['error' => $customerModel->getError()]);
143
             return resultArray(['error' => $customerModel->getError()]);
141
         }
144
         }
142
-        
145
+
143
         $param['user_id'] = $userInfo['id'];
146
         $param['user_id'] = $userInfo['id'];
144
         if ($customerModel->updateDataById($param, $param['id'])) {
147
         if ($customerModel->updateDataById($param, $param['id'])) {
145
             return resultArray(['data' => '编辑成功']);
148
             return resultArray(['data' => '编辑成功']);
147
             return resultArray(['error' => $customerModel->getError()]);
150
             return resultArray(['error' => $customerModel->getError()]);
148
         }
151
         }
149
     }
152
     }
150
-    
153
+
151
     /**
154
     /**
152
      * 删除客户
155
      * 删除客户
153
      * @param
156
      * @param
157
     public function delete()
160
     public function delete()
158
     {
161
     {
159
         $param = $this->param;
162
         $param = $this->param;
160
-        $user=new ApiCommon();
163
+        $user = new ApiCommon();
161
         $userInfo = $user->userInfo;
164
         $userInfo = $user->userInfo;
162
         // 是否客户池
165
         // 是否客户池
163
         if ($param['isSeas'] == 1) {
166
         if ($param['isSeas'] == 1) {
180
         }
183
         }
181
         $delIds = [];
184
         $delIds = [];
182
         $errorMessage = [];
185
         $errorMessage = [];
183
-        
186
+
184
         //数据权限判断
187
         //数据权限判断
185
         $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'delete');
188
         $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'delete');
186
         //判断是否客户池数据(客户池数据只有管理员可以删)
189
         //判断是否客户池数据(客户池数据只有管理员可以删)
204
             //     $isDel = false;
207
             //     $isDel = false;
205
             //     $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:无权操作';
208
             //     $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:无权操作';
206
             // }
209
             // }
207
-            //有商机、合同、联系人则不能删除 
210
+            //有商机、合同、联系人则不能删除
208
             if ($isDel) {
211
             if ($isDel) {
209
                 $resBusiness = db('crm_business')->where(['customer_id' => $v])->find();
212
                 $resBusiness = db('crm_business')->where(['customer_id' => $v])->find();
210
                 if ($resBusiness) {
213
                 if ($resBusiness) {
230
                 $delIds[] = $v;
233
                 $delIds[] = $v;
231
             }
234
             }
232
         }
235
         }
233
-        $dataInfo = $customerModel->where('customer_id',['in',$delIds])->select();
236
+        $dataInfo = $customerModel->where('customer_id', ['in', $delIds])->select();
234
         if ($delIds) {
237
         if ($delIds) {
235
             $delRes = $customerModel->delDatas($delIds);
238
             $delRes = $customerModel->delDatas($delIds);
236
             if (!$delRes) {
239
             if (!$delRes) {
254
             return resultArray(['data' => '删除成功']);
257
             return resultArray(['data' => '删除成功']);
255
         }
258
         }
256
     }
259
     }
257
-    
260
+
258
     /**
261
     /**
259
      * 客户转移
262
      * 客户转移
260
      * @param owner_user_id 变更负责人
263
      * @param owner_user_id 变更负责人
275
         $settingModel = model('Setting');
278
         $settingModel = model('Setting');
276
         $customerConfigModel = model('CustomerConfig');
279
         $customerConfigModel = model('CustomerConfig');
277
         $userModel = new \app\admin\model\User();
280
         $userModel = new \app\admin\model\User();
278
-        
281
+
279
         if (!$param['owner_user_id']) {
282
         if (!$param['owner_user_id']) {
280
             return resultArray(['error' => '变更负责人不能为空']);
283
             return resultArray(['error' => '变更负责人不能为空']);
281
         }
284
         }
285
         $is_remove = ($param['is_remove'] == 2) ? 2 : 1;
288
         $is_remove = ($param['is_remove'] == 2) ? 2 : 1;
286
         $type = $param['type'] == 2 ?: 1;
289
         $type = $param['type'] == 2 ?: 1;
287
         $types = $param['types'] ?: [];
290
         $types = $param['types'] ?: [];
288
-        
291
+
289
         $data = [];
292
         $data = [];
290
         $data['owner_user_id'] = $param['owner_user_id'];
293
         $data['owner_user_id'] = $param['owner_user_id'];
291
         $data['update_time'] = time();
294
         $data['update_time'] = time();
292
         $data['follow'] = '待跟进';
295
         $data['follow'] = '待跟进';
293
         # 获取客户的时间
296
         # 获取客户的时间
294
         $data['obtain_time'] = time();
297
         $data['obtain_time'] = time();
295
-        
298
+
296
         $ownerUserName = $userModel->getUserNameById($param['owner_user_id']);
299
         $ownerUserName = $userModel->getUserNameById($param['owner_user_id']);
297
         $errorMessage = [];
300
         $errorMessage = [];
298
         foreach ($param['customer_id'] as $customer_id) {
301
         foreach ($param['customer_id'] as $customer_id) {
312
                 $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:' . $customerConfigModel->getError();
315
                 $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:' . $customerConfigModel->getError();
313
                 continue;
316
                 continue;
314
             }
317
             }
315
-            
318
+
316
             //团队成员
319
             //团队成员
317
             $teamData = [];
320
             $teamData = [];
318
             $teamData['type'] = $type; //权限 1只读2读写
321
             $teamData['type'] = $type; //权限 1只读2读写
324
 
327
 
325
             # 处理分配标识,待办事项专用
328
             # 处理分配标识,待办事项专用
326
             $data['is_allocation'] = 1;
329
             $data['is_allocation'] = 1;
327
-            
330
+
328
             $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data);
331
             $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data);
329
             if (!$resCustomer) {
332
             if (!$resCustomer) {
330
                 $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:数据出错;';
333
                 $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:数据出错;';
343
                 }
346
                 }
344
                 db('crm_customer')->where('customer_id', $customer_id)->update($customerArray);
347
                 db('crm_customer')->where('customer_id', $customer_id)->update($customerArray);
345
             }
348
             }
346
-            
349
+
347
             if (in_array('crm_contacts', $types)) {
350
             if (in_array('crm_contacts', $types)) {
348
                 $contactsIds = [];
351
                 $contactsIds = [];
349
                 $contactsIds = db('crm_contacts')->where(['customer_id' => $customer_id])->column('contacts_id');
352
                 $contactsIds = db('crm_contacts')->where(['customer_id' => $customer_id])->column('contacts_id');
355
                     }
358
                     }
356
                 }
359
                 }
357
             }
360
             }
358
-            
361
+
359
             //商机、合同转移
362
             //商机、合同转移
360
             if (in_array('crm_business', $types)) {
363
             if (in_array('crm_business', $types)) {
361
                 $businessIds = [];
364
                 $businessIds = [];
368
                     }
371
                     }
369
                 }
372
                 }
370
             }
373
             }
371
-            
374
+
372
             if (in_array('crm_contract', $types)) {
375
             if (in_array('crm_contract', $types)) {
373
                 $contractIds = [];
376
                 $contractIds = [];
374
                 $contractIds = db('crm_contract')->where(['customer_id' => $customer_id])->column('contract_id');
377
                 $contractIds = db('crm_contract')->where(['customer_id' => $customer_id])->column('contract_id');
382
             }
385
             }
383
             //修改记录
386
             //修改记录
384
             updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户转移给:' . $ownerUserName);
387
             updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户转移给:' . $ownerUserName);
385
-            RecordActionLog($userInfo['id'], 'crm_customer', 'transfer',$customerInfo['name'], '','','将客户:'.$customerInfo['name'].'转移给:' . $ownerUserName);
388
+            RecordActionLog($userInfo['id'], 'crm_customer', 'transfer', $customerInfo['name'], '', '', '将客户:' . $customerInfo['name'] . '转移给:' . $ownerUserName);
386
         }
389
         }
387
         if (!$errorMessage) {
390
         if (!$errorMessage) {
388
             return resultArray(['data' => '转移成功']);
391
             return resultArray(['data' => '转移成功']);
390
             return resultArray(['error' => $errorMessage]);
393
             return resultArray(['error' => $errorMessage]);
391
         }
394
         }
392
     }
395
     }
393
-    
396
+
394
     /**
397
     /**
395
      * 客户放入公海(负责人置为0)
398
      * 客户放入公海(负责人置为0)
396
      * @param
399
      * @param
407
         $userId = $userInfo['id'];
410
         $userId = $userInfo['id'];
408
         $customerIds = $this->param['customer_id'];
411
         $customerIds = $this->param['customer_id'];
409
         $poolId = $this->param['pool_id'];
412
         $poolId = $this->param['pool_id'];
410
-        $customerModel=new \app\crm\model\Customer();
413
+        $customerModel = new \app\crm\model\Customer();
411
         # 消息数据
414
         # 消息数据
412
         $message = [];
415
         $message = [];
413
 
416
 
414
         # 获取客户数据
417
         # 获取客户数据
415
         $customerData = [];
418
         $customerData = [];
416
         $customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name'])->whereIn('customer_id', $customerIds)->select();
419
         $customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name'])->whereIn('customer_id', $customerIds)->select();
417
-        foreach ($customerList AS $key => $value) {
420
+        foreach ($customerList as $key => $value) {
418
             $customerData[$value['customer_id']] = $value;
421
             $customerData[$value['customer_id']] = $value;
419
         }
422
         }
420
 
423
 
424
         $poolRecordData = [];
427
         $poolRecordData = [];
425
         $fieldRecordData = [];
428
         $fieldRecordData = [];
426
         $operationLogData = [];
429
         $operationLogData = [];
427
-        foreach ($customerIds AS $key => $value)
428
-        {
430
+        foreach ($customerIds as $key => $value) {
429
             if (empty($customerData[$value])) {
431
             if (empty($customerData[$value])) {
430
                 $message[] = '将客户放入公海失败,错误原因:数据不存在!';
432
                 $message[] = '将客户放入公海失败,错误原因:数据不存在!';
431
                 unset($customerIds[(int)$key]);
433
                 unset($customerIds[(int)$key]);
458
             ];
460
             ];
459
             # 字段操作记录数据
461
             # 字段操作记录数据
460
             $fieldRecordData[] = [
462
             $fieldRecordData[] = [
461
-                'user_id'     => $userId,
462
-                'types'       => 'crm_customer',
463
-                'action_id'   => $value,
464
-                'content'     => '将客户放入公海',
463
+                'user_id' => $userId,
464
+                'types' => 'crm_customer',
465
+                'action_id' => $value,
466
+                'content' => '将客户放入公海',
465
                 'create_time' => time()
467
                 'create_time' => time()
466
             ];
468
             ];
467
             # 数据操作日志数据
469
             # 数据操作日志数据
468
             $operationLogData[] = [
470
             $operationLogData[] = [
469
-                'user_id'     => $userId,
470
-                'client_ip'   => $ip,
471
-                'module'      => 'crm_customer',
472
-                'action_id'   => $value,
473
-                'content'     => '将客户放入公海',
471
+                'user_id' => $userId,
472
+                'client_ip' => $ip,
473
+                'module' => 'crm_customer',
474
+                'action_id' => $value,
475
+                'content' => '将客户放入公海',
474
                 'create_time' => time(),
476
                 'create_time' => time(),
475
                 'action_name' => 'update',
477
                 'action_name' => 'update',
476
                 'target_name' => !empty($customerData[$value]['name']) ? $customerData[$value]['name'] : ''
478
                 'target_name' => !empty($customerData[$value]['name']) ? $customerData[$value]['name'] : ''
488
                 'owner_user_id' => 0,
490
                 'owner_user_id' => 0,
489
                 'into_pool_time' => time()
491
                 'into_pool_time' => time()
490
             ]);
492
             ]);
491
-          
493
+
492
             # 删除联系人的负责人
494
             # 删除联系人的负责人
493
             Db::name('crm_contacts')->whereIn('customer_id', $customerIds)->update(['owner_user_id' => 0]);
495
             Db::name('crm_contacts')->whereIn('customer_id', $customerIds)->update(['owner_user_id' => 0]);
494
-           
496
+
495
             # 将客户放入公海
497
             # 将客户放入公海
496
             Db::name('crm_customer_pool_relation')->insertAll($poolRelationData);
498
             Db::name('crm_customer_pool_relation')->insertAll($poolRelationData);
497
-            
499
+
498
             # 公海操作记录
500
             # 公海操作记录
499
             Db::name('crm_customer_pool_record')->insertAll($poolRecordData);
501
             Db::name('crm_customer_pool_record')->insertAll($poolRecordData);
500
-           
502
+
501
             # 字段操作记录
503
             # 字段操作记录
502
             Db::name('admin_action_record')->insertAll($fieldRecordData);
504
             Db::name('admin_action_record')->insertAll($fieldRecordData);
503
 
505
 
557
 //            return resultArray(['error' => $errorMessage]);
559
 //            return resultArray(['error' => $errorMessage]);
558
 //        }
560
 //        }
559
     }
561
     }
560
-    
562
+
561
     /**
563
     /**
562
      * 客户锁定,解锁
564
      * 客户锁定,解锁
563
      * @param is_lock 1锁定,2解锁
565
      * @param is_lock 1锁定,2解锁
599
             //已成交客户,锁定,提示无需锁定
601
             //已成交客户,锁定,提示无需锁定
600
             // if ($customerInfo['deal_status'] == '已成交' && $is_lock == 1) {
602
             // if ($customerInfo['deal_status'] == '已成交' && $is_lock == 1) {
601
             //     $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:已成交状态,无需锁定';
603
             //     $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:已成交状态,无需锁定';
602
-            //     continue;                 
603
-            // }         
604
+            //     continue;
605
+            // }
604
             $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data);
606
             $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data);
605
             if (!$resCustomer) {
607
             if (!$resCustomer) {
606
                 $errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:数据出错;';
608
                 $errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:数据出错;';
607
             }
609
             }
608
             //修改记录
610
             //修改记录
609
             updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户' . $lock_name);
611
             updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户' . $lock_name);
610
-            if($is_lock == 2){
611
-                RecordActionLog($userInfo['id'], 'crm_customer', 'islock',$customerInfo['name'], '','','将客户'.$customerInfo['name'].$lock_name );
612
-            }else{
613
-                RecordActionLog($userInfo['id'], 'crm_customer', 'lock',$customerInfo['name'], '','','将客户'.$customerInfo['name'].$lock_name );
612
+            if ($is_lock == 2) {
613
+                RecordActionLog($userInfo['id'], 'crm_customer', 'islock', $customerInfo['name'], '', '', '将客户' . $customerInfo['name'] . $lock_name);
614
+            } else {
615
+                RecordActionLog($userInfo['id'], 'crm_customer', 'lock', $customerInfo['name'], '', '', '将客户' . $customerInfo['name'] . $lock_name);
614
             }
616
             }
615
         }
617
         }
616
         if (!$errorMessage) {
618
         if (!$errorMessage) {
619
             return resultArray(['error' => $errorMessage]);
621
             return resultArray(['error' => $errorMessage]);
620
         }
622
         }
621
     }
623
     }
622
-    
624
+
623
     /**
625
     /**
624
      * 客户领取
626
      * 客户领取
625
      * @param
627
      * @param
632
         $userInfo = $this->userInfo;
634
         $userInfo = $this->userInfo;
633
         $customerModel = model('Customer');
635
         $customerModel = model('Customer');
634
         $customerConfigModel = model('CustomerConfig');
636
         $customerConfigModel = model('CustomerConfig');
635
-        
637
+
636
         $customer_ids = $param['customer_id'] ?: $userInfo['id'];
638
         $customer_ids = $param['customer_id'] ?: $userInfo['id'];
637
         if (!$customer_ids || !is_array($customer_ids)) {
639
         if (!$customer_ids || !is_array($customer_ids)) {
638
             return resultArray(['error' => '请选择需要领取的客户']);
640
             return resultArray(['error' => '请选择需要领取的客户']);
671
             db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $userInfo['id']]);
673
             db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $userInfo['id']]);
672
             //修改记录
674
             //修改记录
673
             updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '领取了客户');
675
             updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '领取了客户');
674
-            RecordActionLog($userInfo['id'], 'crm_customer', 'update',$dataName, '','','领取了客户:'.$dataName);
676
+            RecordActionLog($userInfo['id'], 'crm_customer', 'update', $dataName, '', '', '领取了客户:' . $dataName);
675
         }
677
         }
676
         if (!$errorMessage) {
678
         if (!$errorMessage) {
677
             return resultArray(['data' => '领取成功']);
679
             return resultArray(['data' => '领取成功']);
679
             return resultArray(['error' => $errorMessage]);
681
             return resultArray(['error' => $errorMessage]);
680
         }
682
         }
681
     }
683
     }
682
-    
684
+
683
     /**
685
     /**
684
      * 客户分配
686
      * 客户分配
685
      * @param
687
      * @param
693
         $customerModel = model('Customer');
695
         $customerModel = model('Customer');
694
         $userModel = new \app\admin\model\User();
696
         $userModel = new \app\admin\model\User();
695
         $customerConfigModel = model('CustomerConfig');
697
         $customerConfigModel = model('CustomerConfig');
696
-        
698
+
697
         $customer_ids = $param['customer_id'];
699
         $customer_ids = $param['customer_id'];
698
         $owner_user_id = $param['owner_user_id'];
700
         $owner_user_id = $param['owner_user_id'];
699
         if (!$customer_ids || !is_array($customer_ids)) {
701
         if (!$customer_ids || !is_array($customer_ids)) {
703
             return resultArray(['error' => '请选择分配人']);
705
             return resultArray(['error' => '请选择分配人']);
704
         }
706
         }
705
         $ownerUserName = $userModel->getUserNameById($owner_user_id);
707
         $ownerUserName = $userModel->getUserNameById($owner_user_id);
706
-        
708
+
707
         $errorMessage = [];
709
         $errorMessage = [];
708
         $wherePool = $customerModel->getWhereByPool();
710
         $wherePool = $customerModel->getWhereByPool();
709
         foreach ($customer_ids as $k => $v) {
711
         foreach ($customer_ids as $k => $v) {
738
             db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $owner_user_id]);
740
             db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $owner_user_id]);
739
             //修改记录
741
             //修改记录
740
             updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '将客户分配给:' . $ownerUserName);
742
             updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '将客户分配给:' . $ownerUserName);
741
-            RecordActionLog($userInfo['id'], 'crm_customer', 'distribute',$dataName, '','','将客户'.$dataName.'分配给:' . $ownerUserName);
743
+            RecordActionLog($userInfo['id'], 'crm_customer', 'distribute', $dataName, '', '', '将客户' . $dataName . '分配给:' . $ownerUserName);
742
             //站内信
744
             //站内信
743
             $send_user_id[] = $owner_user_id;
745
             $send_user_id[] = $owner_user_id;
744
             $sendContent = $userInfo['realname'] . '将客户《' . $dataName . '》,分配给您';
746
             $sendContent = $userInfo['realname'] . '将客户《' . $dataName . '》,分配给您';
752
             return resultArray(['error' => $errorMessage]);
754
             return resultArray(['error' => $errorMessage]);
753
         }
755
         }
754
     }
756
     }
755
-    
757
+
756
     /**
758
     /**
757
      * 客户导出
759
      * 客户导出
758
      * @param
760
      * @param
764
         $param = $this->param;
766
         $param = $this->param;
765
         $userInfo = $this->userInfo;
767
         $userInfo = $this->userInfo;
766
         $param['user_id'] = $userInfo['id'];
768
         $param['user_id'] = $userInfo['id'];
767
-        $action_name='导出全部';
769
+        $action_name = '导出全部';
768
         if ($param['customer_id']) {
770
         if ($param['customer_id']) {
769
             $param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => ''];
771
             $param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => ''];
770
-            $action_name='导出选中';
772
+            $action_name = '导出选中';
771
         }
773
         }
772
         $param['is_excel'] = 1;
774
         $param['is_excel'] = 1;
773
         $excelModel = new \app\admin\model\Excel();
775
         $excelModel = new \app\admin\model\Excel();
774
         // 导出的字段列表
776
         // 导出的字段列表
775
         $fieldModel = new \app\admin\model\Field();
777
         $fieldModel = new \app\admin\model\Field();
776
-        $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id'],'','excel');
778
+        $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id'], '', 'excel');
777
         // 文件名
779
         // 文件名
778
         $file_name = '5kcrm_customer_' . date('Ymd');
780
         $file_name = '5kcrm_customer_' . date('Ymd');
779
-        
781
+
780
         $model = model('Customer');
782
         $model = model('Customer');
781
         $temp_file = $param['temp_file'];
783
         $temp_file = $param['temp_file'];
782
         unset($param['temp_file']);
784
         unset($param['temp_file']);
783
         $page = $param['page'] ?: 1;
785
         $page = $param['page'] ?: 1;
784
         unset($param['page']);
786
         unset($param['page']);
785
         unset($param['export_queue_index']);
787
         unset($param['export_queue_index']);
786
-        RecordActionLog($userInfo['id'],'crm_customer','excelexport',$action_name,'','','导出客户');
788
+        RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出客户');
787
         return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
789
         return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
788
             $param['page'] = $page;
790
             $param['page'] = $page;
789
             $param['limit'] = $limit;
791
             $param['limit'] = $limit;
791
             $data['list'] = $model->exportHandle($data['list'], $field_list, 'customer');
793
             $data['list'] = $model->exportHandle($data['list'], $field_list, 'customer');
792
             return $data;
794
             return $data;
793
         });
795
         });
794
-       
796
+
795
     }
797
     }
796
-    
798
+
797
     /**
799
     /**
798
      * 客户导入模板下载
800
      * 客户导入模板下载
799
      * @param string $save_path 本地保存路径     用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
801
      * @param string $save_path 本地保存路径     用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
811
         $fieldParam['types'] = 'crm_customer';
813
         $fieldParam['types'] = 'crm_customer';
812
         $fieldParam['action'] = 'excel';
814
         $fieldParam['action'] = 'excel';
813
         $field_list = $fieldModel->field($fieldParam);
815
         $field_list = $fieldModel->field($fieldParam);
814
-        $field=[1=>[
815
-           'field'=>'owner_user_id',
816
-           'types'=>'crm_customer',
817
-           'name'=>'负责人',
818
-           'form_type'=>'user',
819
-           'default_value'=>'',
820
-           'is_null' => 1,
821
-           'input_tips' =>'',
822
-           'setting' => Array(),
823
-            'is_hidden'=>0,
816
+        $field = [1 => [
817
+            'field' => 'owner_user_id',
818
+            'types' => 'crm_customer',
819
+            'name' => '负责人',
820
+            'form_type' => 'user',
821
+            'default_value' => '',
822
+            'is_null' => 1,
823
+            'input_tips' => '',
824
+            'setting' => array(),
825
+            'is_hidden' => 0,
824
             'writeStatus' => 1,
826
             'writeStatus' => 1,
825
             'value' => '']
827
             'value' => '']
826
         ];
828
         ];
827
-        $first_array = array_splice($field_list, 2,0, $field);
829
+        $first_array = array_splice($field_list, 2, 0, $field);
828
         $excelModel->excelImportDownload($field_list, 'crm_customer', $save_path);
830
         $excelModel->excelImportDownload($field_list, 'crm_customer', $save_path);
829
     }
831
     }
830
-    
831
-    
832
+
833
+
832
     /**
834
     /**
833
      * 客户数据导入
835
      * 客户数据导入
834
      * @param
836
      * @param
848
         $file = request()->file('file');
850
         $file = request()->file('file');
849
         // $res = $excelModel->importExcel($file, $param, $this);
851
         // $res = $excelModel->importExcel($file, $param, $this);
850
         $res = $excelModel->batchImportData($file, $param, $this);
852
         $res = $excelModel->batchImportData($file, $param, $this);
851
-        RecordActionLog($userInfo['id'],'crm_customer','excel','导入客户','','','导入客户');
853
+        RecordActionLog($userInfo['id'], 'crm_customer', 'excel', '导入客户', '', '', '导入客户');
852
         return resultArray(['data' => $excelModel->getError()]);
854
         return resultArray(['data' => $excelModel->getError()]);
853
     }
855
     }
854
-    
856
+
855
     /**
857
     /**
856
      * 客户标记为已跟进
858
      * 客户标记为已跟进
857
      * @param
859
      * @param
873
         }
875
         }
874
         return resultArray(['data' => '跟进成功']);
876
         return resultArray(['data' => '跟进成功']);
875
     }
877
     }
876
-    
878
+
877
     /**
879
     /**
878
      * 置顶 / 取消置顶
880
      * 置顶 / 取消置顶
879
      * @return [type] [description]
881
      * @return [type] [description]
880
      */
882
      */
881
     public function top()
883
     public function top()
882
     {
884
     {
885
+        $customerModel=model('Customer');
883
         $param = $this->param;
886
         $param = $this->param;
884
         $userInfo = $this->userInfo;
887
         $userInfo = $this->userInfo;
885
         $param['create_role_id'] = $userInfo['id'];
888
         $param['create_role_id'] = $userInfo['id'];
886
         $param['top_time'] = time();
889
         $param['top_time'] = time();
887
-        
890
+
888
         $top_id = Db::name('crm_top')->where(['module' => ['eq', $param['module']], 'create_role_id' => ['eq', $userInfo['id']], 'module_id' => ['eq', $param['module_id']]])->column('top_id');
891
         $top_id = Db::name('crm_top')->where(['module' => ['eq', $param['module']], 'create_role_id' => ['eq', $userInfo['id']], 'module_id' => ['eq', $param['module_id']]])->column('top_id');
889
         if ($top_id) {
892
         if ($top_id) {
890
             if ($res = Db::name('crm_top')->where('top_id', $top_id[0])->update($param)) {
893
             if ($res = Db::name('crm_top')->where('top_id', $top_id[0])->update($param)) {
900
             }
903
             }
901
         }
904
         }
902
     }
905
     }
903
-    
904
-    /**
905
-     * 客户公海导出
906
-     * @param
907
-     * @return
908
-     * @author Michael_xu
909
-     */
910
-    public function poolExcelExport()
911
-    {
912
-        $param = $this->param;
913
-        $userInfo = $this->userInfo;
914
-        $param['user_id'] = $userInfo['id'];
915
-        if ($param['customer_id']) {
916
-            $param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => ''];
917
-            $action_name='导出选中';
918
-        }
919
-        $param['is_excel'] = 1;
920
-        $excelModel = new \app\admin\model\Excel();
921
-        // 导出的字段列表
922
-        $fieldModel = new \app\admin\model\Field();
923
-        $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id']);
924
-        $field_list = array_filter($field_list, function ($val) {
925
-            return $val['field'] != 'owner_user_id';
926
-        });
927
-        // 文件名
928
-        $file_name = '5kcrm_customer_pool_' . date('Ymd');
929
-        $param['action'] = 'pool';
930
 
906
 
931
-        $model = model('Customer');
932
-        $temp_file = $param['temp_file'];
933
-        unset($param['temp_file']);
934
-        $page = $param['page'] ?: 1;
935
-        unset($param['page']);
936
-        unset($param['export_queue_index']);
937
-        RecordActionLog($userInfo['id'],'crm_customer','excelexport',$action_name,'','','导出客户');
938
-        return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param) {
939
-            $param['page'] = $page;
940
-            $param['limit'] = $limit;
941
-            $data = $model->getDataList($param);
942
-            $data['list'] = $model->exportHandle($data['list'],  $field_list,'crm_customer');
943
-            return $data;
944
-        });
945
-    }
946
-    
947
     /**
907
     /**
948
      * 客户成交状态
908
      * 客户成交状态
949
      * @param status 1已成交,2未成交
909
      * @param status 1已成交,2未成交
1001
             }
961
             }
1002
             //修改记录
962
             //修改记录
1003
             updateActionLog($userInfo['id'], 'crm_customer', $customer_id, ['deal_status' => $dataInfo['deal_status']], ['deal_status' => $data['deal_status']]);
963
             updateActionLog($userInfo['id'], 'crm_customer', $customer_id, ['deal_status' => $dataInfo['deal_status']], ['deal_status' => $data['deal_status']]);
1004
-            if($param['status']==1){
1005
-                RecordActionLog($userInfo['id'], 'crm_customer', 'status',$dataInfo['name'], '','','修改客户:'.$dataInfo['name'].'成交状态:'.$statusArr[$param['status']]);
1006
-            }else{
1007
-                RecordActionLog($userInfo['id'], 'crm_customer', 'status',$dataInfo['name'], '','','修改客户:'.$dataInfo['name'].'成交状态:'.$statusArr[$param['status']]);
964
+            if ($param['status'] == 1) {
965
+                RecordActionLog($userInfo['id'], 'crm_customer', 'status', $dataInfo['name'], '', '', '修改客户:' . $dataInfo['name'] . '成交状态:' . $statusArr[$param['status']]);
966
+            } else {
967
+                RecordActionLog($userInfo['id'], 'crm_customer', 'status', $dataInfo['name'], '', '', '修改客户:' . $dataInfo['name'] . '成交状态:' . $statusArr[$param['status']]);
1008
             }
968
             }
1009
         }
969
         }
1010
         if (!$errorMessage) {
970
         if (!$errorMessage) {
1013
             return resultArray(['error' => $errorMessage]);
973
             return resultArray(['error' => $errorMessage]);
1014
         }
974
         }
1015
     }
975
     }
1016
-    
976
+
1017
     /**
977
     /**
1018
      * 设置关注
978
      * 设置关注
1019
      *
979
      *
1026
         $userId = $this->userInfo['id'];
986
         $userId = $this->userInfo['id'];
1027
         $targetId = $this->param['target_id'];
987
         $targetId = $this->param['target_id'];
1028
         $type = $this->param['type'];
988
         $type = $this->param['type'];
1029
-        
989
+
1030
         if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
990
         if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
1031
-        
991
+
1032
         if (!$this->setStar($type, $userId, $targetId)) {
992
         if (!$this->setStar($type, $userId, $targetId)) {
1033
             return resultArray(['error' => '设置关注失败!']);
993
             return resultArray(['error' => '设置关注失败!']);
1034
         }
994
         }
1035
-        
995
+
1036
         return resultArray(['data' => '设置关注成功!']);
996
         return resultArray(['data' => '设置关注成功!']);
1037
     }
997
     }
1038
-    
998
+
1039
     /**
999
     /**
1040
      * 附近客户
1000
      * 附近客户
1041
      *
1001
      *
1046
         if (empty($this->param['lng'])) return resultArray(['error' => '缺少经度参数!']);
1006
         if (empty($this->param['lng'])) return resultArray(['error' => '缺少经度参数!']);
1047
         if (empty($this->param['lat'])) return resultArray(['error' => '缺少纬度参数!']);
1007
         if (empty($this->param['lat'])) return resultArray(['error' => '缺少纬度参数!']);
1048
         if (empty($this->param['distance'])) return resultArray(['error' => '请选择距离!']);
1008
         if (empty($this->param['distance'])) return resultArray(['error' => '请选择距离!']);
1049
-        
1009
+
1050
         $customerModel = model('Customer');
1010
         $customerModel = model('Customer');
1051
-        
1011
+
1052
         $data = $customerModel->getNearbyList($this->param);
1012
         $data = $customerModel->getNearbyList($this->param);
1053
-        
1013
+
1054
         return resultArray(['data' => $data]);
1014
         return resultArray(['data' => $data]);
1055
     }
1015
     }
1056
-    
1016
+
1057
     /**
1017
     /**
1058
      * 系统信息
1018
      * 系统信息
1059
      *
1019
      *
1065
     public function system()
1025
     public function system()
1066
     {
1026
     {
1067
         if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']);
1027
         if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']);
1068
-        
1028
+
1069
         $customerModel = new \app\crm\model\Customer();
1029
         $customerModel = new \app\crm\model\Customer();
1070
-        
1030
+
1071
         $data = $customerModel->getSystemInfo($this->param['id']);
1031
         $data = $customerModel->getSystemInfo($this->param['id']);
1072
-        
1032
+
1073
         return resultArray(['data' => $data]);
1033
         return resultArray(['data' => $data]);
1074
     }
1034
     }
1075
-    
1035
+
1076
     /**
1036
     /**
1077
      * table标签栏数量
1037
      * table标签栏数量
1078
      *
1038
      *
1086
         if (empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']);
1046
         if (empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']);
1087
 
1047
 
1088
         $userInfo = $this->userInfo;
1048
         $userInfo = $this->userInfo;
1089
-        
1049
+
1090
         $customerId = $this->param['customer_id'];
1050
         $customerId = $this->param['customer_id'];
1091
-        
1051
+
1092
         # 联系人
1052
         # 联系人
1093
         $contactsAuth = $this->getContactsSearchWhere($userInfo['id']);
1053
         $contactsAuth = $this->getContactsSearchWhere($userInfo['id']);
1094
         $contactsCount = Db::name('crm_contacts')->where('customer_id', $customerId)->where($contactsAuth)->count();
1054
         $contactsCount = Db::name('crm_contacts')->where('customer_id', $customerId)->where($contactsAuth)->count();
1122
 
1082
 
1123
         # 附件
1083
         # 附件
1124
         $fileCount = Db::name('crm_customer_file')->alias('customer')->join('__ADMIN_FILE__ file', 'file.file_id = customer.file_id')->where('customer_id', $customerId)->count();
1084
         $fileCount = Db::name('crm_customer_file')->alias('customer')->join('__ADMIN_FILE__ file', 'file.file_id = customer.file_id')->where('customer_id', $customerId)->count();
1125
-        
1085
+
1126
         $data = [
1086
         $data = [
1127
-            'businessCount'    => $businessCount,
1128
-            'contactCount'     => $contactsCount,
1129
-            'contractCount'    => $contractCount,
1130
-            'fileCount'        => $fileCount,
1131
-            'invoiceCount'     => $invoiceCount,
1132
-            'memberCount'      => count($teamCount),
1087
+            'businessCount' => $businessCount,
1088
+            'contactCount' => $contactsCount,
1089
+            'contractCount' => $contractCount,
1090
+            'fileCount' => $fileCount,
1091
+            'invoiceCount' => $invoiceCount,
1092
+            'memberCount' => count($teamCount),
1133
             'receivablesCount' => $receivablesCount,
1093
             'receivablesCount' => $receivablesCount,
1134
             'returnVisitCount' => $visitCount
1094
             'returnVisitCount' => $visitCount
1135
         ];
1095
         ];
1136
-        
1096
+
1137
         return resultArray(['data' => $data]);
1097
         return resultArray(['data' => $data]);
1138
     }
1098
     }
1139
-    
1099
+
1140
     /**
1100
     /**
1141
      * 公海权限
1101
      * 公海权限
1142
      *
1102
      *
1155
             'index' => false, # 列表
1115
             'index' => false, # 列表
1156
             'receive' => false, # 领取
1116
             'receive' => false, # 领取
1157
         ];
1117
         ];
1158
-        
1118
+
1159
         $userId = $this->userInfo['id'];
1119
         $userId = $this->userInfo['id'];
1160
-        
1120
+
1161
         if (empty($userId)) return resultArray(['data' => $authority]);
1121
         if (empty($userId)) return resultArray(['data' => $authority]);
1162
-        
1122
+
1163
         # 员工角色数据
1123
         # 员工角色数据
1164
         $groupIds = $customerLogic->getEmployeeGroups($userId);
1124
         $groupIds = $customerLogic->getEmployeeGroups($userId);
1165
         # 员工角色下的规则数据
1125
         # 员工角色下的规则数据
1166
         $ruleIds = $customerLogic->getEmployeeRules($groupIds);
1126
         $ruleIds = $customerLogic->getEmployeeRules($groupIds);
1167
         # 公海规则数据
1127
         # 公海规则数据
1168
         $poolRules = $customerLogic->getPoolRules();
1128
         $poolRules = $customerLogic->getPoolRules();
1169
-        
1129
+
1170
         # 整理员工规则数据
1130
         # 整理员工规则数据
1171
         $rules = [];
1131
         $rules = [];
1172
         $ruleIds = implode(',', $ruleIds);
1132
         $ruleIds = implode(',', $ruleIds);
1180
             if ($value['name'] == 'poolExcelExport') $exportId = $value['id'];
1140
             if ($value['name'] == 'poolExcelExport') $exportId = $value['id'];
1181
             if ($value['name'] == 'poolDelete') $deleteId = $value['id'];
1141
             if ($value['name'] == 'poolDelete') $deleteId = $value['id'];
1182
         }
1142
         }
1183
-        
1143
+
1184
         # 权限判断
1144
         # 权限判断
1185
         $authority['delete'] = $userId == 1 || in_array(1, $groupIds) || in_array($deleteId, $rules) ? true : false;
1145
         $authority['delete'] = $userId == 1 || in_array(1, $groupIds) || in_array($deleteId, $rules) ? true : false;
1186
         $authority['distribute'] = $userId == 1 || in_array(1, $groupIds) || in_array($distributeId, $rules) ? true : false;
1146
         $authority['distribute'] = $userId == 1 || in_array(1, $groupIds) || in_array($distributeId, $rules) ? true : false;
1187
         $authority['excelexport'] = $userId == 1 || in_array(1, $groupIds) || in_array($exportId, $rules) ? true : false;
1147
         $authority['excelexport'] = $userId == 1 || in_array(1, $groupIds) || in_array($exportId, $rules) ? true : false;
1188
         $authority['index'] = $userId == 1 || in_array(1, $groupIds) || in_array($indexId, $rules) ? true : false;
1148
         $authority['index'] = $userId == 1 || in_array(1, $groupIds) || in_array($indexId, $rules) ? true : false;
1189
         $authority['receive'] = $userId == 1 || in_array(1, $groupIds) || in_array($receiveId, $rules) ? true : false;
1149
         $authority['receive'] = $userId == 1 || in_array(1, $groupIds) || in_array($receiveId, $rules) ? true : false;
1190
-        
1150
+
1191
         return resultArray(['data' => $authority]);
1151
         return resultArray(['data' => $authority]);
1192
     }
1152
     }
1193
 
1153
 
1194
     /**
1154
     /**
1195
      * 客户级别列表
1155
      * 客户级别列表
1196
      *
1156
      *
1197
-     * @author fanqi
1198
-     * @since 2021-03-29
1199
      * @return \think\response\Json
1157
      * @return \think\response\Json
1158
+     * @since 2021-03-29
1159
+     * @author fanqi
1200
      */
1160
      */
1201
     public function level()
1161
     public function level()
1202
     {
1162
     {

+ 3
- 1
application/crm/controller/CustomerPool.php Просмотреть файл

371
                     }
371
                     }
372
                     break;
372
                     break;
373
                 case 'detail_address':
373
                 case 'detail_address':
374
-                    unset($pool_list[$k]);
374
+                    if($param['is_excel']!=1){
375
+                        unset($pool_list[$k]);
376
+                    }
375
                     break;
377
                     break;
376
                 case ($v['form_type'] == 'select') || ($v['form_type'] == 'checkbox') :
378
                 case ($v['form_type'] == 'select') || ($v['form_type'] == 'checkbox') :
377
                     $set= db('admin_field')->where(['types' => 'crm_customer', 'field' => $v['field']])->find();
379
                     $set= db('admin_field')->where(['types' => 'crm_customer', 'field' => $v['field']])->find();

+ 1
- 1
application/crm/controller/Index.php Просмотреть файл

309
         
309
         
310
         foreach ($time['list'] as $val) {
310
         foreach ($time['list'] as $val) {
311
             $item = [];
311
             $item = [];
312
-            $item['type'] = $val['type'];
312
+            $item['type'] = date('m-d',strtotime($val['type']));
313
             $item['money'] = $res_money[$val['type']]['sum'] ?: 0;
313
             $item['money'] = $res_money[$val['type']]['sum'] ?: 0;
314
             $money += $item['money'];
314
             $money += $item['money'];
315
 
315
 

+ 2
- 2
application/crm/controller/Invoice.php Просмотреть файл

135
             $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
135
             $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
136
         } else {
136
         } else {
137
             # 审批流停用,将状态改为审核通过
137
             # 审批流停用,将状态改为审核通过
138
-            $param['check_status'] = 2;
138
+            $param['check_status'] = 7;
139
         }
139
         }
140
 
140
 
141
         // 数据验证
141
         // 数据验证
350
         // }            
350
         // }            
351
         
351
         
352
         $checkStatus = $invoiceLogic->getExamineStatus($param['invoice_id']);
352
         $checkStatus = $invoiceLogic->getExamineStatus($param['invoice_id']);
353
-        if (!in_array($checkStatus, ['3', '4', '5', '6'])) return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
353
+        if (!in_array($checkStatus, ['3', '4', '5', '6', '7']) && $checkStatus!=0) return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
354
         
354
         
355
         # 自动设置发票编号
355
         # 自动设置发票编号
356
         $numberInfo = [];
356
         $numberInfo = [];

+ 3
- 0
application/crm/controller/Leads.php Просмотреть файл

233
             $data['create_time'] = time();
233
             $data['create_time'] = time();
234
             $data['update_time'] = time();
234
             $data['update_time'] = time();
235
             $data['next_time'] = $leadsInfo['next_time'];
235
             $data['next_time'] = $leadsInfo['next_time'];
236
+
236
             if (empty($data['telephone'])) $data['telephone'] = 0;
237
             if (empty($data['telephone'])) $data['telephone'] = 0;
237
             # 获取客户的时间
238
             # 获取客户的时间
238
             $data['obtain_time'] = time();
239
             $data['obtain_time'] = time();
245
                 $errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:无权限;';
246
                 $errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:无权限;';
246
                 continue;
247
                 continue;
247
             }
248
             }
249
+
248
             $resCustomer = $customerModel->createData($data);
250
             $resCustomer = $customerModel->createData($data);
251
+
249
             if (!$resCustomer) {
252
             if (!$resCustomer) {
250
                 $errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:' . $customerModel->getError();
253
                 $errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:' . $customerModel->getError();
251
                 continue;
254
                 continue;

+ 2
- 1
application/crm/controller/Message.php Просмотреть файл

490
         switch ($type) {
490
         switch ($type) {
491
             case '1' :
491
             case '1' :
492
                 $param['end_time'] = array('between',array(date('Y-m-d',time()),date('Y-m-d',time()+86400*$expireDay)));
492
                 $param['end_time'] = array('between',array(date('Y-m-d',time()),date('Y-m-d',time()+86400*$expireDay)));
493
-                $param['expire_remind'] = 1;
493
+                $param['expire_remind'] = 0;
494
                 break;
494
                 break;
495
             case '2' : $param['end_time'] = array('lt',date('Y-m-d',time())); break;
495
             case '2' : $param['end_time'] = array('lt',date('Y-m-d',time())); break;
496
         }
496
         }
497
         $data = $contractModel->getDataList($param);
497
         $data = $contractModel->getDataList($param);
498
+//        p($contractModel->getLastSql());
498
         if ($types == 'list') {
499
         if ($types == 'list') {
499
             return resultArray(['data' => $data]);
500
             return resultArray(['data' => $data]);
500
         }
501
         }

+ 19
- 5
application/crm/controller/Receivables.php Просмотреть файл

74
         $excelModel = new \app\admin\model\Excel();
74
         $excelModel = new \app\admin\model\Excel();
75
         // 导出的字段列表
75
         // 导出的字段列表
76
         $fieldModel = new \app\admin\model\Field();
76
         $fieldModel = new \app\admin\model\Field();
77
-        $field_list = $fieldModel->getIndexFieldConfig('crm_receivables', $userInfo['id']);
77
+        $field_list = $fieldModel->getIndexFieldConfig('crm_receivables', $userInfo['id'],'','excel');
78
         // 文件名
78
         // 文件名
79
         $file_name = '5kcrm_receivables_' . date('Ymd');
79
         $file_name = '5kcrm_receivables_' . date('Ymd');
80
         $model = model('Receivables');
80
         $model = model('Receivables');
148
             $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
148
             $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
149
         } else {
149
         } else {
150
             # 审批流停用,将状态改为审核通过
150
             # 审批流停用,将状态改为审核通过
151
-            $param['check_status'] = 2;
151
+            // $param['check_status'] = 2;
152
+            
153
+            # 审批流停用,将状态改为正常   zjf 20210727  默认值为7
154
+            $param['check_status'] = 7;
152
         }
155
         }
153
         
156
         
154
         $res = $receivablesModel->createData($param);
157
         $res = $receivablesModel->createData($param);
224
         }
227
         }
225
         
228
         
226
         //已进行审批,不能编辑
229
         //已进行审批,不能编辑
227
-        if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) {
230
+        if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6', '7']) && $dataInfo['check_status']!=0) {
228
             return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
231
             return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
229
         }
232
         }
230
         
233
         
271
                 }
274
                 }
272
             }
275
             }
273
         }
276
         }
274
-        
275
         $res = $receivablesModel->updateDataById($param, $param['id']);
277
         $res = $receivablesModel->updateDataById($param, $param['id']);
276
         if ($res) {
278
         if ($res) {
277
             //将审批记录至为无效
279
             //将审批记录至为无效
474
             
476
             
475
             //审批记录
477
             //审批记录
476
             $resRecord = $examineRecordModel->createData($checkData);
478
             $resRecord = $examineRecordModel->createData($checkData);
477
-            
479
+                $receivablesPlan=db('crm_receivables_plan')->where('receivables_id',$param['id'])->find();
480
+                $data=[];
481
+                $data['un_money']=$receivablesPlan['real_money']-$dataInfo['money'] <= 0 ? 0 :$receivablesPlan['un_money']-$dataInfo['money'];
482
+                $data['real_money']=$receivablesPlan['real_money']-$dataInfo['money'] <= 0 ?$dataInfo['money']:$receivablesPlan['real_money']-$dataInfo['money'];
483
+                $data['real_data']=date('Y-m-d',time());
484
+                if( $data['un_money']==0){
485
+                    $data['status']=1;
486
+                }else{
487
+                    $data['status']=2;
488
+                }
489
+            if(!db('crm_receivables_plan')->where('receivables_id',$param['id'])->update($data)){
490
+                return resultArray(['data' => '审批失败,未更新回款计划信息!']);
491
+            }
478
             if ($is_end == 1 && !empty($status)) {
492
             if ($is_end == 1 && !empty($status)) {
479
                 //发送站内信 通过
493
                 //发送站内信 通过
480
                 (new Message())->send(
494
                 (new Message())->send(

+ 38
- 1
application/crm/controller/ReceivablesPlan.php Просмотреть файл

161
         } else {
161
         } else {
162
             return resultArray(['error'=>'参数错误']);
162
             return resultArray(['error'=>'参数错误']);
163
         }        
163
         }        
164
-    }     
164
+    }
165
+    /**
166
+     * 回款计划导出
167
+     * @param
168
+     * @return
169
+     * @author Michael_xu
170
+     */
171
+    public function excelExport()
172
+    {
173
+        $param = $this->param;
174
+        $userInfo = $this->userInfo;
175
+        $param['user_id'] = $userInfo['id'];
176
+        $action_name = '导出全部';
177
+        if ($param['plan_id']) {
178
+            $param['plan_id'] = ['condition' => 'in', 'value' => $param['plan_id'], 'form_type' => 'text', 'name' => ''];
179
+            $action_name='导出选中';
180
+        }
181
+        $excelModel = new \app\admin\model\Excel();
182
+        // 导出的字段列表
183
+        $fieldModel = new \app\admin\model\Field();
184
+        $field_list = $fieldModel->getIndexFieldConfig('crm_receivables_plan', $userInfo['id'],'','excel');
185
+        // 文件名
186
+        $file_name = '5kcrm_receivables_plan_' . date('Ymd');
187
+        $model = model('ReceivablesPlan');
188
+        $temp_file = $param['temp_file'];
189
+        unset($param['temp_file']);
190
+        $page = $param['page'] ?: 1;
191
+        unset($param['page']);
192
+        unset($param['export_queue_index']);
193
+//        RecordActionLog($userInfo['id'],'crm_receivables_plan','excelexport',$action_name,'','','导出回款');
194
+        return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
195
+            $param['page'] = $page;
196
+            $param['limit'] = $limit;
197
+            $data = $model->getDataList($param);
198
+            $data['list'] = $model->exportHandle($data['list'], $field_list, 'ReceivablesPlan');
199
+            return $data;
200
+        });
201
+    }
165
 }
202
 }

+ 3
- 1
application/crm/logic/ActivityLogic.php Просмотреть файл

442
         $param['type']           = 1;
442
         $param['type']           = 1;
443
         $param['next_time']      = !empty($param['next_time'])    ? strtotime($param['next_time'])        : 0;
443
         $param['next_time']      = !empty($param['next_time'])    ? strtotime($param['next_time'])        : 0;
444
         $param['business_ids']   = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : '';
444
         $param['business_ids']   = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : '';
445
-        $param['create_time']    = time();
445
+       
446
         $param['update_time']    = time();
446
         $param['update_time']    = time();
447
         if(empty($param['excel'])){
447
         if(empty($param['excel'])){
448
             if (!empty($param['contacts_ids'])) $param['contacts_ids'] = ',' . $param['contacts_ids'] . ',';
448
             if (!empty($param['contacts_ids'])) $param['contacts_ids'] = ',' . $param['contacts_ids'] . ',';
449
         }else{
449
         }else{
450
+            $param['create_time']    = $param['create_time'];
450
             unset($param['excel']);
451
             unset($param['excel']);
451
         }
452
         }
453
+       
452
         $activityJson = Activity::create($param);
454
         $activityJson = Activity::create($param);
453
         if (empty($activityJson)) return false;
455
         if (empty($activityJson)) return false;
454
 
456
 

+ 52
- 61
application/crm/logic/IndexLogic.php Просмотреть файл

22
         '11' => 'november',
22
         '11' => 'november',
23
         '12' => 'december',
23
         '12' => 'december',
24
     ];
24
     ];
25
-    
25
+
26
     /**
26
     /**
27
      * @param $param
27
      * @param $param
28
      * @return array
28
      * @return array
31
     {
31
     {
32
         $adminModel = new \app\admin\model\Admin();
32
         $adminModel = new \app\admin\model\Admin();
33
         $userModel = new \app\admin\model\User();
33
         $userModel = new \app\admin\model\User();
34
-        $customerModel = new \app\crm\model\Customer();
35
-        $contactsModel = new \app\crm\model\Contacts();
36
-        $businessModel = new \app\crm\model\Business();
37
-        $contractModel = new \app\crm\model\Contract();
38
-        $receivablesModel = new \app\crm\model\Receivables();
39
-        $activityModel = new \app\crm\model\Activity();
40
         $last_between_time = ByDateTime($param['type']);
34
         $last_between_time = ByDateTime($param['type']);
41
         if($param['start_time'] && $param['end_time']){
35
         if($param['start_time'] && $param['end_time']){
42
             $param['start_time']=$param['start_time'].' 00:00:00';
36
             $param['start_time']=$param['start_time'].' 00:00:00';
43
             $param['end_time']=$param['end_time'].' 23:59:59';
37
             $param['end_time']=$param['end_time'].' 23:59:59';
44
         }
38
         }
45
         $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
39
         $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
46
-//        $lastArr = $adminModel->getWhere($param, 1, '', true); //统计条件
47
         $userIds = $whereArr['userIds'];
40
         $userIds = $whereArr['userIds'];
48
         $between_time = $whereArr['between_time'];
41
         $between_time = $whereArr['between_time'];
49
-   
42
+
50
         $customerNum = 0; //新增客户
43
         $customerNum = 0; //新增客户
51
         $customerLastNum = 0; //上期对比
44
         $customerLastNum = 0; //上期对比
52
         $contactsNum = 0; //新增联系人
45
         $contactsNum = 0; //新增联系人
63
         $contractLastMoneyNum = 0; //上期对比
56
         $contractLastMoneyNum = 0; //上期对比
64
         $receivablesMoneyNum = 0; //新增回款金额
57
         $receivablesMoneyNum = 0; //新增回款金额
65
         $receivablesLastMoneyNum = 0; //上期对比
58
         $receivablesLastMoneyNum = 0; //上期对比
66
-        
59
+
67
         $where = [];
60
         $where = [];
68
         $where['owner_user_id']['value'] = $userIds;
61
         $where['owner_user_id']['value'] = $userIds;
69
         $where['create_time']['start'] = $between_time[0];
62
         $where['create_time']['start'] = $between_time[0];
70
         $where['create_time']['end'] = $between_time[1];
63
         $where['create_time']['end'] = $between_time[1];
71
         $where['getCount'] = 1;
64
         $where['getCount'] = 1;
72
-        
65
+
73
         $customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
66
         $customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
74
         $contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index');
67
         $contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index');
75
         $business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index');
68
         $business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index');
100
                 'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids) ? : [-1],
93
                 'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids) ? : [-1],
101
             ])
94
             ])
102
         );
95
         );
103
-        
96
+
104
         $customerNum = (int)$resCount[0]['count1'] ?: 0;
97
         $customerNum = (int)$resCount[0]['count1'] ?: 0;
105
         $contactsNum = (int)$resCount[1]['count1'] ?: 0;
98
         $contactsNum = (int)$resCount[1]['count1'] ?: 0;
106
         $businessNum = (int)$resCount[2]['count1'] ?: 0;
99
         $businessNum = (int)$resCount[2]['count1'] ?: 0;
109
         $contractMoneyNum = $resCount[3]['count2'] ?: 0;
102
         $contractMoneyNum = $resCount[3]['count2'] ?: 0;
110
         $receivablesMoneyNum = $resCount[4]['count1'] ?: 0;
103
         $receivablesMoneyNum = $resCount[4]['count1'] ?: 0;
111
         $recordNum = (int)$resCount[5]['count1'] ?: 0;
104
         $recordNum = (int)$resCount[5]['count1'] ?: 0;
112
-        
105
+
113
         $customerLastNum = (int)$resLastCount[0]['count1'] ?: 0;
106
         $customerLastNum = (int)$resLastCount[0]['count1'] ?: 0;
114
         $contactsLastNum = (int)$resLastCount[1]['count1'] ?: 0;
107
         $contactsLastNum = (int)$resLastCount[1]['count1'] ?: 0;
115
         $businessLastNum = (int)$resLastCount[2]['count1'] ?: 0;
108
         $businessLastNum = (int)$resLastCount[2]['count1'] ?: 0;
121
         $data = [];
114
         $data = [];
122
         $data['data']['customerNum'] = $customerNum;
115
         $data['data']['customerNum'] = $customerNum;
123
         $data['prev']['customerNum'] = $this->getProportion($customerNum, $customerLastNum);
116
         $data['prev']['customerNum'] = $this->getProportion($customerNum, $customerLastNum);
124
-        
117
+
125
         $data['data']['contactsNum'] = $contactsNum;
118
         $data['data']['contactsNum'] = $contactsNum;
126
         $data['prev']['contactsNum'] = $this->getProportion($contactsNum, $contactsLastNum);
119
         $data['prev']['contactsNum'] = $this->getProportion($contactsNum, $contactsLastNum);
127
-        
120
+
128
         $data['data']['businessNum'] = $businessNum;
121
         $data['data']['businessNum'] = $businessNum;
129
         $data['prev']['businessNum'] = $this->getProportion($businessNum, $businessLastNum);
122
         $data['prev']['businessNum'] = $this->getProportion($businessNum, $businessLastNum);
130
-        
123
+
131
         $data['data']['contractNum'] = $contractNum;
124
         $data['data']['contractNum'] = $contractNum;
132
         $data['prev']['contractNum'] = $this->getProportion($contractNum, $contractLastNum);
125
         $data['prev']['contractNum'] = $this->getProportion($contractNum, $contractLastNum);
133
-        
126
+
134
         $data['data']['recordNum'] = $recordNum;
127
         $data['data']['recordNum'] = $recordNum;
135
         $data['prev']['recordNum'] = $this->getProportion($recordNum, $recordLastNum);
128
         $data['prev']['recordNum'] = $this->getProportion($recordNum, $recordLastNum);
136
-        
129
+
137
         $data['data']['businessMoneyNum'] = $businessMoneyNum;
130
         $data['data']['businessMoneyNum'] = $businessMoneyNum;
138
         $data['prev']['businessMoneyNum'] = $this->getProportion($businessMoneyNum, $businessLastMoneyNum);
131
         $data['prev']['businessMoneyNum'] = $this->getProportion($businessMoneyNum, $businessLastMoneyNum);
139
-        
132
+
140
         $data['data']['contractMoneyNum'] = $contractMoneyNum;
133
         $data['data']['contractMoneyNum'] = $contractMoneyNum;
141
         $data['prev']['contractMoneyNum'] = $this->getProportion($contractMoneyNum, $contractLastMoneyNum);
134
         $data['prev']['contractMoneyNum'] = $this->getProportion($contractMoneyNum, $contractLastMoneyNum);
142
-        
135
+
143
         $data['data']['receivablesMoneyNum'] = $receivablesMoneyNum;
136
         $data['data']['receivablesMoneyNum'] = $receivablesMoneyNum;
144
         $data['prev']['receivablesMoneyNum'] = $this->getProportion($receivablesMoneyNum, $receivablesLastMoneyNum);
137
         $data['prev']['receivablesMoneyNum'] = $this->getProportion($receivablesMoneyNum, $receivablesLastMoneyNum);
145
-        
138
+
146
         return $data;
139
         return $data;
147
     }
140
     }
148
-    
141
+
149
     public function getCountSql($param)
142
     public function getCountSql($param)
150
     {
143
     {
151
         $countSql = "SELECT
144
         $countSql = "SELECT
196
         and create_user_id IN (" . implode(',', $param['record_auth_user_ids']) . ")";
189
         and create_user_id IN (" . implode(',', $param['record_auth_user_ids']) . ")";
197
         return $countSql;
190
         return $countSql;
198
     }
191
     }
199
-    
192
+
200
     ///计算涨幅
193
     ///计算涨幅
201
     public function getProportion($now, $last)
194
     public function getProportion($now, $last)
202
     {
195
     {
211
         }
204
         }
212
         return $res;
205
         return $res;
213
     }
206
     }
214
-    
215
-    
207
+
208
+
216
     /**
209
     /**
217
      * 遗忘数据统计
210
      * 遗忘数据统计
218
      * @return mixed
211
      * @return mixed
233
         $auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
226
         $auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
234
         $auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
227
         $auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
235
         $owner_user_ids = array('in', $auth_customer_user_ids);
228
         $owner_user_ids = array('in', $auth_customer_user_ids);
236
-        
229
+
237
         $customerParam = [];
230
         $customerParam = [];
238
         $customerParam['limit'] = $param['limit'];
231
         $customerParam['limit'] = $param['limit'];
239
         $customerParam['page'] = $param['page'];
232
         $customerParam['page'] = $param['page'];
240
         $customerParam['search'] = $param['search'];
233
         $customerParam['search'] = $param['search'];
241
         $customerParam['getCount'] = 1;
234
         $customerParam['getCount'] = 1;
242
         $customerParam['owner_user_id'] = $owner_user_ids;
235
         $customerParam['owner_user_id'] = $owner_user_ids;
243
-        
236
+
244
         $sevenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-1 week') . ") ";
237
         $sevenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-1 week') . ") ";
245
         $fifteenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-15 day') . ") ";
238
         $fifteenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-15 day') . ") ";
246
         $oneMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-30 day') . ") ";
239
         $oneMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-30 day') . ") ";
253
         $data['threeMonth'] = $customerModel->getDataList(array_merge($customerParam, $threeMonthParam))['dataCount'] ?: 0;
246
         $data['threeMonth'] = $customerModel->getDataList(array_merge($customerParam, $threeMonthParam))['dataCount'] ?: 0;
254
         $data['sixMonth'] = $customerModel->getDataList(array_merge($customerParam, $sixMonthParam))['dataCount'] ?: 0;
247
         $data['sixMonth'] = $customerModel->getDataList(array_merge($customerParam, $sixMonthParam))['dataCount'] ?: 0;
255
         $data['unContactCustomerCount'] = $customerModel->getDataList(array_merge($customerParam, $unContactParam))['dataCount'] ?: 0;
248
         $data['unContactCustomerCount'] = $customerModel->getDataList(array_merge($customerParam, $unContactParam))['dataCount'] ?: 0;
256
-        
249
+
257
         return $data;
250
         return $data;
258
     }
251
     }
259
-    
252
+
260
     /**
253
     /**
261
      * 遗忘数据列表
254
      * 遗忘数据列表
262
      * @return mixed
255
      * @return mixed
279
         $auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
272
         $auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
280
         $auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
273
         $auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
281
         $owner_user_ids = array('in', $auth_customer_user_ids);
274
         $owner_user_ids = array('in', $auth_customer_user_ids);
282
-        
275
+
283
         $sql_unContactCustomerList = db('crm_customer')
276
         $sql_unContactCustomerList = db('crm_customer')
284
             ->where(['owner_user_id' => $owner_user_ids])
277
             ->where(['owner_user_id' => $owner_user_ids])
285
             ->where('last_time < next_time AND next_time < now()')
278
             ->where('last_time < next_time AND next_time < now()')
286
             ->fetchSql()
279
             ->fetchSql()
287
             ->select();
280
             ->select();
288
-        
281
+
289
         $label = $param['label'];
282
         $label = $param['label'];
290
         $day = $param['day'] ?: '';
283
         $day = $param['day'] ?: '';
291
         $customerParam = [];
284
         $customerParam = [];
293
         $customerParam['page'] = $param['page'];
286
         $customerParam['page'] = $param['page'];
294
         $customerParam['search'] = $param['search'];
287
         $customerParam['search'] = $param['search'];
295
         $customerParam['owner_user_id'] = $owner_user_ids;
288
         $customerParam['owner_user_id'] = $owner_user_ids;
296
-        
289
+
297
         switch ($label) {
290
         switch ($label) {
298
             case 1 :
291
             case 1 :
299
 //                ((( next_time < " . strtotime(date('Y-m-d 00:00:00')).") AND (last_time IS NOT NULL))  AND (IFNULL(last_time,next_time) >0))
292
 //                ((( next_time < " . strtotime(date('Y-m-d 00:00:00')).") AND (last_time IS NOT NULL))  AND (IFNULL(last_time,next_time) >0))
317
         }
310
         }
318
         return $customerModel->getDataList($customerParam);
311
         return $customerModel->getDataList($customerParam);
319
     }
312
     }
320
-    
313
+
321
     /**
314
     /**
322
      * 排行榜
315
      * 排行榜
323
      * @param $param
316
      * @param $param
338
         $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
331
         $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
339
         $userIds = $whereArr['userIds'];
332
         $userIds = $whereArr['userIds'];
340
         $between_time = $whereArr['between_time'];
333
         $between_time = $whereArr['between_time'];
341
-        
334
+
342
         $auth_user_ids = $userModel->getUserByPer('bi', 'ranking', 'read');
335
         $auth_user_ids = $userModel->getUserByPer('bi', 'ranking', 'read');
343
         $auth_user_ids = $auth_user_ids ? array_intersect($userIds, $auth_user_ids) : []; //取交集
336
         $auth_user_ids = $auth_user_ids ? array_intersect($userIds, $auth_user_ids) : []; //取交集
344
         switch ($param['label']) {
337
         switch ($param['label']) {
533
             $ranking['ranking'][] = $v;
526
             $ranking['ranking'][] = $v;
534
             $ranking['self'] = $list['self'];
527
             $ranking['self'] = $list['self'];
535
         }
528
         }
536
-        
529
+
537
         $data = [];
530
         $data = [];
538
         $data = $ranking ?: [];
531
         $data = $ranking ?: [];
539
         return $data;
532
         return $data;
540
     }
533
     }
541
-    
534
+
542
     /**
535
     /**
543
      * 数据汇总
536
      * 数据汇总
544
      * @param $param
537
      * @param $param
555
         $user_id = $param['user_id'] ?: [-1];
548
         $user_id = $param['user_id'] ?: [-1];
556
         $userIds = $whereArr['userIds'];
549
         $userIds = $whereArr['userIds'];
557
         $between_time = $whereArr['between_time'];
550
         $between_time = $whereArr['between_time'];
558
-        
551
+
559
         $customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
552
         $customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
560
         $contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index');
553
         $contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index');
561
         $business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index');
554
         $business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index');
583
         }
576
         }
584
         return $resDataArr;
577
         return $resDataArr;
585
     }
578
     }
586
-    
579
+
587
     /**
580
     /**
588
      * [数据汇总sql]
581
      * [数据汇总sql]
589
      * @return
582
      * @return
659
         }
652
         }
660
         return $countSql;
653
         return $countSql;
661
     }
654
     }
662
-    
655
+
663
     /**
656
     /**
664
      * 销售漏斗查看
657
      * 销售漏斗查看
665
      */
658
      */
680
         $param['scene_id'] = $scene_id ?: '';
673
         $param['scene_id'] = $scene_id ?: '';
681
         $param['create_time']['start'] = $start_time;
674
         $param['create_time']['start'] = $start_time;
682
         $param['create_time']['end'] = $end_time;
675
         $param['create_time']['end'] = $end_time;
683
-        
676
+
684
         $param['owner_user_id']['value'] =  $userIds;
677
         $param['owner_user_id']['value'] =  $userIds;
685
         unset($param['type']);
678
         unset($param['type']);
686
         unset($param['dataType']);
679
         unset($param['dataType']);
691
         $data=$businessModel->getDataList($param);
684
         $data=$businessModel->getDataList($param);
692
         return $data;
685
         return $data;
693
     }
686
     }
694
-    
687
+
695
     /**
688
     /**
696
      * 仪表盘布局列表
689
      * 仪表盘布局列表
697
      */
690
      */
699
     {
692
     {
700
         $data = [];
693
         $data = [];
701
         $list = db('crm_dashboard')->where('user_id', $param['user_id'])->find();
694
         $list = db('crm_dashboard')->where('user_id', $param['user_id'])->find();
702
-        
695
+
703
         if ($list) {
696
         if ($list) {
704
             $data = unserialize($list['dashboard']);
697
             $data = unserialize($list['dashboard']);
705
             return $data ?: [];
698
             return $data ?: [];
713
             $data['left'][2]['modelId'] = 7;
706
             $data['left'][2]['modelId'] = 7;
714
             $data['left'][2]['list'] = 1;
707
             $data['left'][2]['list'] = 1;
715
             $data['left'][2]['isHidden'] = 0;
708
             $data['left'][2]['isHidden'] = 0;
716
-            
709
+
717
             $data['right'][0]['modelId'] = 2;
710
             $data['right'][0]['modelId'] = 2;
718
             $data['right'][0]['list'] = 2;
711
             $data['right'][0]['list'] = 2;
719
             $data['right'][0]['isHidden'] = 0;
712
             $data['right'][0]['isHidden'] = 0;
725
             $data['right'][2]['isHidden'] = 0;
718
             $data['right'][2]['isHidden'] = 0;
726
             return $data;
719
             return $data;
727
         }
720
         }
728
-        
721
+
729
     }
722
     }
730
-    
723
+
731
     /**
724
     /**
732
      * 修改自定义仪表盘
725
      * 修改自定义仪表盘
733
      * @param $param
726
      * @param $param
734
      */
727
      */
735
     public function updateDashboard($param)
728
     public function updateDashboard($param)
736
     {
729
     {
737
-        
730
+
738
         $data = db('crm_dashboard')->where('user_id', $param['user_id'])->find();
731
         $data = db('crm_dashboard')->where('user_id', $param['user_id'])->find();
739
         if ($data) {
732
         if ($data) {
740
             $list = db('crm_dashboard')->where('user_id', $param['user_id'])->update(['dashboard' => serialize($param['dashboard'])]);
733
             $list = db('crm_dashboard')->where('user_id', $param['user_id'])->update(['dashboard' => serialize($param['dashboard'])]);
743
             $list = db('crm_dashboard')->insert(['user_id' => $param['user_id'], 'dashboard' => serialize($param['dashboard'])]);
736
             $list = db('crm_dashboard')->insert(['user_id' => $param['user_id'], 'dashboard' => serialize($param['dashboard'])]);
744
             return $list;
737
             return $list;
745
         }
738
         }
746
-        
739
+
747
     }
740
     }
748
-    
741
+
749
     /**
742
     /**
750
      * 跟进记录列表
743
      * 跟进记录列表
751
      * @param $param
744
      * @param $param
798
                 $end_time = $param['end_time'] ? strtotime($param['end_time'] . ' 23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
791
                 $end_time = $param['end_time'] ? strtotime($param['end_time'] . ' 23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
799
                 $type['t.create_time'] = ['between', [$start_time, $end_time]];
792
                 $type['t.create_time'] = ['between', [$start_time, $end_time]];
800
             }
793
             }
801
-            
794
+
802
             if ($param['queryType'] == 0) {
795
             if ($param['queryType'] == 0) {
803
                 $type['t.type'] = ['in', [1, 4]];
796
                 $type['t.type'] = ['in', [1, 4]];
804
             } else {
797
             } else {
805
                 $type['t.type'] = $param['queryType'];
798
                 $type['t.type'] = $param['queryType'];
806
             }
799
             }
807
             if ($param['user_id'] == '') {
800
             if ($param['user_id'] == '') {
808
-               
801
+
809
                 if ($param['subUser'] === "0" || $param['subUser']===0) {
802
                 if ($param['subUser'] === "0" || $param['subUser']===0) {
810
                     $type['t.create_user_id'] = $param['id'];
803
                     $type['t.create_user_id'] = $param['id'];
811
                     //下属创建
804
                     //下属创建
853
                 if ($v['activity_type'] == 2) {
846
                 if ($v['activity_type'] == 2) {
854
                     $activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find();
847
                     $activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find();
855
                     $list[$k]['activity_type_name'] = $activity_name['name'];
848
                     $list[$k]['activity_type_name'] = $activity_name['name'];
856
-                    $activity_business = Db::name('crm_business')->where('business_id', $v['activity_type_id'])->select();
857
-                    $activity_contacts = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->select();
849
+                    $activity_business = Db::name('crm_business')->where('business_id',['in',$v['business_ids']])->find();
850
+                    $activity_contacts = Db::name('crm_contacts')->where('contacts_id', ['in',$v['contacts_ids']])->find();
858
                     $list[$k]['business_list'] = $activity_business ?: [];
851
                     $list[$k]['business_list'] = $activity_business ?: [];
859
                     $list[$k]['contacts_list'] = $activity_contacts ?: [];
852
                     $list[$k]['contacts_list'] = $activity_contacts ?: [];
860
-                  
861
                    }
853
                    }
862
-                
863
                 if ($v['activity_type'] == 3) {
854
                 if ($v['activity_type'] == 3) {
864
                     $activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find();
855
                     $activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find();
865
                     $list[$k]['activity_type_name'] = $activity_name['name'];
856
                     $list[$k]['activity_type_name'] = $activity_name['name'];
898
                 };
889
                 };
899
                 $list[$k]['fileList'] = $fileList ?: [];
890
                 $list[$k]['fileList'] = $fileList ?: [];
900
                 $list[$k]['imgList'] = $imgList ?: [];
891
                 $list[$k]['imgList'] = $imgList ?: [];
901
-               
892
+
902
                 $dataInfo['customerList'] = $relation_list['customerList'] ?: [];
893
                 $dataInfo['customerList'] = $relation_list['customerList'] ?: [];
903
                 $dataInfo['contactsList'] = $relation_list['contactsList'] ?: [];
894
                 $dataInfo['contactsList'] = $relation_list['contactsList'] ?: [];
904
                 $dataInfo['businessList'] = $relation_list['businessList'] ?: [];
895
                 $dataInfo['businessList'] = $relation_list['businessList'] ?: [];
913
                 ->alias('t')
904
                 ->alias('t')
914
                 ->join('__ADMIN_USER__ user', 'user.id = t.create_user_id', 'LEFT')
905
                 ->join('__ADMIN_USER__ user', 'user.id = t.create_user_id', 'LEFT')
915
                 ->where($where_activity)
906
                 ->where($where_activity)
916
-                ->field('t.content,t.next_time,t.update_time,t.create_time,t.category,t.activity_type,t.type,t.activity_id,t.activity_type_id,user.realname as create_user_name,user.thumb_img')
907
+                ->field('t.business_ids,t.contacts_ids,t.content,t.next_time,t.update_time,t.create_time,t.category,t.activity_type,t.type,t.activity_id,t.activity_type_id,user.realname as create_user_name,user.thumb_img')
917
                 ->page($param['page'], $param['limit'])
908
                 ->page($param['page'], $param['limit'])
918
                 ->order('t.create_time desc')
909
                 ->order('t.create_time desc')
919
                 ->select();
910
                 ->select();
928
                 if ($param['activity_type'] == 2) {
919
                 if ($param['activity_type'] == 2) {
929
                     $activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find();
920
                     $activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find();
930
                     $list[$k]['activity_type_name'] = $activity_name['name'];
921
                     $list[$k]['activity_type_name'] = $activity_name['name'];
931
-                    $activity_business = Db::name('crm_business')->where('business_id', $v['activity_type_id'])->select();
932
-                    $activity_contacts = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->select();
922
+                    $activity_business = Db::name('crm_business')->where('business_id',['in',$v['business_ids']])->find();
923
+                    $activity_contacts = Db::name('crm_contacts')->where('contacts_id', ['in',$v['contacts_ids']])->find();
933
                     $list[$k]['business_list'] = $activity_business ?: [];
924
                     $list[$k]['business_list'] = $activity_business ?: [];
934
                     $list[$k]['contacts_list'] = $activity_contacts ?: [];
925
                     $list[$k]['contacts_list'] = $activity_contacts ?: [];
935
                 }
926
                 }
936
-                
927
+
937
                 if ($param['activity_type'] == 3) {
928
                 if ($param['activity_type'] == 3) {
938
                     $activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find();
929
                     $activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find();
939
                     $list[$k]['activity_type_name'] = $activity_name['name'];
930
                     $list[$k]['activity_type_name'] = $activity_name['name'];
980
                 $list[$k]['dataInfo'] = $dataInfo ?: [];
971
                 $list[$k]['dataInfo'] = $dataInfo ?: [];
981
             }
972
             }
982
         }
973
         }
983
-        
984
-        
974
+
975
+
985
         $data = [];
976
         $data = [];
986
         $data['list'] = $list;
977
         $data['list'] = $list;
987
         $data['dataCount'] = $dataCount ?: 0;
978
         $data['dataCount'] = $dataCount ?: 0;

+ 128
- 52
application/crm/logic/InvoiceLogic.php Просмотреть файл

17
 {
17
 {
18
     private $invoiceType = ['增值税专用发票', '增值税普通发票', '国税通用机打发票', '地税通用机打发票', '收据'];
18
     private $invoiceType = ['增值税专用发票', '增值税普通发票', '国税通用机打发票', '地税通用机打发票', '收据'];
19
     private $check_status = ['待审核', '审核中', '审核通过', '审核未通过', '撤回'];
19
     private $check_status = ['待审核', '审核中', '审核通过', '审核未通过', '撤回'];
20
-    
20
+
21
     /**
21
     /**
22
      * 列表
22
      * 列表
23
      *
23
      *
45
         $scene_id = $param['scene_id'];
45
         $scene_id = $param['scene_id'];
46
         $isMessage = !empty($param['isMessage']);
46
         $isMessage = !empty($param['isMessage']);
47
         $common = new Common();
47
         $common = new Common();
48
-        
48
+
49
         unset($param['getCount']);
49
         unset($param['getCount']);
50
 //        unset($param['limit']); 导出使用 暂未发现为何去掉分页参数
50
 //        unset($param['limit']); 导出使用 暂未发现为何去掉分页参数
51
 //        unset($param['page']);
51
 //        unset($param['page']);
60
         unset($param['isMessage']);
60
         unset($param['isMessage']);
61
         $request = $common->fmtRequest($param);
61
         $request = $common->fmtRequest($param);
62
         $where = [];
62
         $where = [];
63
-       
63
+
64
         # 高级搜索
64
         # 高级搜索
65
         $requestMap = !empty($request['map']) ? $request['map'] : [];
65
         $requestMap = !empty($request['map']) ? $request['map'] : [];
66
         unset($requestMap['search']);
66
         unset($requestMap['search']);
67
-        
67
+
68
         # 场景
68
         # 场景
69
         $sceneMap = [];
69
         $sceneMap = [];
70
         $sceneModel = new \app\admin\model\Scene();
70
         $sceneModel = new \app\admin\model\Scene();
94
         # 替换掉字段前缀,不修改公共函数
94
         # 替换掉字段前缀,不修改公共函数
95
         foreach ($map as $key => $value) {
95
         foreach ($map as $key => $value) {
96
             $k = str_replace('invoice.', '', $key);
96
             $k = str_replace('invoice.', '', $key);
97
-            
97
+
98
             $where[$k] = $value;
98
             $where[$k] = $value;
99
         }
99
         }
100
         # 待办事项查询参数
100
         # 待办事项查询参数
101
         $dealtWhere = [];
101
         $dealtWhere = [];
102
         if (!empty($invoiceIdArray)) $dealtWhere['invoice.invoice_id'] = ['in', $invoiceIdArray];
102
         if (!empty($invoiceIdArray)) $dealtWhere['invoice.invoice_id'] = ['in', $invoiceIdArray];
103
-        
103
+
104
         # 权限,不是待办事项,则加上列表权限
104
         # 权限,不是待办事项,则加上列表权限
105
         $auth = [];
105
         $auth = [];
106
         $userModel = new \app\admin\model\User();
106
         $userModel = new \app\admin\model\User();
154
             ->limit($request['offset'], $request['length'])
154
             ->limit($request['offset'], $request['length'])
155
             ->orderRaw($order)
155
             ->orderRaw($order)
156
             ->select();
156
             ->select();
157
-        
157
+
158
         $dataCount = db('crm_invoice')
158
         $dataCount = db('crm_invoice')
159
             ->alias('invoice')
159
             ->alias('invoice')
160
             ->join($join)
160
             ->join($join)
176
         $positionField = $fieldModel->getFieldByFormType('crm_invoice', 'position'); // 地址类型字段
176
         $positionField = $fieldModel->getFieldByFormType('crm_invoice', 'position'); // 地址类型字段
177
         $handwritingField = $fieldModel->getFieldByFormType('crm_invoice', 'handwriting_sign'); // 手写签名类型字段
177
         $handwritingField = $fieldModel->getFieldByFormType('crm_invoice', 'handwriting_sign'); // 手写签名类型字段
178
         $locationField = $fieldModel->getFieldByFormType('crm_invoice', 'location'); // 定位类型字段
178
         $locationField = $fieldModel->getFieldByFormType('crm_invoice', 'location'); // 定位类型字段
179
-
179
+        $boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
180
+        $floatField = $fieldModel->getFieldByFormType('crm_invoice', 'floatnumber'); // 货币类型字段
181
+//        $fieldGrant = db('admin_field_mask')->where('types', 'invoice')->select();
180
         # 扩展数据
182
         # 扩展数据
181
         $extraData = [];
183
         $extraData = [];
182
         $invoice_id_list = !empty($list) ? array_column($list, 'invoice_id') : [];
184
         $invoice_id_list = !empty($list) ? array_column($list, 'invoice_id') : [];
183
         $extraList = db('crm_invoice_data')->whereIn('invoice_id', $invoice_id_list)->select();
185
         $extraList = db('crm_invoice_data')->whereIn('invoice_id', $invoice_id_list)->select();
184
-        foreach ($extraList AS $key => $value) {
186
+        foreach ($extraList as $key => $value) {
185
             $extraData[$value['invoice_id']][$value['field']] = $value['content'];
187
             $extraData[$value['invoice_id']][$value['field']] = $value['content'];
186
         }
188
         }
187
-
189
+        $grantData = getFieldGrantData($userId);
190
+        foreach ($grantData['crm_invoice'] as $key => $value) {
191
+            foreach ($value as $ke => $va) {
192
+                if($va['maskType']!=0){
193
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
194
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
195
+                    $fieldGrant[$ke]['field'] = $va['field'];
196
+                }
197
+            }
198
+        }
188
         # 处理发票类型
199
         # 处理发票类型
189
         foreach ($list as $key => $value) {
200
         foreach ($list as $key => $value) {
190
             $list[$key]['check_status_info'] = $this->check_status[$value['check_status']];
201
             $list[$key]['check_status_info'] = $this->check_status[$value['check_status']];
191
             $list[$key]['invoice_status'] = !empty($value['invoice_status']) ? '已开票' : '未开票';
202
             $list[$key]['invoice_status'] = !empty($value['invoice_status']) ? '已开票' : '未开票';
192
-            $list[$key]['create_time'] = !empty($value['create_time']) ? date('Y-m-d H:i:s',$value['create_time']) : null;
193
-            $list[$key]['update_time'] = !empty($value['update_time']) ? date('Y-m-d H:i:s',$value['update_time']) : null;
203
+            $list[$key]['create_time'] = !empty($value['create_time']) ? date('Y-m-d H:i:s', $value['create_time']) : null;
204
+            $list[$key]['update_time'] = !empty($value['update_time']) ? date('Y-m-d H:i:s', $value['update_time']) : null;
205
+            # 系统字段  负责人部门   zjf  20210726
206
+            $ownerUserIdInfo = $userModel->getUserById($value['owner_user_id']);
207
+            $list[$key]['owner_user_structure_name'] = $ownerUserIdInfo['structure_name'];
194
             foreach ($userField as $k => $val) {
208
             foreach ($userField as $k => $val) {
195
                 $usernameField = !empty($value[$val]) ? db('admin_user')->whereIn('id', stringToArray($value[$val]))->column('realname') : [];
209
                 $usernameField = !empty($value[$val]) ? db('admin_user')->whereIn('id', stringToArray($value[$val]))->column('realname') : [];
196
                 $list[$key][$val] = implode($usernameField, ',');
210
                 $list[$key][$val] = implode($usernameField, ',');
214
                 $list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null;
228
                 $list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null;
215
             }
229
             }
216
             // 手写签名类型字段
230
             // 手写签名类型字段
217
-            foreach ($handwritingField AS $k => $val) {
231
+            foreach ($handwritingField as $k => $val) {
218
                 $handwritingData = !empty($value[$val]) ? db('admin_file')->where('file_id', $value[$val])->value('file_path') : null;
232
                 $handwritingData = !empty($value[$val]) ? db('admin_file')->where('file_id', $value[$val])->value('file_path') : null;
219
                 $list[$key][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
233
                 $list[$key][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
220
             }
234
             }
222
             foreach ($locationField as $k => $val) {
236
             foreach ($locationField as $k => $val) {
223
                 $list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null;
237
                 $list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null;
224
             }
238
             }
239
+
240
+            // 多选框类型字段
241
+            foreach ($boxField as $k => $val) {
242
+                $list[$key][$val] = !empty($value[$val]) ? trim($value[$val], ',') : null;
243
+            }
244
+            //货币类型字段
245
+            foreach ($floatField as $k => $val) {
246
+                $list[$key][$val] = $value[$val] != '0.00' ? (string)$value[$val] : null;
247
+            }
248
+            //掩码相关类型字段
249
+            foreach ($fieldGrant AS $key => $v){
250
+                //掩码相关类型字段
251
+                if ($v['maskType']!=0 && $v['form_type'] == 'mobile') {
252
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
253
+                    $rs = preg_replace($pattern, "$1****$2", $value[$v['field']]);
254
+                    $list[$k][$v['field']] = !empty($value[$v['field']]) ? (string)$rs : null;
255
+                } elseif ($v['maskType']!=0 && $v['form_type'] == 'email') {
256
+                    $email_array = explode("@", $value[$v['field']]);
257
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($value[$v['field']], 0, 2); //邮箱前缀
258
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $value[$v['field']], -1, $count);
259
+                    $rs = $prevfix . $str;
260
+                    $list[$k][$v['field']] = !empty($value[$v['field']]) ?$rs: null;
261
+                } elseif ($v['maskType']!=0 && in_array($v['form_type'],['position','floatnumber'])) {
262
+                    $list[$k][$v['field']] = !empty($value[$v['field']]) ? (string)substr_replace($value[$v['field']], '*****',0,strlen($value[$v['field']])) : null;
263
+                }
264
+            }
265
+            $data = [];
266
+            $data['list'] = $list ?: [];
267
+            $data['dataCount'] = $dataCount ?: 0;
268
+            return $data;
225
         }
269
         }
226
-        $data = [];
227
-        $data['list'] = $list ?: [];
228
-        $data['dataCount'] = $dataCount ?: 0;
229
-        return $data;
230
     }
270
     }
231
-    
271
+
232
     /**
272
     /**
233
      * 创建
273
      * 创建
234
      *
274
      *
235
      * @param $param
275
      * @param $param
236
      * @return Invoice|int|string
276
      * @return Invoice|int|string
237
      */
277
      */
238
-    public function save($param)
278
+    public
279
+    function save($param) 
239
     {
280
     {
240
         return db('crm_invoice')->insert($param, false, true);
281
         return db('crm_invoice')->insert($param, false, true);
241
     }
282
     }
242
-    
283
+
243
     /**
284
     /**
244
      * 详情
285
      * 详情
245
      *
286
      *
250
      * @throws \think\db\exception\ModelNotFoundException
291
      * @throws \think\db\exception\ModelNotFoundException
251
      * @throws \think\exception\DbException
292
      * @throws \think\exception\DbException
252
      */
293
      */
253
-    public function read($invoiceId, $isUpdate)
294
+    public
295
+    function read($invoiceId, $isUpdate)
254
     {
296
     {
255
         $apiCommon = new ApiCommon();
297
         $apiCommon = new ApiCommon();
256
-        
298
+
257
         $userId = $apiCommon->userInfo['id'];
299
         $userId = $apiCommon->userInfo['id'];
258
         $result = [];
300
         $result = [];
259
         $dataObject = Invoice::with(['toCustomer', 'toContract'])->where('invoice_id', $invoiceId)->find();
301
         $dataObject = Invoice::with(['toCustomer', 'toContract'])->where('invoice_id', $invoiceId)->find();
260
-        
302
+
261
         if (empty($dataObject)) return $result;
303
         if (empty($dataObject)) return $result;
262
-        
304
+
263
         $dataArray = $dataObject->toArray();
305
         $dataArray = $dataObject->toArray();
264
-        
306
+
265
         if (!empty($isUpdate)) return $dataArray;
307
         if (!empty($isUpdate)) return $dataArray;
266
-        
308
+        $grantData = getFieldGrantData($userId);
309
+        foreach ($grantData['crm_leads'] as $key => $value) {
310
+            foreach ($value as $ke => $va) {
311
+                if($va['maskType']!=0){
312
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
313
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
314
+                    $fieldGrant[$ke]['field'] = $va['field'];
315
+                }
316
+            }
317
+        }
318
+        foreach ($fieldGrant AS $key => $val){
319
+            //掩码相关类型字段
320
+            if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
321
+                $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
322
+                $rs = preg_replace($pattern, "$1****$2", $dataArray[$val['field']]);
323
+                $dataArray[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
324
+            } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
325
+                $email_array = explode("@", $dataArray[$val['field']]);
326
+                $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataArray[$val['field']], 0, 2); //邮箱前缀
327
+                $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataArray[$val['field']], -1, $count);
328
+                $rs = $prevfix . $str;
329
+                $dataArray[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
330
+            } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
331
+                $dataArray[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataArray[$val['field']], '*****',0,strlen($dataArray[$val['field']])) : null;
332
+            }
333
+        }
267
         # 主键ID
334
         # 主键ID
268
         $result['invoice_id'] = $dataArray['invoice_id'];
335
         $result['invoice_id'] = $dataArray['invoice_id'];
269
-        
336
+
270
         # 是否显示撤回按钮
337
         # 是否显示撤回按钮
271
         $result['isShowRecall'] = 0;
338
         $result['isShowRecall'] = 0;
272
         if ($userId == $dataArray['owner_user_id'] && $dataArray['check_status'] == 0) $result['isShowRecall'] = 1;
339
         if ($userId == $dataArray['owner_user_id'] && $dataArray['check_status'] == 0) $result['isShowRecall'] = 1;
273
-        
340
+
274
         $result['customer_name'] = $dataArray['customer_name'];     # 客户名称
341
         $result['customer_name'] = $dataArray['customer_name'];     # 客户名称
275
         $result['invoice_money'] = $dataArray['invoice_money'];     # 开票金额
342
         $result['invoice_money'] = $dataArray['invoice_money'];     # 开票金额
276
         $result['invoice_number'] = $dataArray['invoice_number'];    # 发票号码
343
         $result['invoice_number'] = $dataArray['invoice_number'];    # 发票号码
296
             'customer_id' => $dataArray['customer_id'],
363
             'customer_id' => $dataArray['customer_id'],
297
             'check_status' => $check[$dataArray['check_status']]
364
             'check_status' => $check[$dataArray['check_status']]
298
         ];
365
         ];
299
-        
366
+
300
         # 发票信息
367
         # 发票信息
301
         $result['invoice'] = [
368
         $result['invoice'] = [
302
             'title_type' => $dataArray['title_type'],
369
             'title_type' => $dataArray['title_type'],
307
             'deposit_address' => $dataArray['deposit_address'],
374
             'deposit_address' => $dataArray['deposit_address'],
308
             'phone' => $dataArray['phone']
375
             'phone' => $dataArray['phone']
309
         ];
376
         ];
310
-        
377
+
311
         # 邮寄信息
378
         # 邮寄信息
312
         $result['posting'] = [
379
         $result['posting'] = [
313
             'contacts_name' => $dataArray['contacts_name'],
380
             'contacts_name' => $dataArray['contacts_name'],
314
             'contacts_mobile' => $dataArray['contacts_mobile'],
381
             'contacts_mobile' => $dataArray['contacts_mobile'],
315
             'contacts_address' => $dataArray['contacts_address']
382
             'contacts_address' => $dataArray['contacts_address']
316
         ];
383
         ];
317
-        
384
+
318
         return $result;
385
         return $result;
319
     }
386
     }
320
-    
387
+
321
     /**
388
     /**
322
      * 编辑
389
      * 编辑
323
      *
390
      *
324
      * @param $param
391
      * @param $param
325
      * @return Invoice
392
      * @return Invoice
326
      */
393
      */
327
-    public function update($param)
394
+    public
395
+    function update($param)
328
     {
396
     {
329
         return Invoice::update($param);
397
         return Invoice::update($param);
330
     }
398
     }
331
-    
399
+
332
     /**
400
     /**
333
      * 删除
401
      * 删除
334
      *
402
      *
335
      * @param $where
403
      * @param $where
336
      * @return int
404
      * @return int
337
      */
405
      */
338
-    public function delete($where)
406
+    public
407
+    function delete($where)
339
     {
408
     {
340
         return Invoice::destroy($where);
409
         return Invoice::destroy($where);
341
     }
410
     }
342
-    
411
+
343
     /**
412
     /**
344
      * 获取审批状态
413
      * 获取审批状态
345
      *
414
      *
350
      * @throws \think\db\exception\ModelNotFoundException
419
      * @throws \think\db\exception\ModelNotFoundException
351
      * @throws \think\exception\DbException
420
      * @throws \think\exception\DbException
352
      */
421
      */
353
-    public function getExamineStatus($invoiceId, $isDelete = false)
422
+    public
423
+    function getExamineStatus($invoiceId, $isDelete = false)
354
     {
424
     {
355
         # 删除
425
         # 删除
356
         if ($isDelete) {
426
         if ($isDelete) {
357
             return Invoice::field(['check_status'])->whereIn('invoice_id', $invoiceId)->select();
427
             return Invoice::field(['check_status'])->whereIn('invoice_id', $invoiceId)->select();
358
         }
428
         }
359
-        
429
+
360
         # 编辑
430
         # 编辑
361
         return Invoice::where('invoice_id', $invoiceId)->value('check_status');
431
         return Invoice::where('invoice_id', $invoiceId)->value('check_status');
362
     }
432
     }
363
-    
433
+
364
     /**
434
     /**
365
      * 转移(变更负责人)
435
      * 转移(变更负责人)
366
      *
436
      *
368
      * @param $ownerUserId
438
      * @param $ownerUserId
369
      * @return Invoice
439
      * @return Invoice
370
      */
440
      */
371
-    public function transfer($invoiceIds, $ownerUserId)
441
+    public
442
+    function transfer($invoiceIds, $ownerUserId)
372
     {
443
     {
373
         return Invoice::whereIn('invoice_id', $invoiceIds)->update(['owner_user_id' => $ownerUserId]);
444
         return Invoice::whereIn('invoice_id', $invoiceIds)->update(['owner_user_id' => $ownerUserId]);
374
     }
445
     }
375
-    
446
+
376
     /**
447
     /**
377
      * 设置开票
448
      * 设置开票
378
      *
449
      *
379
      * @param $param
450
      * @param $param
380
      * @return Invoice
451
      * @return Invoice
381
      */
452
      */
382
-    public function setInvoice($param)
453
+    public
454
+    function setInvoice($param)
383
     {
455
     {
384
         return Invoice::update($param);
456
         return Invoice::update($param);
385
     }
457
     }
386
-    
458
+
387
     /**
459
     /**
388
      * 获取发票审核信息
460
      * 获取发票审核信息
389
      *
461
      *
393
      * @throws \think\db\exception\ModelNotFoundException
465
      * @throws \think\db\exception\ModelNotFoundException
394
      * @throws \think\exception\DbException
466
      * @throws \think\exception\DbException
395
      */
467
      */
396
-    public function getExamineInfo($invoiceId)
468
+    public
469
+    function getExamineInfo($invoiceId)
397
     {
470
     {
398
         $field = ['check_status', 'flow_id', 'order_id', 'check_user_id', 'flow_user_id', 'invoice_apple_number', 'owner_user_id', 'create_user_id'];
471
         $field = ['check_status', 'flow_id', 'order_id', 'check_user_id', 'flow_user_id', 'invoice_apple_number', 'owner_user_id', 'create_user_id'];
399
-        
472
+
400
         return Invoice::field($field)->where('invoice_id', $invoiceId)->find();
473
         return Invoice::field($field)->where('invoice_id', $invoiceId)->find();
401
     }
474
     }
402
-    
475
+
403
     /**
476
     /**
404
      * 设置审批信息
477
      * 设置审批信息
405
      *
478
      *
406
      * @param $data
479
      * @param $data
407
      * @return Invoice
480
      * @return Invoice
408
      */
481
      */
409
-    public function setExamineInfo($data)
482
+    public
483
+    function setExamineInfo($data)
410
     {
484
     {
411
         return Invoice::update($data);
485
         return Invoice::update($data);
412
     }
486
     }
413
-    
487
+
414
     /**
488
     /**
415
      * 添加撤销审核记录
489
      * 添加撤销审核记录
416
      *
490
      *
420
      * @param $content
494
      * @param $content
421
      * @param $userId
495
      * @param $userId
422
      */
496
      */
423
-    public function createExamineRecord($invoiceId, $examineInfo, $realname, $content, $userId)
497
+    public
498
+    function createExamineRecord($invoiceId, $examineInfo, $realname, $content, $userId)
424
     {
499
     {
425
         $data = [
500
         $data = [
426
             'types' => 'crm_invoice',
501
             'types' => 'crm_invoice',
432
             'status' => 2,
507
             'status' => 2,
433
             'content' => !empty($content) ? $content : $realname . ' 撤销了审核',
508
             'content' => !empty($content) ? $content : $realname . ' 撤销了审核',
434
         ];
509
         ];
435
-        
510
+
436
         Db::name('admin_examine_record')->insert($data);
511
         Db::name('admin_examine_record')->insert($data);
437
     }
512
     }
438
-    
513
+
439
     /**
514
     /**
440
      * 检查发票编号是否重复
515
      * 检查发票编号是否重复
441
      *
516
      *
442
      * @param $where
517
      * @param $where
443
      * @return int|mixed|string|null
518
      * @return int|mixed|string|null
444
      */
519
      */
445
-    public function getInvoiceId($where)
520
+    public
521
+    function getInvoiceId($where)
446
     {
522
     {
447
         return Db::name('crm_invoice')->where($where)->value('invoice_id');
523
         return Db::name('crm_invoice')->where($where)->value('invoice_id');
448
     }
524
     }

+ 82
- 2
application/crm/logic/VisitLogic.php Просмотреть файл

100
         $positionField = $fieldModel->getFieldByFormType('crm_visit', 'position'); // 地址类型字段
100
         $positionField = $fieldModel->getFieldByFormType('crm_visit', 'position'); // 地址类型字段
101
         $handwritingField = $fieldModel->getFieldByFormType('crm_visit', 'handwriting_sign'); // 手写签名类型字段
101
         $handwritingField = $fieldModel->getFieldByFormType('crm_visit', 'handwriting_sign'); // 手写签名类型字段
102
         $locationField = $fieldModel->getFieldByFormType('crm_visit', 'location'); // 定位类型字段
102
         $locationField = $fieldModel->getFieldByFormType('crm_visit', 'location'); // 定位类型字段
103
+        $boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
104
+        $floatField = $fieldModel->getFieldByFormType('crm_visit', 'floatnumber'); // 货币类型字段
105
+        //        $fieldGrant = db('admin_field_mask')->where('types', 'visit')->select();
103
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
106
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
104
         $temporaryField = str_replace('_name', '', $order_field);
107
         $temporaryField = str_replace('_name', '', $order_field);
105
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
108
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
147
         foreach ($extraList AS $key => $value) {
150
         foreach ($extraList AS $key => $value) {
148
             $extraData[$value['visit_id']][$value['field']] = $value['content'];
151
             $extraData[$value['visit_id']][$value['field']] = $value['content'];
149
         }
152
         }
153
+        $grantData = getFieldGrantData($user_id);
154
+        foreach ($grantData['crm_visit_'] as $key => $value) {
155
+            foreach ($value as $ke => $va) {
156
+                if($va['maskType']!=0){
157
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
158
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
159
+                    $fieldGrant[$ke]['field'] = $va['field'];
160
+                }
161
+            }
162
+        }
150
         foreach ($list as $k => $v) {
163
         foreach ($list as $k => $v) {
151
             $list[$k]['contract_num'] = $v['contract_number'];
164
             $list[$k]['contract_num'] = $v['contract_number'];
152
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
165
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
153
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
166
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
154
             $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
167
             $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
155
             $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
168
             $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
169
+
170
+            # 系统字段  负责人部门   zjf  20210726
171
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
172
+
156
             foreach ($userField as $key => $val) {
173
             foreach ($userField as $key => $val) {
157
                 $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
174
                 $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
158
                 $list[$k][$val.'_name'] = implode($usernameField, ',');
175
                 $list[$k][$val.'_name'] = implode($usernameField, ',');
184
             foreach ($locationField AS $key => $val) {
201
             foreach ($locationField AS $key => $val) {
185
                 $list[$k][$val] = !empty($extraData[$v['visit_id']][$val]) ? json_decode($extraData[$v['visit_id']][$val], true) : null;
202
                 $list[$k][$val] = !empty($extraData[$v['visit_id']][$val]) ? json_decode($extraData[$v['visit_id']][$val], true) : null;
186
             }
203
             }
204
+            // 多选框类型字段
205
+            foreach ($boxField AS $key => $val) {
206
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
207
+            }
208
+            // 货币类型字段
209
+            foreach ($floatField AS $key => $val) {
210
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
211
+            }
212
+            //掩码相关类型字段
213
+            foreach ($fieldGrant AS $key => $val){
214
+                //掩码相关类型字段
215
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
216
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
217
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
218
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
219
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
220
+                    $email_array = explode("@", $v[$val['field']]);
221
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
222
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
223
+                    $rs = $prevfix . $str;
224
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
225
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
226
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
227
+                }
228
+            }
187
             $list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
229
             $list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
188
             $list[$k]['contract_id_info']['name'] = $v['contract_name'];
230
             $list[$k]['contract_id_info']['name'] = $v['contract_name'];
189
             $list[$k]['customer_id_info']['customer_id'] = $v['create_user_id'];
231
             $list[$k]['customer_id_info']['customer_id'] = $v['create_user_id'];
226
             $this->error = '暂无此数据';
268
             $this->error = '暂无此数据';
227
             return false;
269
             return false;
228
         }
270
         }
271
+        $grantData = getFieldGrantData($userId);
272
+        foreach ($grantData['crm_leads'] as $key => $value) {
273
+            foreach ($value as $ke => $va) {
274
+                if($va['maskType']!=0){
275
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
276
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
277
+                    $fieldGrant[$ke]['field'] = $va['field'];
278
+                }
279
+            }
280
+        }
281
+        foreach ($fieldGrant AS $key => $val){
282
+            //掩码相关类型字段
283
+            if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
284
+                $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
285
+                $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
286
+                $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
287
+            } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
288
+                $email_array = explode("@", $dataInfo[$val['field']]);
289
+                $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
290
+                $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
291
+                $rs = $prevfix . $str;
292
+                $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
293
+            } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
294
+                $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
295
+            }
296
+        }
229
         $userModel = new \app\admin\model\User();
297
         $userModel = new \app\admin\model\User();
230
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
298
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
231
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
299
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
584
     public function getSystemInfo($id)
652
     public function getSystemInfo($id)
585
     {
653
     {
586
         # 回访
654
         # 回访
587
-        $visit = Db::name('crm_visit')->field(['create_user_id', 'create_time', 'update_time'])->where('visit_id', $id)->find();
655
+        $visit = Db::name('crm_visit')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('visit_id', $id)->find();
588
         # 创建人
656
         # 创建人
589
         $realname = Db::name('admin_user')->where('id', $visit['create_user_id'])->value('realname');
657
         $realname = Db::name('admin_user')->where('id', $visit['create_user_id'])->value('realname');
658
+        
659
+        # zjf   20210726
660
+        $userModel   = new \app\admin\model\User();
661
+        $ownerUserInfo = $userModel->getUserById($visit['owner_user_id']);
662
+        # 负责人部门
663
+        $ownerStructureName = $ownerUserInfo['structure_name'];
664
+
665
+        # 负责人
666
+        $ownerUserName = $ownerUserInfo['realname'];
667
+        
590
         return [
668
         return [
591
             'create_user_id' => $realname,
669
             'create_user_id' => $realname,
670
+            'owner_user_id' => $ownerUserName,
592
             'create_time' => date('Y-m-d H:i:s', $visit['create_time']),
671
             'create_time' => date('Y-m-d H:i:s', $visit['create_time']),
593
-            'update_time' => date('Y-m-d H:i:s', $visit['update_time'])
672
+            'update_time' => date('Y-m-d H:i:s', $visit['update_time']),
673
+            'owner_user_structure_name' => $ownerStructureName
594
         ];
674
         ];
595
     }
675
     }
596
 }
676
 }

+ 82
- 4
application/crm/model/Business.php Просмотреть файл

161
         $positionField = $fieldModel->getFieldByFormType('crm_business', 'position'); // 地址类型字段
161
         $positionField = $fieldModel->getFieldByFormType('crm_business', 'position'); // 地址类型字段
162
         $handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); // 手写签名类型字段
162
         $handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); // 手写签名类型字段
163
         $locationField = $fieldModel->getFieldByFormType('crm_business', 'location'); // 定位类型字段
163
         $locationField = $fieldModel->getFieldByFormType('crm_business', 'location'); // 定位类型字段
164
+        $boxField = $fieldModel->getFieldByFormType('crm_business', 'checkbox'); // 多选类型字段
165
+        $floatField = $fieldModel->getFieldByFormType('crm_business', 'floatnumber'); // 货币类型字段
166
+//        $fieldGrant = db('admin_field_mask')->where('types', 'business')->select();
164
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
167
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
165
         $temporaryField = str_replace('_name', '', $order_field);
168
         $temporaryField = str_replace('_name', '', $order_field);
166
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
169
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
224
         foreach ($extraList AS $key => $value) {
227
         foreach ($extraList AS $key => $value) {
225
             $extraData[$value['business_id']][$value['field']] = $value['content'];
228
             $extraData[$value['business_id']][$value['field']] = $value['content'];
226
         }
229
         }
230
+        $grantData = getFieldGrantData($user_id);
231
+        foreach ($grantData['crm_business'] as $key => $value) {
232
+            foreach ($value as $ke => $va) {
233
+                if($va['maskType']!=0){
234
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
235
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
236
+                    $fieldGrant[$ke]['field'] = $va['field'];
237
+                }
238
+            }
239
+        }
227
         foreach ($list as $k => $v) {
240
         foreach ($list as $k => $v) {
228
             $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
241
             $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
229
             $list[$k]['customer_id_info']['name'] = $v['customer_name'];
242
             $list[$k]['customer_id_info']['name'] = $v['customer_name'];
262
             foreach ($locationField AS $key => $val) {
275
             foreach ($locationField AS $key => $val) {
263
                 $list[$k][$val] = !empty($extraData[$v['business_id']][$val]) ? json_decode($extraData[$v['business_id']][$val], true) : null;
276
                 $list[$k][$val] = !empty($extraData[$v['business_id']][$val]) ? json_decode($extraData[$v['business_id']][$val], true) : null;
264
             }
277
             }
278
+            // 多选框类型字段
279
+            foreach ($boxField AS $key => $val) {
280
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
281
+            }
282
+            // 货币类型字段
283
+            foreach ($floatField AS $key => $val) {
284
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
285
+            }
286
+            //掩码相关类型字段
287
+            foreach ($fieldGrant AS $key => $val){
288
+                //掩码相关类型字段
289
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
290
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
291
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
292
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
293
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
294
+                    $email_array = explode("@", $v[$val['field']]);
295
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
296
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
297
+                    $rs = $prevfix . $str;
298
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
299
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
300
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
301
+                }
302
+            }
265
             $statusInfo = [];
303
             $statusInfo = [];
266
             $status_count = 0;
304
             $status_count = 0;
267
             if (!$v['is_end']) {
305
             if (!$v['is_end']) {
301
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
339
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
302
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
340
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
303
             $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
341
             $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
342
+
343
+            # 系统字段  负责人部门   zjf  20210726
344
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
304
         }
345
         }
305
         $data = [];
346
         $data = [];
306
         $data['list'] = $list ?: [];
347
         $data['list'] = $list ?: [];
633
      * @throws \think\db\exception\ModelNotFoundException
674
      * @throws \think\db\exception\ModelNotFoundException
634
      * @throws \think\exception\DbException
675
      * @throws \think\exception\DbException
635
      */
676
      */
636
-    public function getDataById($id = '', $userId = 0)
677
+    public function getDataById($id = '', $userId = 0,$model='')
637
     {
678
     {
638
         $dataInfo = db('crm_business')->where('business_id', $id)->find();
679
         $dataInfo = db('crm_business')->where('business_id', $id)->find();
639
         if (!$dataInfo) {
680
         if (!$dataInfo) {
640
             $this->error = '暂无此数据';
681
             $this->error = '暂无此数据';
641
             return false;
682
             return false;
642
         }
683
         }
684
+        if(empty($model) && $model!='update'){
685
+            $grantData = getFieldGrantData($userId);
686
+            foreach ($grantData['crm_business'] as $key => $value) {
687
+                foreach ($value as $ke => $va) {
688
+                    if($va['maskType']!=0){
689
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
690
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
691
+                        $fieldGrant[$ke]['field'] = $va['field'];
692
+                    }
693
+                }
694
+            }
695
+            foreach ($fieldGrant AS $key => $val){
696
+                //掩码相关类型字段
697
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
698
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
699
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
700
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
701
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
702
+                    $email_array = explode("@", $dataInfo[$val['field']]);
703
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
704
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
705
+                    $rs = $prevfix . $str;
706
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
707
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
708
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
709
+                }
710
+            }
711
+        }
643
         $userModel = new \app\admin\model\User();
712
         $userModel = new \app\admin\model\User();
644
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
713
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
645
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
714
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
902
     public function getSystemInfo($id)
971
     public function getSystemInfo($id)
903
     {
972
     {
904
         # 商机
973
         # 商机
905
-        $business = Db::name('crm_business')->field(['create_user_id', 'create_time', 'update_time', 'last_time'])->where('business_id', $id)->find();
974
+        $business = Db::name('crm_business')->field(['create_user_id' ,'owner_user_id', 'create_time', 'update_time', 'last_time'])->where('business_id', $id)->find();
906
         # 创建人
975
         # 创建人
907
         $realname = Db::name('admin_user')->where('id', $business['create_user_id'])->value('realname');
976
         $realname = Db::name('admin_user')->where('id', $business['create_user_id'])->value('realname');
908
-
977
+        
978
+        # zjf   20210726
979
+        $userModel   = new \app\admin\model\User();
980
+        $ownerUserInfo = $userModel->getUserById($business['owner_user_id']);
981
+        # 负责人部门
982
+        $ownerStructureName = $ownerUserInfo['structure_name'];
983
+        # 负责人
984
+        $ownerUserName = $ownerUserInfo['realname'];
909
         return [
985
         return [
910
             'create_user_id' => $realname,
986
             'create_user_id' => $realname,
987
+            'owner_user_id' => $ownerUserName,
911
             'create_time' => date('Y-m-d H:i:s', $business['create_time']),
988
             'create_time' => date('Y-m-d H:i:s', $business['create_time']),
912
             'update_time' => date('Y-m-d H:i:s', $business['update_time']),
989
             'update_time' => date('Y-m-d H:i:s', $business['update_time']),
913
-            'last_time' => !empty($business['last_time']) ? date('Y-m-d H:i:s', $business['last_time']) : ''
990
+            'last_time' => !empty($business['last_time']) ? date('Y-m-d H:i:s', $business['last_time']) : '',
991
+            'owner_user_structure_name' => $ownerStructureName
914
         ];
992
         ];
915
     }
993
     }
916
 
994
 

+ 84
- 4
application/crm/model/Contacts.php Просмотреть файл

136
         $positionField = $fieldModel->getFieldByFormType('crm_contacts', 'position'); // 地址类型字段
136
         $positionField = $fieldModel->getFieldByFormType('crm_contacts', 'position'); // 地址类型字段
137
         $handwritingField = $fieldModel->getFieldByFormType('crm_contacts', 'handwriting_sign'); // 手写签名类型字段
137
         $handwritingField = $fieldModel->getFieldByFormType('crm_contacts', 'handwriting_sign'); // 手写签名类型字段
138
         $locationField = $fieldModel->getFieldByFormType('crm_contacts', 'location'); // 定位类型字段
138
         $locationField = $fieldModel->getFieldByFormType('crm_contacts', 'location'); // 定位类型字段
139
+        $boxField = $fieldModel->getFieldByFormType('crm_contacts', 'checkbox'); // 多选类型字段
140
+        $floatField = $fieldModel->getFieldByFormType('crm_contacts', 'floatnumber'); // 货币类型字段
141
+//        $fieldGrant = db('admin_field_mask')->where('types', 'contacts')->select();
139
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
142
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
140
         $temporaryField = str_replace('_name', '', $order_field);
143
         $temporaryField = str_replace('_name', '', $order_field);
141
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
144
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
187
         foreach ($extraList as $key => $value) {
190
         foreach ($extraList as $key => $value) {
188
             $extraData[$value['contacts_id']][$value['field']] = $value['content'];
191
             $extraData[$value['contacts_id']][$value['field']] = $value['content'];
189
         }
192
         }
193
+        $grantData = getFieldGrantData($user_id);
194
+        foreach ($grantData['crm_contacts'] as $key => $value) {
195
+            foreach ($value as $ke => $va) {
196
+                if($va['maskType']!=0){
197
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
198
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
199
+                    $fieldGrant[$ke]['field'] = $va['field'];
200
+                }
201
+            }
202
+        }
190
         foreach ($list as $k => $v) {
203
         foreach ($list as $k => $v) {
191
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
204
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
192
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
205
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
223
             foreach ($locationField AS $key => $val) {
236
             foreach ($locationField AS $key => $val) {
224
                 $list[$k][$val] = !empty($extraData[$v['contacts_id']][$val]) ? json_decode($extraData[$v['contacts_id']][$val], true) : null;
237
                 $list[$k][$val] = !empty($extraData[$v['contacts_id']][$val]) ? json_decode($extraData[$v['contacts_id']][$val], true) : null;
225
             }
238
             }
239
+            // 多选框类型字段
240
+            foreach ($boxField AS $key => $val) {
241
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
242
+            }
243
+            // 货币类型字段
244
+            foreach ($floatField AS $key => $val) {
245
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
246
+            }
247
+            //掩码相关类型字段
248
+            foreach ($fieldGrant AS $key => $val){
249
+                //掩码相关类型字段
250
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
251
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
252
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
253
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
254
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
255
+                    $email_array = explode("@", $v[$val['field']]);
256
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
257
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
258
+                    $rs = $prevfix . $str;
259
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
260
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
261
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
262
+                }
263
+            }
226
             //权限
264
             //权限
227
             $permission = [];
265
             $permission = [];
228
             $is_read = 0;
266
             $is_read = 0;
248
             $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
286
             $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
249
             # 负责人
287
             # 负责人
250
             $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
288
             $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
289
+
290
+            # 系统字段  负责人部门   zjf  20210726
291
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
251
         }
292
         }
252
         $data = [];
293
         $data = [];
253
         $data['list'] = $list;
294
         $data['list'] = $list;
586
      * @throws \think\db\exception\ModelNotFoundException
627
      * @throws \think\db\exception\ModelNotFoundException
587
      * @throws \think\exception\DbException
628
      * @throws \think\exception\DbException
588
      */
629
      */
589
-    public function getDataById($id = '', $userId = 0)
630
+    public function getDataById($id = '', $userId = 0,$model='')
590
     {
631
     {
591
         $map['contacts_id'] = $id;
632
         $map['contacts_id'] = $id;
592
         $dataInfo = db('crm_contacts')->where($map)->find();
633
         $dataInfo = db('crm_contacts')->where($map)->find();
594
             $this->error = '暂无此数据';
635
             $this->error = '暂无此数据';
595
             return false;
636
             return false;
596
         }
637
         }
638
+        if(empty($model) && $model!='update'){
639
+            $grantData = getFieldGrantData($userId);
640
+            foreach ($grantData['crm_contacts'] as $key => $value) {
641
+                foreach ($value as $ke => $va) {
642
+                    if($va['maskType']!=0){
643
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
644
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
645
+                        $fieldGrant[$ke]['field'] = $va['field'];
646
+                    }
647
+                }
648
+            }
649
+            foreach ($fieldGrant AS $key => $val){
650
+                //掩码相关类型字段
651
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
652
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
653
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
654
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
655
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
656
+                    $email_array = explode("@", $dataInfo[$val['field']]);
657
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
658
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
659
+                    $rs = $prevfix . $str;
660
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
661
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
662
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
663
+                }
664
+            }
665
+        }
666
+
597
         $userModel = new \app\admin\model\User();
667
         $userModel = new \app\admin\model\User();
598
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
668
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
599
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
669
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
694
     public function getSystemInfo($id)
764
     public function getSystemInfo($id)
695
     {
765
     {
696
         # 联系人
766
         # 联系人
697
-        $contacts = Db::name('crm_contacts')->field(['create_user_id', 'create_time', 'update_time', 'last_time'])->where('contacts_id', $id)->find();
767
+        $contacts = Db::name('crm_contacts')->field(['create_user_id','owner_user_id' , 'create_time', 'update_time', 'last_time'])->where('contacts_id', $id)->find();
698
         # 创建人
768
         # 创建人
699
         $realname = Db::name('admin_user')->where('id', $contacts['create_user_id'])->value('realname');
769
         $realname = Db::name('admin_user')->where('id', $contacts['create_user_id'])->value('realname');
700
-        
770
+
771
+        # zjf   20210726
772
+        $userModel   = new \app\admin\model\User();
773
+        $ownerUserInfo = $userModel->getUserById($contacts['owner_user_id']);
774
+        # 负责人部门
775
+        $ownerStructureName = $ownerUserInfo['structure_name'];
776
+
777
+        # 负责人
778
+        $ownerUserName = $ownerUserInfo['realname'];
701
         return [
779
         return [
702
             'create_user_id' => $realname,
780
             'create_user_id' => $realname,
781
+            'owner_user_id' => $ownerUserName,
703
             'create_time' => date('Y-m-d H:i:s', $contacts['create_time']),
782
             'create_time' => date('Y-m-d H:i:s', $contacts['create_time']),
704
             'update_time' => date('Y-m-d H:i:s', $contacts['update_time']),
783
             'update_time' => date('Y-m-d H:i:s', $contacts['update_time']),
705
-            'last_time' => !empty($contacts['last_time']) ? date('Y-m-d H:i:s', $contacts['last_time']) : ''
784
+            'last_time' => !empty($contacts['last_time']) ? date('Y-m-d H:i:s', $contacts['last_time']) : '',
785
+            'owner_user_structure_name' => $ownerStructureName
706
         ];
786
         ];
707
     }
787
     }
708
 }
788
 }

+ 101
- 9
application/crm/model/Contract.php Просмотреть файл

23
     protected $createTime = 'create_time';
23
     protected $createTime = 'create_time';
24
     protected $updateTime = 'update_time';
24
     protected $updateTime = 'update_time';
25
 	protected $autoWriteTimestamp = true;
25
 	protected $autoWriteTimestamp = true;
26
-	private $statusArr = ['0'=>'待审核','1'=>'审核中','2'=>'审核通过','3'=>'已拒绝','4'=>'已撤回','5'=>'未提交','6'=>'已作废'];
26
+	private $statusArr = ['0'=>'待审核','1'=>'审核中','2'=>'审核通过','3'=>'已拒绝','4'=>'已撤回','5'=>'未提交','6'=>'已作废', '7'=>'正常'];
27
 
27
 
28
     /**
28
     /**
29
      * [getDataList 合同list]
29
      * [getDataList 合同list]
36
      */
36
      */
37
 	public function getDataList($request)
37
 	public function getDataList($request)
38
     {
38
     {
39
+        // if($param['check_status'] == 2){
40
+        //     die('11');
41
+        // }
39
     	$userModel = new \app\admin\model\User();
42
     	$userModel = new \app\admin\model\User();
40
     	$structureModel = new \app\admin\model\Structure();
43
     	$structureModel = new \app\admin\model\Structure();
41
     	$fieldModel = new \app\admin\model\Field();
44
     	$fieldModel = new \app\admin\model\Field();
62
         unset($request['isMessage']);
65
         unset($request['isMessage']);
63
 
66
 
64
         $request = $this->fmtRequest( $request );
67
         $request = $this->fmtRequest( $request );
65
-
66
         $requestMap = $request['map'] ? : [];
68
         $requestMap = $request['map'] ? : [];
69
+
67
 		$sceneModel = new \app\admin\model\Scene();
70
 		$sceneModel = new \app\admin\model\Scene();
68
         # getCount是代办事项传来的参数,代办事项不需要使用场景
71
         # getCount是代办事项传来的参数,代办事项不需要使用场景
69
         $sceneMap = [];
72
         $sceneMap = [];
148
         $positionField = $fieldModel->getFieldByFormType('crm_contract', 'position'); // 地址类型字段
151
         $positionField = $fieldModel->getFieldByFormType('crm_contract', 'position'); // 地址类型字段
149
         $handwritingField = $fieldModel->getFieldByFormType('crm_contract', 'handwriting_sign'); // 手写签名类型字段
152
         $handwritingField = $fieldModel->getFieldByFormType('crm_contract', 'handwriting_sign'); // 手写签名类型字段
150
         $locationField = $fieldModel->getFieldByFormType('crm_contract', 'location'); // 定位类型字段
153
         $locationField = $fieldModel->getFieldByFormType('crm_contract', 'location'); // 定位类型字段
154
+        $boxField = $fieldModel->getFieldByFormType('crm_contract', 'checkbox'); // 多选类型字段
155
+        $floatField = $fieldModel->getFieldByFormType('crm_contract', 'floatnumber'); // 货币类型字段
156
+
151
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
157
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
152
         $temporaryField = str_replace('_name', '', $order_field);
158
         $temporaryField = str_replace('_name', '', $order_field);
153
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
159
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
188
             if ($vv == 'contract.customer_name') unset($indexField[(int)$kk]);
194
             if ($vv == 'contract.customer_name') unset($indexField[(int)$kk]);
189
             if ($vv == 'contract.business_name') unset($indexField[(int)$kk]);
195
             if ($vv == 'contract.business_name') unset($indexField[(int)$kk]);
190
         }
196
         }
197
+
198
+        # zjf 20210727 添加回款绑定合同    合同列表   状态为审核通过和正常
199
+        if($requestMap['check_status'] == 2){
200
+            $map['contract.check_status'] = ['in', [2,7]];
201
+        }
202
+        
191
 		$list = db('crm_contract')
203
 		$list = db('crm_contract')
192
 				->alias('contract')
204
 				->alias('contract')
193
 				->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT')		
205
 				->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT')		
218
         foreach ($extraList AS $key => $value) {
230
         foreach ($extraList AS $key => $value) {
219
             $extraData[$value['contract_id']][$value['field']] = $value['content'];
231
             $extraData[$value['contract_id']][$value['field']] = $value['content'];
220
         }
232
         }
233
+        $grantData = getFieldGrantData($user_id);
234
+        foreach ($grantData['crm_contract'] as $key => $value) {
235
+            foreach ($value as $ke => $va) {
236
+                if($va['maskType']!=0){
237
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
238
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
239
+                    $fieldGrant[$ke]['field'] = $va['field'];
240
+                }
241
+            }
242
+        }
221
         foreach ($list as $k=>$v) {
243
         foreach ($list as $k=>$v) {
222
         	$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
244
         	$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
223
         	$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
245
         	$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
253
             // 定位类型字段
275
             // 定位类型字段
254
             foreach ($locationField AS $key => $val) {
276
             foreach ($locationField AS $key => $val) {
255
                 $list[$k][$val] = !empty($extraData[$v['contract_id']][$val]) ? json_decode($extraData[$v['contract_id']][$val], true) : null;
277
                 $list[$k][$val] = !empty($extraData[$v['contract_id']][$val]) ? json_decode($extraData[$v['contract_id']][$val], true) : null;
278
+            }
279
+            // 多选框类型字段
280
+            foreach ($boxField AS $key => $val) {
281
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
282
+            }
283
+            // 货币类型字段
284
+            foreach ($floatField AS $key => $val) {
285
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
286
+            }
287
+            //掩码相关类型字段
288
+            foreach ($fieldGrant AS $key => $val){
289
+                //掩码相关类型字段
290
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
291
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
292
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
293
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
294
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
295
+                    $email_array = explode("@", $v[$val['field']]);
296
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
297
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
298
+                    $rs = $prevfix . $str;
299
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
300
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
301
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
302
+                }
256
             }
303
             }
257
         	$list[$k]['business_id_info']['business_id'] = $v['business_id'];
304
         	$list[$k]['business_id_info']['business_id'] = $v['business_id'];
258
         	$list[$k]['business_id_info']['name'] = $v['business_name'];
305
         	$list[$k]['business_id_info']['name'] = $v['business_name'];
260
         	$list[$k]['customer_id_info']['name'] = $v['customer_name'];
307
         	$list[$k]['customer_id_info']['name'] = $v['customer_name'];
261
 			$list[$k]['contacts_id_info']['contacts_id'] = $v['contacts_id'];
308
 			$list[$k]['contacts_id_info']['contacts_id'] = $v['contacts_id'];
262
         	$list[$k]['contacts_id_info']['name'] = $v['contacts_name'];
309
         	$list[$k]['contacts_id_info']['name'] = $v['contacts_name'];
310
+
263
             $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
311
             $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
264
         	$moneyInfo = [];
312
         	$moneyInfo = [];
265
         	$moneyInfo = $receivablesModel->getMoneyByContractId($v['contract_id']);
313
         	$moneyInfo = $receivablesModel->getMoneyByContractId($v['contract_id']);
298
             $list[$k]['order_user_name'] = implode(',', $orderNames);
346
             $list[$k]['order_user_name'] = implode(',', $orderNames);
299
             unset($list[$k]['order_user_id']);
347
             unset($list[$k]['order_user_id']);
300
             $list[$k]['order_user_id_name'] = $v['order_user_id'];
348
             $list[$k]['order_user_id_name'] = $v['order_user_id'];
349
+
350
+            # 系统字段  负责人部门   zjf  20210726
351
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
301
         }
352
         }
302
         $data = [];
353
         $data = [];
303
         $data['list'] = $list;
354
         $data['list'] = $list;
749
      * @throws \think\db\exception\ModelNotFoundException
800
      * @throws \think\db\exception\ModelNotFoundException
750
      * @throws \think\exception\DbException
801
      * @throws \think\exception\DbException
751
      */
802
      */
752
-   	public function getDataById($id = '', $userId = 0)
803
+   	public function getDataById($id = '', $userId = 0,$model='')
753
    	{   
804
    	{   
754
    		$receivablesModel = new \app\crm\model\Receivables();
805
    		$receivablesModel = new \app\crm\model\Receivables();
755
    		$userModel = new \app\admin\model\User();	
806
    		$userModel = new \app\admin\model\User();	
759
 			$this->error = '暂无此数据';
810
 			$this->error = '暂无此数据';
760
 			return false;
811
 			return false;
761
 		}
812
 		}
813
+        if(empty($model) && $model!='update'){
814
+            $grantData = getFieldGrantData($userId);
815
+            foreach ($grantData['crm_contract'] as $key => $value) {
816
+                foreach ($value as $ke => $va) {
817
+                    if($va['maskType']!=0){
818
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
819
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
820
+                        $fieldGrant[$ke]['field'] = $va['field'];
821
+                    }
822
+                }
823
+            }
824
+            foreach ($fieldGrant AS $key => $val){
825
+                //掩码相关类型字段
826
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
827
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
828
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
829
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
830
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
831
+                    $email_array = explode("@", $dataInfo[$val['field']]);
832
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
833
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
834
+                    $rs = $prevfix . $str;
835
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
836
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
837
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
838
+                }
839
+            }
840
+        }
841
+
762
 		$dataInfo['create_user_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
842
 		$dataInfo['create_user_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
763
 		$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; 
843
 		$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; 
764
 		$dataInfo['create_user_name'] = !empty($dataInfo['create_user_info']['realname']) ? $dataInfo['create_user_info']['realname'] : '';
844
 		$dataInfo['create_user_name'] = !empty($dataInfo['create_user_info']['realname']) ? $dataInfo['create_user_info']['realname'] : '';
903
 	public function getSystemInfo($id)
983
 	public function getSystemInfo($id)
904
     {
984
     {
905
         # 合同
985
         # 合同
906
-        $business = Db::name('crm_contract')->where('contract_id', $id)->find();
986
+        $contract = Db::name('crm_contract')->where('contract_id', $id)->find();
907
         # 创建人
987
         # 创建人
908
-        $realname = Db::name('admin_user')->where('id', $business['create_user_id'])->value('realname');
988
+        $realname = Db::name('admin_user')->where('id', $contract['create_user_id'])->value('realname');
989
+        
990
+        # zjf   20210726
991
+        $userModel   = new \app\admin\model\User();
992
+        $ownerUserInfo = $userModel->getUserById($contract['owner_user_id']);
993
+        # 负责人部门
994
+        $ownerStructureName = $ownerUserInfo['structure_name'];
995
+
996
+        # 负责人
997
+        $ownerUserName = $ownerUserInfo['realname'];
998
+        
909
         # 回款
999
         # 回款
910
         $receivablesModel = new Receivables();
1000
         $receivablesModel = new Receivables();
911
         $receivables = $receivablesModel->getMoneyByContractId($id);
1001
         $receivables = $receivablesModel->getMoneyByContractId($id);
912
 
1002
 
913
         return [
1003
         return [
914
             'create_user_id' => $realname,
1004
             'create_user_id' => $realname,
915
-            'create_time' => date('Y-m-d H:i:s', $business['create_time']),
916
-            'update_time' => date('Y-m-d H:i:s', $business['update_time']),
917
-            'last_time' => !empty($business['last_time']) ? date('Y-m-d H:i:s', $business['last_time']) : '',
1005
+            'owner_user_id' => $ownerUserName,
1006
+            'create_time' => date('Y-m-d H:i:s', $contract['create_time']),
1007
+            'update_time' => date('Y-m-d H:i:s', $contract['update_time']),
1008
+            'last_time' => !empty($contract['last_time']) ? date('Y-m-d H:i:s', $contract['last_time']) : '',
918
             'done_money' => $receivables['doneMoney'],
1009
             'done_money' => $receivables['doneMoney'],
919
-            'un_money' => $receivables['unMoney']
1010
+            'un_money' => $receivables['unMoney'],
1011
+            'owner_user_structure_name' => $ownerStructureName
920
         ];
1012
         ];
921
     }
1013
     }
922
 
1014
 

+ 148
- 28
application/crm/model/Customer.php Просмотреть файл

70
         $request    = $this->fmtRequest( $request );
70
         $request    = $this->fmtRequest( $request );
71
         $requestMap = $request['map'] ? : [];
71
         $requestMap = $request['map'] ? : [];
72
 		$sceneModel = new \app\admin\model\Scene();
72
 		$sceneModel = new \app\admin\model\Scene();
73
-
74
 		# 客户默认条件
73
 		# 客户默认条件
75
         $customerMap = $this->getWhereByCustomer();
74
         $customerMap = $this->getWhereByCustomer();
76
 
75
 
105
             unset($map['team_id']);
104
             unset($map['team_id']);
106
         }else{
105
         }else{
107
             $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
106
             $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
107
+          
108
         }
108
         }
109
+      
109
 		# 高级筛选
110
 		# 高级筛选
110
 		$map = advancedQuery($map, 'crm', 'customer', 'index');
111
 		$map = advancedQuery($map, 'crm', 'customer', 'index');
111
 		
112
 		
112
-		
113
         # 工作台仪表盘
113
         # 工作台仪表盘
114
         $requestData = $this->requestData();
114
         $requestData = $this->requestData();
115
         $dashboardWhere = [];
115
         $dashboardWhere = [];
204
         $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); // 地址类型字段
204
         $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); // 地址类型字段
205
         $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); // 手写签名类型字段
205
         $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); // 手写签名类型字段
206
         $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); // 定位类型字段
206
         $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); // 定位类型字段
207
+        $boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
208
+        $floatField = $fieldModel->getFieldByFormType('crm_customer', 'floatnumber'); // 货币类型字段
207
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
209
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
208
         $temporaryField = str_replace('_name', '', $order_field);
210
         $temporaryField = str_replace('_name', '', $order_field);
209
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
211
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
210
             $order_field = $temporaryField;
212
             $order_field = $temporaryField;
211
         }
213
         }
214
+
212
 		# 排序
215
 		# 排序
213
-		if ($order_type && $order_field) {
216
+		if ($order_type && $order_field && $order_field != 'owner_user_structure_name') {
214
 			$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
217
 			$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
215
 		} else {
218
 		} else {
216
 			$order = 'customer.update_time desc';
219
 			$order = 'customer.update_time desc';
229
         		->limit($request['offset'], $request['length'])
232
         		->limit($request['offset'], $request['length'])
230
         		->field($indexField)
233
         		->field($indexField)
231
         		->orderRaw($order)
234
         		->orderRaw($order)
235
+                // ->fetchSql()
232
 				->select();
236
 				->select();
237
+//	p(db('crm_customer')->getLastSql());
233
         $readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read');
238
         $readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read');
234
         $updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update');
239
         $updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update');
235
 		$deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete');
240
 		$deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete');
245
 				])
250
 				])
246
 				->group('customer_id')
251
 				->group('customer_id')
247
 				->select();
252
 				->select();
253
+    
248
 			$business_count = array_column($business_count, null, 'customer_id');
254
 			$business_count = array_column($business_count, null, 'customer_id');
249
 			$field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id);
255
 			$field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id);
250
 			$field_list = array_column($field_list, 'field');
256
 			$field_list = array_column($field_list, 'field');
257
+   
251
 			# 扩展数据
258
 			# 扩展数据
252
             $extraData = [];
259
             $extraData = [];
253
             $extraList = db('crm_customer_data')->whereIn('customer_id', $customer_id_list)->select();
260
             $extraList = db('crm_customer_data')->whereIn('customer_id', $customer_id_list)->select();
254
             foreach ($extraList AS $key => $value) {
261
             foreach ($extraList AS $key => $value) {
255
                 $extraData[$value['customer_id']][$value['field']] = $value['content'];
262
                 $extraData[$value['customer_id']][$value['field']] = $value['content'];
256
             }
263
             }
264
+            $grantData = getFieldGrantData($user_id);
265
+            foreach ($grantData['crm_customer'] as $key => $value) {
266
+                foreach ($value as $ke => $va) {
267
+                    if($va['maskType']!=0){
268
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
269
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
270
+                        $fieldGrant[$ke]['field'] = $va['field'];
271
+                    }
272
+                }
273
+            }
257
             # 获取进入公海天数
274
             # 获取进入公海天数
258
             $poolDays = $this->getPoolDay($customer_id_list);
275
             $poolDays = $this->getPoolDay($customer_id_list);
259
             # 整理数据
276
             # 整理数据
260
 			foreach ($list AS $k => $v) {
277
 			foreach ($list AS $k => $v) {
278
+          
261
 	        	$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
279
 	        	$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
262
 				$list[$k]['owner_user_id_info']  = isset($v['owner_user_id'])  ? $userModel->getUserById($v['owner_user_id'])  : [];
280
 				$list[$k]['owner_user_id_info']  = isset($v['owner_user_id'])  ? $userModel->getUserById($v['owner_user_id'])  : [];
263
 				$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
281
 				$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
264
                 $list[$k]['owner_user_name']  = !empty($list[$k]['owner_user_id_info']['realname'])  ? $list[$k]['owner_user_id_info']['realname']  : '';
282
                 $list[$k]['owner_user_name']  = !empty($list[$k]['owner_user_id_info']['realname'])  ? $list[$k]['owner_user_id_info']['realname']  : '';
283
+               
265
                 # 用户类型字段
284
                 # 用户类型字段
266
 				foreach ($userField AS $key => $val) {
285
 				foreach ($userField AS $key => $val) {
267
 					if (in_array($val, $indexField)) {
286
 					if (in_array($val, $indexField)) {
300
                 // 定位类型字段
319
                 // 定位类型字段
301
                 foreach ($locationField AS $key => $val) {
320
                 foreach ($locationField AS $key => $val) {
302
                     $list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
321
                     $list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
322
+                }
323
+                // 多选框类型字段
324
+                foreach ($boxField AS $key => $val) {
325
+                    $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
326
+                }
327
+                // 货币类型字段
328
+                foreach ($floatField AS $key => $val) {
329
+                    $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
330
+                }
331
+                //掩码相关类型字段
332
+                foreach ($fieldGrant AS $key => $val){
333
+                    //掩码相关类型字段
334
+                    if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
335
+                        $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
336
+                        $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
337
+                        $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
338
+                    } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
339
+                        $email_array = explode("@", $v[$val['field']]);
340
+                        $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
341
+                        $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
342
+                        $rs = $prevfix . $str;
343
+                        $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
344
+                    } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
345
+                        $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
346
+                    }
303
                 }
347
                 }
304
 				# 商机数
348
 				# 商机数
305
 				$list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0;
349
 				$list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0;
331
                 # 进入公海天数
375
                 # 进入公海天数
332
                 $list[$k]['pool_day'] = isset($poolDays[$v['customer_id']]) ? $poolDays[$v['customer_id']] : '';
376
                 $list[$k]['pool_day'] = isset($poolDays[$v['customer_id']]) ? $poolDays[$v['customer_id']] : '';
333
                 $list[$k]['is_pool'] = 0;
377
                 $list[$k]['is_pool'] = 0;
378
+
379
+                # 系统字段  负责人部门   zjf  20210726
380
+                $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
334
 			}
381
 			}
335
         }
382
         }
336
         $data = [];
383
         $data = [];
423
         $locationField     = $fieldModel->getFieldByFormType('crm_customer', 'location');
470
         $locationField     = $fieldModel->getFieldByFormType('crm_customer', 'location');
424
         $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval');
471
         $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval');
425
         $detailTableField  = $fieldModel->getFieldByFormType('crm_customer', 'detail_table');
472
         $detailTableField  = $fieldModel->getFieldByFormType('crm_customer', 'detail_table');
473
+        $dateField  = $fieldModel->getFieldByFormType('crm_customer', 'date');
426
         foreach ($param AS $key => $value) {
474
         foreach ($param AS $key => $value) {
427
             // 处理地址类型字段数据
475
             // 处理地址类型字段数据
428
             if (in_array($key, $positionField)) {
476
             if (in_array($key, $positionField)) {
429
-                if (!empty($value)) {
477
+                if (!empty($value) && is_array($value)) {
430
                     $customerData[] = [
478
                     $customerData[] = [
431
                         'field'       => $key,
479
                         'field'       => $key,
432
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
480
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
434
                     ];
482
                     ];
435
                     $positionNames = array_column($value, 'name');
483
                     $positionNames = array_column($value, 'name');
436
                     $param[$key] = implode(',', $positionNames);
484
                     $param[$key] = implode(',', $positionNames);
437
-                } else {
485
+                } elseif(!empty($value) && !is_array($value)){
486
+                    $param[$key] = $value;
487
+                }else{
438
                     $param[$key] = '';
488
                     $param[$key] = '';
439
                 }
489
                 }
440
             }
490
             }
441
             // 处理定位类型字段数据
491
             // 处理定位类型字段数据
442
             if (in_array($key, $locationField)) {
492
             if (in_array($key, $locationField)) {
443
-                if (!empty($value)) {
493
+                if (!empty($value) && isset($value['address'])) {
444
                     $customerData[] = [
494
                     $customerData[] = [
445
                         'field'       => $key,
495
                         'field'       => $key,
446
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
496
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
447
                         'create_time' => time()
497
                         'create_time' => time()
448
                     ];
498
                     ];
449
                     $param[$key] = $value['address'];
499
                     $param[$key] = $value['address'];
450
-                } else {
500
+                } elseif(!empty($value) && !isset($value['address'])){
501
+                    $vv['address']=$value;
502
+                    $customerData[] = [
503
+                        'field'       => $key,
504
+                        'content'     => json_encode($vv, JSON_NUMERIC_CHECK),
505
+                        'create_time' => time()
506
+                    ];
507
+                    $param[$key] = $value;
508
+                } else{
451
                     $param[$key] = '';
509
                     $param[$key] = '';
452
                 }
510
                 }
453
             }
511
             }
454
             // 处理日期区间类型字段数据
512
             // 处理日期区间类型字段数据
455
             if (in_array($key, $dateIntervalField)) {
513
             if (in_array($key, $dateIntervalField)) {
456
-                if (!empty($value)) {
514
+                if (!empty($value) && is_array($value)) {
457
                     $customerData[] = [
515
                     $customerData[] = [
458
                         'field'       => $key,
516
                         'field'       => $key,
459
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
517
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
460
                         'create_time' => time()
518
                         'create_time' => time()
461
                     ];
519
                     ];
462
-                    $param[$key] = implode('_', $value);
463
-                } else {
520
+                    $param[$key] = trim(implode('_', $value),'"');
521
+                } elseif(!empty($value) && !is_array($value)){
522
+                    $param[$key] = $value;
523
+                }else{
464
                     $param[$key] = '';
524
                     $param[$key] = '';
465
                 }
525
                 }
466
             }
526
             }
477
                     $param[$key] = '';
537
                     $param[$key] = '';
478
                 }
538
                 }
479
             }
539
             }
540
+            $param[$key]=!empty($value)?trim($value,','):'';
541
+            if (in_array($key, $dateField)) {
542
+                if (!empty($value) ) {
543
+                    $customerData[] = [
544
+                        'field'       => $key,
545
+                        'content'     => json_encode($value, JSON_NUMERIC_CHECK),
546
+                        'create_time' => time()
547
+                    ];
548
+                    $param[$key] = $value;
549
+                } else{
550
+                    $param[$key] = null;
551
+                }
552
+            }
480
         }
553
         }
481
-
554
+//        p($customerData);
482
         # 设置今日需联系客户
555
         # 设置今日需联系客户
483
         if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
556
         if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
484
         $pool_id = !empty($param['pool_id']) ? $param['pool_id'] : 0;
557
         $pool_id = !empty($param['pool_id']) ? $param['pool_id'] : 0;
485
         unset($param['pool_id']);
558
         unset($param['pool_id']);
559
+
486
         if ($this->data($param)->allowField(true)->isUpdate(false)->save()) {
560
         if ($this->data($param)->allowField(true)->isUpdate(false)->save()) {
487
             $data['customer_id'] = $this->customer_id;
561
             $data['customer_id'] = $this->customer_id;
488
             $data['name'] = $param['name'];
562
             $data['name'] = $param['name'];
647
             // 处理日期区间类型字段数据
721
             // 处理日期区间类型字段数据
648
             if (in_array($key, $dateIntervalField)) {
722
             if (in_array($key, $dateIntervalField)) {
649
                 if (!empty($value)) {
723
                 if (!empty($value)) {
724
+
650
                     $customerData[] = [
725
                     $customerData[] = [
651
                         'field'       => $key,
726
                         'field'       => $key,
652
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
727
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
653
                         'create_time' => time()
728
                         'create_time' => time()
654
                     ];
729
                     ];
655
-                    $param[$key] = implode('_', $value);
730
+
731
+                    $param[$key] =implode('_',  $value);
656
                 } else {
732
                 } else {
657
                     $param[$key] = '';
733
                     $param[$key] = '';
658
                 }
734
                 }
671
                 }
747
                 }
672
             }
748
             }
673
         }
749
         }
674
-
675
         // 设置今日需联系客户
750
         // 设置今日需联系客户
676
         if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
751
         if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
677
 
752
 
709
      * @throws \think\db\exception\ModelNotFoundException
784
      * @throws \think\db\exception\ModelNotFoundException
710
      * @throws \think\exception\DbException
785
      * @throws \think\exception\DbException
711
      */
786
      */
712
-   	public function getDataById($id = '', $userId = 0)
787
+   	public function getDataById($id = '', $userId = 0,$model='')
713
    	{  
788
    	{  
714
 		$dataInfo = db('crm_customer')->where(['customer_id' => $id])->find();
789
 		$dataInfo = db('crm_customer')->where(['customer_id' => $id])->find();
715
 		if (!$dataInfo) {
790
 		if (!$dataInfo) {
716
 			$this->error = '数据不存在或已删除';
791
 			$this->error = '数据不存在或已删除';
717
 			return false;
792
 			return false;
718
 		}
793
 		}
794
+		if(empty($model) && $model!='update'){
795
+            $grantData = getFieldGrantData($userId);
796
+            foreach ($grantData['crm_customer'] as $key => $value) {
797
+                foreach ($value as $ke => $va) {
798
+                    if($va['maskType']!=0){
799
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
800
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
801
+                        $fieldGrant[$ke]['field'] = $va['field'];
802
+                    }
803
+                }
804
+            }
805
+            foreach ($fieldGrant AS $key => $val){
806
+                //掩码相关类型字段
807
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
808
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
809
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
810
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
811
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
812
+                    $email_array = explode("@", $dataInfo[$val['field']]);
813
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
814
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
815
+                    $rs = $prevfix . $str;
816
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
817
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
818
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
819
+                }
820
+            }
821
+        }
719
 		$userModel = new \app\admin\model\User();
822
 		$userModel = new \app\admin\model\User();
720
 		$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
823
 		$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
721
 		$dataInfo['owner_user_id_info'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
824
 		$dataInfo['owner_user_id_info'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
1608
      */
1711
      */
1609
     public function getNearbyList($param)
1712
     public function getNearbyList($param)
1610
     {
1713
     {
1714
+        $apiCommon = new ApiCommon();
1611
         $userModel = new \app\admin\model\User();
1715
         $userModel = new \app\admin\model\User();
1612
 
1716
 
1613
-        # 客户条件
1717
+        $poolStatus = checkPerByAction('crm', 'customer', 'pool');
1718
+
1719
+        # 客户
1720
+        $customerAuth = [];
1614
         $customerWhere = [];
1721
         $customerWhere = [];
1615
-        if (!empty($param['type']) && $param['type'] == 2) {
1722
+        if ((!empty($param['type']) && $param['type'] == 2) || !$poolStatus) {
1616
             $customerWhere = $this->getWhereByCustomer();
1723
             $customerWhere = $this->getWhereByCustomer();
1617
         }
1724
         }
1618
 
1725
 
1619
-        # 公海条件
1726
+        # 公海
1620
         $poolWhere = [];
1727
         $poolWhere = [];
1621
-        if (!empty($param['type']) && $param['type'] == 9) {
1728
+        if (!empty($param['type']) && $param['type'] == 9 && $poolStatus) {
1622
             $poolWhere = ['customer.owner_user_id' => 0];
1729
             $poolWhere = ['customer.owner_user_id' => 0];
1623
-            $model = '公海客户管理模块';
1624
         }
1730
         }
1625
-
1626
-        # 距离条件
1731
+        # 附近
1627
         $lngLatRange = $this->getLngLatRange($param['lng'], $param['lat'], $param['distance']);
1732
         $lngLatRange = $this->getLngLatRange($param['lng'], $param['lat'], $param['distance']);
1628
         $lngLatWhere = function ($query) use ($lngLatRange) {
1733
         $lngLatWhere = function ($query) use ($lngLatRange) {
1629
             $query->where(['lng' => ['egt', $lngLatRange['minLng']]]);
1734
             $query->where(['lng' => ['egt', $lngLatRange['minLng']]]);
1643
             ->where($customerWhere)
1748
             ->where($customerWhere)
1644
             ->where($poolWhere)
1749
             ->where($poolWhere)
1645
             ->where($lngLatWhere)
1750
             ->where($lngLatWhere)
1646
-            ->field(['customer_id', 'name', 'address', 'detail_address', 'owner_user_id', 'lat', 'lng','next_time','last_time'])
1751
+            ->where($customerAuth)
1752
+            ->field(['customer_id', 'name', 'address', 'detail_address', 'owner_user_id', 'lat', 'lng', 'next_time', 'last_time'])
1647
             ->order('update_time', 'desc')
1753
             ->order('update_time', 'desc')
1648
             ->select();
1754
             ->select();
1649
 
1755
 
1650
         # 组装数据
1756
         # 组装数据
1651
         foreach ($list as $key => $value) {
1757
         foreach ($list as $key => $value) {
1652
-            $ownerUserInfo = !empty($value['owner_user_id'])    ? $userModel->getUserById($value['owner_user_id']) : [];
1758
+            # todo 暂时将查询写在循环中
1759
+            $ownerUserInfo = !empty($value['owner_user_id']) ? $userModel->getUserById($value['owner_user_id']) : [];
1653
             $ownerUserName = !empty($ownerUserInfo['realname']) ? $ownerUserInfo['realname'] : '';
1760
             $ownerUserName = !empty($ownerUserInfo['realname']) ? $ownerUserInfo['realname'] : '';
1654
             $list[$key]['owner_user_name'] = !empty($ownerUserName) ? $ownerUserName : '暂无负责人';
1761
             $list[$key]['owner_user_name'] = !empty($ownerUserName) ? $ownerUserName : '暂无负责人';
1655
             $list[$key]['distance'] = $this->getLngLatDistance($param['lng'], $param['lat'], $value['lng'], $value['lat'], 1, 0);
1762
             $list[$key]['distance'] = $this->getLngLatDistance($param['lng'], $param['lat'], $value['lng'], $value['lat'], 1, 0);
1656
-            $list[$key]['last_time'] = !empty($value['last_time'])?date('y-m-d H:i:s',$value['last_time']):!empty($value['next_time'])?date('y-m-d H:i:s',$value['next_time']):null;
1657
-            $list[$key]['model']=$model;
1763
+            $list[$key]['last_time'] = !empty($value['last_time']) ? date('y-m-d H:i:s', $value['last_time']) : !empty($value['next_time']) ? date('y-m-d H:i:s', $value['next_time']) : null;
1764
+            if ($value['owner_user_id'] != 0) {
1765
+                $list[$key]['model'] = '客户';
1766
+            } else {
1767
+                $list[$key]['model'] = '公海';
1768
+            }
1658
         }
1769
         }
1659
 
1770
 
1771
+
1660
         return ['list' => $list, 'count' => $count];
1772
         return ['list' => $list, 'count' => $count];
1661
     }
1773
     }
1662
 
1774
 
1775
+
1663
     /**
1776
     /**
1664
      * 计算两点地理坐标之间的距离
1777
      * 计算两点地理坐标之间的距离
1665
      *
1778
      *
1737
         $customer = Db::name('crm_customer')->field($field)->where('customer_id', $id)->find();
1850
         $customer = Db::name('crm_customer')->field($field)->where('customer_id', $id)->find();
1738
         # 创建人
1851
         # 创建人
1739
         $createUserName = Db::name('admin_user')->where('id', $customer['create_user_id'])->value('realname');
1852
         $createUserName = Db::name('admin_user')->where('id', $customer['create_user_id'])->value('realname');
1740
-        # 负责人
1741
-        $ownerUserName = Db::name('admin_user')->where('id', $customer['owner_user_id'])->value('realname');
1742
 
1853
 
1854
+        # zjf   20210726
1855
+        $userModel   = new \app\admin\model\User();
1856
+        $ownerUserInfo = $userModel->getUserById($customer['owner_user_id']);
1857
+        # 负责人部门
1858
+        $ownerStructureName = $ownerUserInfo['structure_name'];
1859
+
1860
+        # 负责人
1861
+        $ownerUserName = $ownerUserInfo['realname'];
1743
         return [
1862
         return [
1744
             'obtain_time' => !empty($customer['obtain_time']) ? date('Y-m-d H:i:s', $customer['obtain_time']) : '',
1863
             'obtain_time' => !empty($customer['obtain_time']) ? date('Y-m-d H:i:s', $customer['obtain_time']) : '',
1745
             'last_record' => !empty($customer['last_record']) ? $customer['last_record'] : '',
1864
             'last_record' => !empty($customer['last_record']) ? $customer['last_record'] : '',
1748
             'create_time' => date('Y-m-d H:i:s', $customer['create_time']),
1867
             'create_time' => date('Y-m-d H:i:s', $customer['create_time']),
1749
             'update_time' => date('Y-m-d H:i:s', $customer['update_time']),
1868
             'update_time' => date('Y-m-d H:i:s', $customer['update_time']),
1750
             'last_time' => !empty($customer['last_time']) ? date('Y-m-d H:i:s', $customer['last_time']) : '',
1869
             'last_time' => !empty($customer['last_time']) ? date('Y-m-d H:i:s', $customer['last_time']) : '',
1751
-            'deal_status' => $customer['deal_status']
1870
+            'deal_status' => $customer['deal_status'],
1871
+            'owner_user_structure_name' => $ownerStructureName
1752
         ];
1872
         ];
1753
     }
1873
     }
1754
 
1874
 

+ 93
- 0
application/crm/model/Invoice.php Просмотреть файл

51
            'owner_user_name' => 'realname'
51
            'owner_user_name' => 'realname'
52
         ]);
52
         ]);
53
     }
53
     }
54
+
55
+    /**
56
+     * @param string $id
57
+     * @param int $userId
58
+     * @param string $model
59
+     * @author: alvin guogaobo
60
+     * @version: 11.1.0
61
+     * Date: 2021/8/30 14:11
62
+     */
63
+    public function getDataById($id = '', $userId = 0, $model='')
64
+    {
65
+        $map['invoice_id'] = $id;
66
+        $dataInfo = $this->where($map)->find();
67
+        if (!$dataInfo) {
68
+            $this->error = '暂无此数据';
69
+            return false;
70
+        }
71
+        if(empty($model) && $model!='update'){
72
+            $grantData = getFieldGrantData($userId);
73
+            foreach ($grantData['crm_invoice'] as $key => $value) {
74
+                foreach ($value as $ke => $va) {
75
+                    if($va['maskType']!=0){
76
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
77
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
78
+                        $fieldGrant[$ke]['field'] = $va['field'];
79
+                    }
80
+                }
81
+            }
82
+            foreach ($fieldGrant AS $key => $val){
83
+                //掩码相关类型字段
84
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
85
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
86
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
87
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
88
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
89
+                    $email_array = explode("@", $dataInfo[$val['field']]);
90
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
91
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
92
+                    $rs = $prevfix . $str;
93
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
94
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
95
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
96
+                }
97
+            }
98
+        }
99
+//        $userModel = new \app\admin\model\User();
100
+//        $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
101
+//        $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
102
+//        $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
103
+//        $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
104
+//        $dataInfo['customer_id_info'] = $dataInfo['customer_id'] ? db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find() : [];
105
+//        $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
106
+//        $dataInfo['receivables_id'] = $id;
107
+//        $userModel = new \app\admin\model\User();
108
+//        $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
109
+//        $dataInfo['plan_id'] = $id;
110
+//        # 处理时间格式
111
+//        $fieldModel = new \app\admin\model\Field();
112
+//        $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
113
+//        foreach ($datetimeField as $key => $val) {
114
+//            $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
115
+//        }
116
+//        $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
117
+//        $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
118
+//        // 字段授权
119
+//        if (!empty($userId)) {
120
+//            $grantData = getFieldGrantData($userId);
121
+//            $userLevel = isSuperAdministrators($userId);
122
+//            foreach ($dataInfo as $key => $value) {
123
+//                if (!$userLevel && !empty($grantData['crm_receivables'])) {
124
+//                    $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
125
+//
126
+//                    # 查看权限
127
+//                    if ($status['read'] == 0) unset($dataInfo[$key]);
128
+//                }
129
+//            }
130
+//            if (!$userLevel && !empty($grantData['crm_receivables'])) {
131
+//                # 客户名称
132
+//                $customerStatus = getFieldGrantStatus('customer_id', $grantData['crm_receivables']);
133
+//                if ($customerStatus['read'] == 0) {
134
+//                    $dataInfo['customer_name'] = '';
135
+//                    $dataInfo['customer_id_info'] = [];
136
+//                }
137
+//                # 合同金额
138
+//                $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
139
+//                if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
140
+//                # 合同名称
141
+//                $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
142
+//                if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
143
+//            }
144
+//        }
145
+        return $dataInfo;
146
+    }
54
 }
147
 }

+ 90
- 7
application/crm/model/Leads.php Просмотреть файл

112
         $positionField = $fieldModel->getFieldByFormType('crm_leads', 'position'); // 地址类型字段
112
         $positionField = $fieldModel->getFieldByFormType('crm_leads', 'position'); // 地址类型字段
113
         $handwritingField = $fieldModel->getFieldByFormType('crm_leads', 'handwriting_sign'); // 手写签名类型字段
113
         $handwritingField = $fieldModel->getFieldByFormType('crm_leads', 'handwriting_sign'); // 手写签名类型字段
114
         $locationField = $fieldModel->getFieldByFormType('crm_leads', 'location'); // 定位类型字段
114
         $locationField = $fieldModel->getFieldByFormType('crm_leads', 'location'); // 定位类型字段
115
+        $boxField = $fieldModel->getFieldByFormType('crm_leads', 'checkbox'); // 多选类型字段
116
+        $floatField = $fieldModel->getFieldByFormType('crm_leads', 'floatnumber'); // 货币类型字段
115
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
117
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
116
         $temporaryField = str_replace('_name', '', $order_field);
118
         $temporaryField = str_replace('_name', '', $order_field);
117
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
119
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
153
             ->field(implode(',', $indexField))
155
             ->field(implode(',', $indexField))
154
             ->orderRaw($order)
156
             ->orderRaw($order)
155
             ->select();
157
             ->select();
156
-//        echo db('crm_leads')->getLastSql();exit;
157
         # 扩展数据
158
         # 扩展数据
158
         $extraData = [];
159
         $extraData = [];
159
         $leads_id_list = !empty($list) ? array_column($list, 'leads_id') : [];
160
         $leads_id_list = !empty($list) ? array_column($list, 'leads_id') : [];
161
         foreach ($extraList AS $key => $value) {
162
         foreach ($extraList AS $key => $value) {
162
             $extraData[$value['leads_id']][$value['field']] = $value['content'];
163
             $extraData[$value['leads_id']][$value['field']] = $value['content'];
163
         }
164
         }
165
+
166
+        $grantData = getFieldGrantData($user_id);
167
+        foreach ($grantData['crm_leads'] as $key => $value) {
168
+            foreach ($value as $ke => $va) {
169
+                if($va['maskType']!=0){
170
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
171
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
172
+                    $fieldGrant[$ke]['field'] = $va['field'];
173
+                }
174
+            }
175
+        }
164
         foreach ($list as $k => $v) {
176
         foreach ($list as $k => $v) {
165
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
177
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
166
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
178
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
197
             foreach ($locationField AS $key => $val) {
209
             foreach ($locationField AS $key => $val) {
198
                 $list[$k][$val] = !empty($extraData[$v['leads_id']][$val]) ? json_decode($extraData[$v['leads_id']][$val], true) : null;
210
                 $list[$k][$val] = !empty($extraData[$v['leads_id']][$val]) ? json_decode($extraData[$v['leads_id']][$val], true) : null;
199
             }
211
             }
212
+            // 多选框类型字段
213
+            foreach ($boxField AS $key => $val) {
214
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
215
+            }
216
+            // 货币类型字段
217
+            foreach ($floatField AS $key => $val) {
218
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
219
+            }
220
+
221
+            foreach ($fieldGrant AS $key => $val){
222
+                //掩码相关类型字段
223
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
224
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
225
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
226
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
227
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
228
+                    $email_array = explode("@", $v[$val['field']]);
229
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
230
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
231
+                    $rs = $prevfix . $str;
232
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
233
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
234
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
235
+                }
236
+            }
237
+
238
+            // 货币类型字段
239
+            foreach ($floatField AS $key => $val) {
240
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
241
+            }
200
             //权限
242
             //权限
201
             $permission = [];
243
             $permission = [];
202
             $is_read = 0;
244
             $is_read = 0;
217
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
259
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
218
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
260
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
219
             $list[$k]['last_time']   = !empty($v['last_time'])   ? date('Y-m-d H:i:s', $v['last_time'])   : null;
261
             $list[$k]['last_time']   = !empty($v['last_time'])   ? date('Y-m-d H:i:s', $v['last_time'])   : null;
262
+
263
+            # 系统字段  负责人部门   zjf  20210726
264
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
220
         }
265
         }
221
         $data = [];
266
         $data = [];
222
         $data['list'] = $list;
267
         $data['list'] = $list;
362
                 'type'             => 2,
407
                 'type'             => 2,
363
                 'activity_type'    => 1,
408
                 'activity_type'    => 1,
364
                 'activity_type_id' => $this->leads_id,
409
                 'activity_type_id' => $this->leads_id,
365
-                'content'          => $param['name'],
410
+                'content'          => $param['name']?:'',
366
                 'create_user_id'   => $param['create_user_id'],
411
                 'create_user_id'   => $param['create_user_id'],
367
                 'update_time'      => time(),
412
                 'update_time'      => time(),
368
                 'create_time'      => time(),
413
                 'create_time'      => time(),
542
      * @throws \think\db\exception\ModelNotFoundException
587
      * @throws \think\db\exception\ModelNotFoundException
543
      * @throws \think\exception\DbException
588
      * @throws \think\exception\DbException
544
      */
589
      */
545
-    public function getDataById($id = '', $userId = 0)
590
+    public function getDataById($id = '', $userId = 0, $model='')
546
     {
591
     {
547
         $map['leads_id'] = $id;
592
         $map['leads_id'] = $id;
548
         $dataInfo = db('crm_leads')->where($map)->find();
593
         $dataInfo = db('crm_leads')->where($map)->find();
550
             $this->error = '暂无此数据';
595
             $this->error = '暂无此数据';
551
             return false;
596
             return false;
552
         }
597
         }
598
+
599
+        if(empty($model) && $model!='update'){
600
+            $grantData = getFieldGrantData($userId);
601
+            foreach ($grantData['crm_leads'] as $key => $value) {
602
+                foreach ($value as $ke => $va) {
603
+                    if($va['maskType']!=0){
604
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
605
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
606
+                        $fieldGrant[$ke]['field'] = $va['field'];
607
+                    }
608
+                }
609
+            }
610
+            foreach ($fieldGrant AS $key => $val){
611
+                //掩码相关类型字段
612
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
613
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
614
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
615
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
616
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
617
+                    $email_array = explode("@", $dataInfo[$val['field']]);
618
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
619
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
620
+                    $rs = $prevfix . $str;
621
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
622
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
623
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
624
+                }
625
+            }
626
+        }
553
         $userModel = new \app\admin\model\User();
627
         $userModel = new \app\admin\model\User();
554
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
628
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
555
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
629
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
592
      * @throws \think\db\exception\ModelNotFoundException
666
      * @throws \think\db\exception\ModelNotFoundException
593
      * @throws \think\exception\DbException
667
      * @throws \think\exception\DbException
594
      */
668
      */
595
-    public
596
-    function getSystemInfo($id)
669
+    public function getSystemInfo($id)
597
     {
670
     {
598
         # 线索
671
         # 线索
599
-        $leads = Db::name('crm_leads')->field(['create_user_id', 'create_time', 'update_time', 'last_time'])->where('leads_id', $id)->find();
672
+        $leads = Db::name('crm_leads')->field(['create_user_id','owner_user_id', 'create_time', 'update_time', 'last_time'])->where('leads_id', $id)->find();
600
         # 创建人
673
         # 创建人
601
         $realname = Db::name('admin_user')->where('id', $leads['create_user_id'])->value('realname');
674
         $realname = Db::name('admin_user')->where('id', $leads['create_user_id'])->value('realname');
602
 
675
 
676
+        # zjf   20210726
677
+        $userModel   = new \app\admin\model\User();
678
+        $ownerUserInfo = $userModel->getUserById($leads['owner_user_id']);
679
+        # 负责人部门
680
+        $ownerStructureName = $ownerUserInfo['structure_name'];
681
+
682
+        # 负责人
683
+        $ownerUserName = $ownerUserInfo['realname'];
603
         return [
684
         return [
604
             'create_user_id' => $realname,
685
             'create_user_id' => $realname,
686
+            'owner_user_id' => $ownerUserName,
605
             'create_time' => date('Y-m-d H:i:s', $leads['create_time']),
687
             'create_time' => date('Y-m-d H:i:s', $leads['create_time']),
606
             'update_time' => date('Y-m-d H:i:s', $leads['update_time']),
688
             'update_time' => date('Y-m-d H:i:s', $leads['update_time']),
607
-            'last_time' => !empty($leads['last_time']) ? date('Y-m-d H:i:s', $leads['last_time']) : ''
689
+            'last_time' => !empty($leads['last_time']) ? date('Y-m-d H:i:s', $leads['last_time']) : '',
690
+            'owner_user_structure_name' => $ownerStructureName
608
         ];
691
         ];
609
     }
692
     }
610
 }
693
 }

+ 84
- 4
application/crm/model/Product.php Просмотреть файл

107
         $positionField = $fieldModel->getFieldByFormType('crm_product', 'position'); // 地址类型字段
107
         $positionField = $fieldModel->getFieldByFormType('crm_product', 'position'); // 地址类型字段
108
         $handwritingField = $fieldModel->getFieldByFormType('crm_product', 'handwriting_sign'); // 手写签名类型字段
108
         $handwritingField = $fieldModel->getFieldByFormType('crm_product', 'handwriting_sign'); // 手写签名类型字段
109
         $locationField = $fieldModel->getFieldByFormType('crm_product', 'location'); // 定位类型字段
109
         $locationField = $fieldModel->getFieldByFormType('crm_product', 'location'); // 定位类型字段
110
+        $boxField = $fieldModel->getFieldByFormType('crm_product', 'checkbox'); // 多选类型字段
111
+        $floatField = $fieldModel->getFieldByFormType('crm_product', 'floatnumber'); // 货币类型字段
112
+
110
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
113
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
111
         $temporaryField = str_replace('_name', '', $order_field);
114
         $temporaryField = str_replace('_name', '', $order_field);
112
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
115
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
142
         foreach ($extraList AS $key => $value) {
145
         foreach ($extraList AS $key => $value) {
143
             $extraData[$value['product_id']][$value['field']] = $value['content'];
146
             $extraData[$value['product_id']][$value['field']] = $value['content'];
144
         }
147
         }
148
+        $grantData = getFieldGrantData($user_id);
149
+        foreach ($grantData['crm_product'] as $key => $value) {
150
+            foreach ($value as $ke => $va) {
151
+                if($va['maskType']!=0){
152
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
153
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
154
+                    $fieldGrant[$ke]['field'] = $va['field'];
155
+                }
156
+            }
157
+        }
145
         foreach ($list as $k => $v) {
158
         foreach ($list as $k => $v) {
146
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
159
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
147
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
160
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
178
             foreach ($locationField AS $key => $val) {
191
             foreach ($locationField AS $key => $val) {
179
                 $list[$k][$val] = !empty($extraData[$v['product_id']][$val]) ? json_decode($extraData[$v['product_id']][$val], true) : null;
192
                 $list[$k][$val] = !empty($extraData[$v['product_id']][$val]) ? json_decode($extraData[$v['product_id']][$val], true) : null;
180
             }
193
             }
194
+            // 多选框类型字段
195
+            foreach ($boxField AS $key => $val) {
196
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
197
+            }
198
+            // 货币类型字段
199
+            foreach ($floatField AS $key => $val) {
200
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
201
+            }
202
+            //掩码相关类型字段
203
+            foreach ($fieldGrant AS $key => $val){
204
+                //掩码相关类型字段
205
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
206
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
207
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
208
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
209
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
210
+                    $email_array = explode("@", $v[$val['field']]);
211
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
212
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
213
+                    $rs = $prevfix . $str;
214
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
215
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
216
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
217
+                }
218
+            }
181
             //产品类型
219
             //产品类型
182
             $list[$k]['category_id_info'] = $v['category_name'];
220
             $list[$k]['category_id_info'] = $v['category_name'];
183
             # 处理日期格式
221
             # 处理日期格式
184
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
222
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
185
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
223
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
224
+
225
+            # 系统字段  负责人部门   zjf  20210726
226
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
186
         }
227
         }
187
         $data = [];
228
         $data = [];
188
         $data['list'] = $list;
229
         $data['list'] = $list;
503
      * @throws \think\db\exception\ModelNotFoundException
544
      * @throws \think\db\exception\ModelNotFoundException
504
      * @throws \think\exception\DbException
545
      * @throws \think\exception\DbException
505
      */
546
      */
506
-    public function getDataById($id = '', $userId = 0)
547
+    public function getDataById($id = '', $userId = 0,$model='')
507
     {
548
     {
508
         $map['product_id'] = $id;
549
         $map['product_id'] = $id;
509
         $map['delete_user_id'] = 0;
550
         $map['delete_user_id'] = 0;
512
             $this->error = '暂无此数据';
553
             $this->error = '暂无此数据';
513
             return false;
554
             return false;
514
         }
555
         }
515
-        
556
+        if(empty($model) && $model!='update'){
557
+            $grantData = getFieldGrantData($userId);
558
+            foreach ($grantData['crm_product'] as $key => $value) {
559
+                foreach ($value as $ke => $va) {
560
+                    if($va['maskType']!=0){
561
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
562
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
563
+                        $fieldGrant[$ke]['field'] = $va['field'];
564
+                    }
565
+                }
566
+            }
567
+            foreach ($fieldGrant AS $key => $val){
568
+                //掩码相关类型字段
569
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
570
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
571
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
572
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
573
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
574
+                    $email_array = explode("@", $dataInfo[$val['field']]);
575
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
576
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
577
+                    $rs = $prevfix . $str;
578
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
579
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
580
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
581
+                }
582
+            }
583
+        }
584
+
516
         # 获取封面图片
585
         # 获取封面图片
517
         $dataInfo['cover_images'] = $this->getProductImages($dataInfo['cover_images']);
586
         $dataInfo['cover_images'] = $this->getProductImages($dataInfo['cover_images']);
518
         # 获取详情图片
587
         # 获取详情图片
947
     public function getSystemInfo($id)
1016
     public function getSystemInfo($id)
948
     {
1017
     {
949
         # 产品
1018
         # 产品
950
-        $product = Db::name('crm_product')->field(['create_user_id', 'create_time', 'update_time'])->where('product_id', $id)->find();
1019
+        $product = Db::name('crm_product')->field(['create_user_id','owner_user_id', 'create_time', 'update_time'])->where('product_id', $id)->find();
951
         # 创建人
1020
         # 创建人
952
         $realname = Db::name('admin_user')->where('id', $product['create_user_id'])->value('realname');
1021
         $realname = Db::name('admin_user')->where('id', $product['create_user_id'])->value('realname');
953
         
1022
         
1023
+        # zjf   20210726
1024
+        $userModel   = new \app\admin\model\User();
1025
+        $ownerUserInfo = $userModel->getUserById($product['owner_user_id']);
1026
+        # 负责人部门
1027
+        $ownerStructureName = $ownerUserInfo['structure_name'];
1028
+
1029
+        # 负责人
1030
+        $ownerUserName = $ownerUserInfo['realname'];
1031
+        
954
         return [
1032
         return [
955
             'create_user_id' => $realname,
1033
             'create_user_id' => $realname,
1034
+            'owner_user_id' => $ownerUserName,
956
             'create_time' => date('Y-m-d H:i:s', $product['create_time']),
1035
             'create_time' => date('Y-m-d H:i:s', $product['create_time']),
957
-            'update_time' => date('Y-m-d H:i:s', $product['update_time'])
1036
+            'update_time' => date('Y-m-d H:i:s', $product['update_time']),
1037
+            'owner_user_structure_name' => $ownerStructureName
958
         ];
1038
         ];
959
     }
1039
     }
960
     
1040
     

+ 5
- 3
application/crm/model/ProductCategory.php Просмотреть файл

120
 		if (db('crm_product')->where(['category_id' => $param['id']])->find()) {
120
 		if (db('crm_product')->where(['category_id' => $param['id']])->find()) {
121
 			$resDel = false;			
121
 			$resDel = false;			
122
 		}
122
 		}
123
-		if ($delSon && is_numeric($id)) {
124
-			$childIds = $this->getAllChild($id);
123
+
124
+		if ($delSon && is_numeric($param['id'])) {
125
+			$childIds = $this->getAllChild($param['id']);
125
 			if($childIds){
126
 			if($childIds){
126
 				if (db('crm_product')->where(['category_id' => ['in',$childIds]])->find()) {
127
 				if (db('crm_product')->where(['category_id' => ['in',$childIds]])->find()) {
127
 					$resDel = false;
128
 					$resDel = false;
132
 			$this->error = '请先移除该类型及子类下的相关产品';
133
 			$this->error = '请先移除该类型及子类下的相关产品';
133
 			return false;			
134
 			return false;			
134
 		}
135
 		}
136
+
135
         $data=db('crm_product_category')->where('category_id' , $param['id'])->find();
137
         $data=db('crm_product_category')->where('category_id' , $param['id'])->find();
136
 		//提交事务
138
 		//提交事务
137
 		$this->startTrans();
139
 		$this->startTrans();
145
 				}
147
 				}
146
 			}
148
 			}
147
             # 系统操作日志
149
             # 系统操作日志
148
-            SystemActionLog($param['user_id'], 'crm_product','customer', $id,  'update',$data['name'] , '', '','删除了产品分类:'.$data['name']);
150
+            SystemActionLog($param['user_id'], 'crm_product','customer',  $param['id'],  'update',$data['name'] , '', '','删除了产品分类:'.$data['name']);
149
             $this->commit();
151
             $this->commit();
150
 			return true;
152
 			return true;
151
 		} catch(\Exception $e) {
153
 		} catch(\Exception $e) {

+ 130
- 51
application/crm/model/Receivables.php Просмотреть файл

16
 class Receivables extends Common
16
 class Receivables extends Common
17
 {
17
 {
18
     use FieldVerificationTrait;
18
     use FieldVerificationTrait;
19
-    
19
+
20
     /**
20
     /**
21
      * 为了数据库的整洁,同时又不影响Model和Controller的名称
21
      * 为了数据库的整洁,同时又不影响Model和Controller的名称
22
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
22
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
25
     protected $createTime = 'create_time';
25
     protected $createTime = 'create_time';
26
     protected $updateTime = 'update_time';
26
     protected $updateTime = 'update_time';
27
     protected $autoWriteTimestamp = true;
27
     protected $autoWriteTimestamp = true;
28
-    private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回'];
29
-    
28
+    private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回', '7' => '正常'];
29
+
30
     /**
30
     /**
31
      * [getDataList 回款list]
31
      * [getDataList 回款list]
32
      *
32
      *
60
 
60
 
61
         $request = $this->fmtRequest($request);
61
         $request = $this->fmtRequest($request);
62
         $requestMap = $request['map'] ?: [];
62
         $requestMap = $request['map'] ?: [];
63
-        
63
+
64
         $sceneModel = new \app\admin\model\Scene();
64
         $sceneModel = new \app\admin\model\Scene();
65
         # getCount是代办事项传来的参数,代办事项不需要使用场景
65
         # getCount是代办事项传来的参数,代办事项不需要使用场景
66
         $sceneMap = [];
66
         $sceneMap = [];
97
         }
97
         }
98
         //高级筛选
98
         //高级筛选
99
         $map = advancedQuery($map, 'crm', 'receivables', 'index');
99
         $map = advancedQuery($map, 'crm', 'receivables', 'index');
100
-        
100
+
101
         //权限
101
         //权限
102
         $authMap = [];
102
         $authMap = [];
103
         if (!$partMap) {
103
         if (!$partMap) {
140
         $positionField = $fieldModel->getFieldByFormType('crm_receivables', 'position'); // 地址类型字段
140
         $positionField = $fieldModel->getFieldByFormType('crm_receivables', 'position'); // 地址类型字段
141
         $handwritingField = $fieldModel->getFieldByFormType('crm_receivables', 'handwriting_sign'); // 手写签名类型字段
141
         $handwritingField = $fieldModel->getFieldByFormType('crm_receivables', 'handwriting_sign'); // 手写签名类型字段
142
         $locationField = $fieldModel->getFieldByFormType('crm_receivables', 'location'); // 定位类型字段
142
         $locationField = $fieldModel->getFieldByFormType('crm_receivables', 'location'); // 定位类型字段
143
+        $boxField = $fieldModel->getFieldByFormType('crm_receivables', 'checkbox'); // 多选类型字段
144
+        $floatField = $fieldModel->getFieldByFormType('crm_receivables', 'floatnumber'); // 货币类型字段
145
+//        $fieldGrant = db('admin_field_mask')->where('types', 'receivables')->select();
143
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
146
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
144
         $temporaryField = str_replace('_name', '', $order_field);
147
         $temporaryField = str_replace('_name', '', $order_field);
145
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
148
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
151
         } else {
154
         } else {
152
             $order = 'receivables.update_time desc';
155
             $order = 'receivables.update_time desc';
153
         }
156
         }
154
-        
157
+
155
         # 待办事项查询参数
158
         # 待办事项查询参数
156
         $dealtWhere = [];
159
         $dealtWhere = [];
157
         if (!empty($receivablesIdArray)) $dealtWhere['receivables.receivables_id'] = ['in', $receivablesIdArray];
160
         if (!empty($receivablesIdArray)) $dealtWhere['receivables.receivables_id'] = ['in', $receivablesIdArray];
158
-        
161
+
159
         $readAuthIds = $userModel->getUserByPer('crm', 'receivables', 'read');
162
         $readAuthIds = $userModel->getUserByPer('crm', 'receivables', 'read');
160
         $updateAuthIds = $userModel->getUserByPer('crm', 'receivables', 'update');
163
         $updateAuthIds = $userModel->getUserByPer('crm', 'receivables', 'update');
161
         $deleteAuthIds = $userModel->getUserByPer('crm', 'receivables', 'delete');
164
         $deleteAuthIds = $userModel->getUserByPer('crm', 'receivables', 'delete');
192
         foreach ($extraList as $key => $value) {
195
         foreach ($extraList as $key => $value) {
193
             $extraData[$value['receivables_id']][$value['field']] = $value['content'];
196
             $extraData[$value['receivables_id']][$value['field']] = $value['content'];
194
         }
197
         }
198
+        $grantData = getFieldGrantData($user_id);
199
+        foreach ($grantData['crm_receivables'] as $key => $value) {
200
+            foreach ($value as $ke => $va) {
201
+                if($va['maskType']!=0){
202
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
203
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
204
+                    $fieldGrant[$ke]['field'] = $va['field'];
205
+                }
206
+            }
207
+        }
195
         foreach ($list as $k => $v) {
208
         foreach ($list as $k => $v) {
196
             $list[$k]['create_user_id_info'] = $v['create_user_id'] ? $userModel->getUserById($v['create_user_id']) : [];
209
             $list[$k]['create_user_id_info'] = $v['create_user_id'] ? $userModel->getUserById($v['create_user_id']) : [];
197
             $list[$k]['owner_user_id_info'] = $v['owner_user_id'] ? $userModel->getUserById($v['owner_user_id']) : [];
210
             $list[$k]['owner_user_id_info'] = $v['owner_user_id'] ? $userModel->getUserById($v['owner_user_id']) : [];
234
             foreach ($locationField AS $key => $val) {
247
             foreach ($locationField AS $key => $val) {
235
                 $list[$k][$val] = !empty($extraData[$v['receivables_id']][$val]) ? json_decode($extraData[$v['receivables_id']][$val], true) : null;
248
                 $list[$k][$val] = !empty($extraData[$v['receivables_id']][$val]) ? json_decode($extraData[$v['receivables_id']][$val], true) : null;
236
             }
249
             }
250
+            // 多选框类型字段
251
+            foreach ($boxField AS $key => $val) {
252
+                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val],',') : null;
253
+                }
254
+            // 货币类型字段
255
+            foreach ($floatField AS $key => $val) {
256
+                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
257
+            }
258
+            foreach ($fieldGrant AS $key => $val){
259
+                //掩码相关类型字段
260
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
261
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
262
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
263
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
264
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
265
+                    $email_array = explode("@", $v[$val['field']]);
266
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
267
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
268
+                    $rs = $prevfix . $str;
269
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
270
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
271
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
272
+                }
273
+            }
237
             $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
274
             $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
238
             //期数
275
             //期数
239
             $plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num');
276
             $plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num');
253
             # 日期
290
             # 日期
254
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
291
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
255
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
292
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
293
+            //掩码相关类型字段
294
+
295
+            # 系统字段  负责人部门   zjf  20210726
296
+            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
256
         }
297
         }
257
         $data = [];
298
         $data = [];
258
         $data['list'] = $list;
299
         $data['list'] = $list;
259
         $data['dataCount'] = $dataCount ?: 0;
300
         $data['dataCount'] = $dataCount ?: 0;
260
         $data['extraData']['money'] = ['receivablesMoney' => $this->getReceivablesMoney($map, $authMap)];
301
         $data['extraData']['money'] = ['receivablesMoney' => $this->getReceivablesMoney($map, $authMap)];
261
-        
302
+
262
         return $data;
303
         return $data;
263
     }
304
     }
264
-    
305
+
265
     /**
306
     /**
266
      * 获取回款总金额
307
      * 获取回款总金额
267
      *
308
      *
275
             ->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT')
316
             ->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT')
276
             ->join('__CRM_CONTRACT__ contract', 'receivables.contract_id = contract.contract_id', 'LEFT')
317
             ->join('__CRM_CONTRACT__ contract', 'receivables.contract_id = contract.contract_id', 'LEFT')
277
             ->where($map)->where($authMap)->where('receivables.check_status', 2)->sum('receivables.money');
318
             ->where($map)->where($authMap)->where('receivables.check_status', 2)->sum('receivables.money');
278
-        
319
+
279
         return !empty($money) ? sprintf("%.2f", $money) : 0.00;
320
         return !empty($money) ? sprintf("%.2f", $money) : 0.00;
280
     }
321
     }
281
-    
322
+
282
     /**
323
     /**
283
      * 创建回款信息
324
      * 创建回款信息
284
      * @param
325
      * @param
289
     {
330
     {
290
         // 回款扩展表数据
331
         // 回款扩展表数据
291
         $receivablesData = [];
332
         $receivablesData = [];
292
-        
333
+
293
         if (!$param['customer_id']) {
334
         if (!$param['customer_id']) {
294
             $this->error = '请先选择客户';
335
             $this->error = '请先选择客户';
295
             return false;
336
             return false;
300
             if ($check_status == 6) {
341
             if ($check_status == 6) {
301
                 $this->error = '合同已作废';
342
                 $this->error = '合同已作废';
302
                 return false;
343
                 return false;
303
-            } elseif ($check_status != 2) {
344
+            } elseif ($check_status != 2 && $check_status != 7) {
304
                 $this->error = '合同未审核通过';
345
                 $this->error = '合同未审核通过';
305
                 return false;
346
                 return false;
306
             }
347
             }
308
             $this->error = '请先选择合同';
349
             $this->error = '请先选择合同';
309
             return false;
350
             return false;
310
         }
351
         }
311
-        
352
+
312
         $fieldModel = new \app\admin\model\Field();
353
         $fieldModel = new \app\admin\model\Field();
313
-        
354
+
314
         // 数据验证
355
         // 数据验证
315
         $validateResult = $this->fieldDataValidate($param, $this->name, $param['create_user_id']);
356
         $validateResult = $this->fieldDataValidate($param, $this->name, $param['create_user_id']);
316
         if (!empty($validateResult)) {
357
         if (!empty($validateResult)) {
317
             $this->error = $validateResult;
358
             $this->error = $validateResult;
318
             return false;
359
             return false;
319
         }
360
         }
320
-        
361
+
321
         # 验证回款计划是否已经被关联
362
         # 验证回款计划是否已经被关联
322
         if (!empty($param['plan_id']) && db('crm_receivables_plan')->where('plan_id', $param['plan_id'])->value('receivables_id')) {
363
         if (!empty($param['plan_id']) && db('crm_receivables_plan')->where('plan_id', $param['plan_id'])->value('receivables_id')) {
323
             $this->error = '回款已经已经关联了其他回款,不能重复关联!';
364
             $this->error = '回款已经已经关联了其他回款,不能重复关联!';
324
             return false;
365
             return false;
325
         }
366
         }
326
-        
367
+
327
         // 处理部门、员工、附件、多选类型字段
368
         // 处理部门、员工、附件、多选类型字段
328
         $arrFieldAtt = $fieldModel->getArrayField('crm_receivables');
369
         $arrFieldAtt = $fieldModel->getArrayField('crm_receivables');
329
         foreach ($arrFieldAtt as $k => $v) {
370
         foreach ($arrFieldAtt as $k => $v) {
405
                 }
446
                 }
406
             }
447
             }
407
         }
448
         }
408
-        
449
+
409
         if ($this->data($param)->allowField(true)->save()) {
450
         if ($this->data($param)->allowField(true)->save()) {
410
             //站内信
451
             //站内信
411
             $send_user_id = stringToArray($param['check_user_id']);
452
             $send_user_id = stringToArray($param['check_user_id']);
421
             }
462
             }
422
             $data = [];
463
             $data = [];
423
             $data['receivables_id'] = $this->receivables_id;
464
             $data['receivables_id'] = $this->receivables_id;
424
-            
465
+
425
             //修改记录
466
             //修改记录
426
             updateActionLog($param['create_user_id'], 'crm_receivables', $this->receivables_id, '', '', '创建了回款');
467
             updateActionLog($param['create_user_id'], 'crm_receivables', $this->receivables_id, '', '', '创建了回款');
427
             RecordActionLog($param['create_user_id'], 'crm_receivables', 'save', $param['number'], '', '', '新增了回款' . $param['number']);
468
             RecordActionLog($param['create_user_id'], 'crm_receivables', 'save', $param['number'], '', '', '新增了回款' . $param['number']);
428
-            
469
+
429
             # 添加活动记录
470
             # 添加活动记录
430
             Db::name('crm_activity')->insert([
471
             Db::name('crm_activity')->insert([
431
                 'type' => 2,
472
                 'type' => 2,
438
                 'customer_ids' => ',' . $param['customer_id'] . ',',
479
                 'customer_ids' => ',' . $param['customer_id'] . ',',
439
                 'contract_ids' => ',' . $param['contract_id'] . ','
480
                 'contract_ids' => ',' . $param['contract_id'] . ','
440
             ]);
481
             ]);
441
-            
482
+
442
             # 创建待办事项的关联数据
483
             # 创建待办事项的关联数据
443
             $checkUserIds = db('crm_receivables')->where('receivables_id', $data['receivables_id'])->value('check_user_id');
484
             $checkUserIds = db('crm_receivables')->where('receivables_id', $data['receivables_id'])->value('check_user_id');
444
             $checkUserIdArray = stringToArray($checkUserIds);
485
             $checkUserIdArray = stringToArray($checkUserIds);
451
                 ];
492
                 ];
452
             }
493
             }
453
             if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
494
             if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
454
-            
495
+
455
             // 添加回款扩展数据
496
             // 添加回款扩展数据
456
             array_walk($receivablesData, function (&$val) use ($data) {
497
             array_walk($receivablesData, function (&$val) use ($data) {
457
                 $val['receivables_id'] = $data['receivables_id'];
498
                 $val['receivables_id'] = $data['receivables_id'];
458
             });
499
             });
459
             db('crm_receivables_data')->insertAll($receivablesData);
500
             db('crm_receivables_data')->insertAll($receivablesData);
460
-            
501
+
461
             return $data;
502
             return $data;
462
         } else {
503
         } else {
463
             $this->error = '添加失败';
504
             $this->error = '添加失败';
464
             return false;
505
             return false;
465
         }
506
         }
466
     }
507
     }
467
-    
508
+
468
     /**
509
     /**
469
      * 根据对象ID 获取该年各个月回款情况
510
      * 根据对象ID 获取该年各个月回款情况
470
      * @param [year] [哪一年]
511
      * @param [year] [哪一年]
490
         $data = $this->where($map)->where(['return_time' => ['between', [$start, $stop]]])->sum('money');
531
         $data = $this->where($map)->where(['return_time' => ['between', [$start, $stop]]])->sum('money');
491
         return $data;
532
         return $data;
492
     }
533
     }
493
-    
534
+
494
     /**
535
     /**
495
      * 编辑回款主表信息
536
      * 编辑回款主表信息
496
      * @param
537
      * @param
501
     {
542
     {
502
         // 回款扩展表数据
543
         // 回款扩展表数据
503
         $receivablesData = [];
544
         $receivablesData = [];
504
-        
545
+
505
         $userModel = new \app\admin\model\User();
546
         $userModel = new \app\admin\model\User();
506
         $dataInfo = db('crm_receivables')->where(['receivables_id' => $receivables_id])->find();
547
         $dataInfo = db('crm_receivables')->where(['receivables_id' => $receivables_id])->find();
507
         if (!$dataInfo) {
548
         if (!$dataInfo) {
514
         foreach ($unUpdateField as $v) {
555
         foreach ($unUpdateField as $v) {
515
             unset($param[$v]);
556
             unset($param[$v]);
516
         }
557
         }
517
-        
558
+
518
         $fieldModel = new \app\admin\model\Field();
559
         $fieldModel = new \app\admin\model\Field();
519
-        
560
+
520
         // 数据验证
561
         // 数据验证
521
         $validateResult = $this->fieldDataValidate($param, $this->name, $param['user_id'], $param['receivables_id']);
562
         $validateResult = $this->fieldDataValidate($param, $this->name, $param['user_id'], $param['receivables_id']);
522
         if (!empty($validateResult)) {
563
         if (!empty($validateResult)) {
523
             $this->error = $validateResult;
564
             $this->error = $validateResult;
524
             return false;
565
             return false;
525
         }
566
         }
526
-        
567
+
527
         // 处理部门、员工、附件、多选类型字段
568
         // 处理部门、员工、附件、多选类型字段
528
         $arrFieldAtt = $fieldModel->getArrayField('crm_receivables');
569
         $arrFieldAtt = $fieldModel->getArrayField('crm_receivables');
529
         foreach ($arrFieldAtt as $k => $v) {
570
         foreach ($arrFieldAtt as $k => $v) {
605
                 }
646
                 }
606
             }
647
             }
607
         }
648
         }
608
-        
649
+
609
         if ($this->update($param, ['receivables_id' => $receivables_id], true)) {
650
         if ($this->update($param, ['receivables_id' => $receivables_id], true)) {
610
             //修改记录
651
             //修改记录
611
             updateActionLog($param['user_id'], 'crm_receivables', $receivables_id, $dataInfo, $param);
652
             updateActionLog($param['user_id'], 'crm_receivables', $receivables_id, $dataInfo, $param);
622
                     $send_user_id
663
                     $send_user_id
623
                 );
664
                 );
624
             }
665
             }
625
-            
666
+
626
             $data = [];
667
             $data = [];
627
             $data['receivables_id'] = $receivables_id;
668
             $data['receivables_id'] = $receivables_id;
628
-            
669
+
629
             # 删除待办事项的关联数据
670
             # 删除待办事项的关联数据
630
             db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'types_id' => ['eq', $data['receivables_id']]])->delete();
671
             db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'types_id' => ['eq', $data['receivables_id']]])->delete();
631
             # 创建待办事项的关联数据
672
             # 创建待办事项的关联数据
640
                 ];
681
                 ];
641
             }
682
             }
642
             if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
683
             if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
643
-            
684
+
644
             // 添加回款扩展数据
685
             // 添加回款扩展数据
645
             db('crm_receivables_data')->where('receivables_id', $receivables_id)->delete();
686
             db('crm_receivables_data')->where('receivables_id', $receivables_id)->delete();
646
             array_walk($receivablesData, function (&$val) use ($receivables_id) {
687
             array_walk($receivablesData, function (&$val) use ($receivables_id) {
647
                 $val['receivables_id'] = $receivables_id;
688
                 $val['receivables_id'] = $receivables_id;
648
             });
689
             });
649
             db('crm_receivables_data')->insertAll($receivablesData);
690
             db('crm_receivables_data')->insertAll($receivablesData);
650
-            
691
+
651
             return $data;
692
             return $data;
652
         } else {
693
         } else {
653
             $this->error = '编辑失败';
694
             $this->error = '编辑失败';
654
             return false;
695
             return false;
655
         }
696
         }
656
     }
697
     }
657
-    
698
+
658
     /**
699
     /**
659
      * 回款数据
700
      * 回款数据
660
      *
701
      *
664
      * @throws \think\db\exception\ModelNotFoundException
705
      * @throws \think\db\exception\ModelNotFoundException
665
      * @throws \think\exception\DbException
706
      * @throws \think\exception\DbException
666
      */
707
      */
667
-    public function getDataById($id = '', $userId = 0)
708
+    public function getDataById($id = '', $userId = 0,$model='')
668
     {
709
     {
669
         $map['receivables_id'] = $id;
710
         $map['receivables_id'] = $id;
670
         $dataInfo = db('crm_receivables')->where($map)->find();
711
         $dataInfo = db('crm_receivables')->where($map)->find();
672
             $this->error = '暂无此数据';
713
             $this->error = '暂无此数据';
673
             return false;
714
             return false;
674
         }
715
         }
716
+        if(empty($model) && $model!='update'){
717
+            $grantData = getFieldGrantData($userId);
718
+            foreach ($grantData['crm_receivables'] as $key => $value) {
719
+                foreach ($value as $ke => $va) {
720
+                    if($va['maskType']!=0){
721
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
722
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
723
+                        $fieldGrant[$ke]['field'] = $va['field'];
724
+                    }
725
+                }
726
+            }
727
+            foreach ($fieldGrant AS $key => $val){
728
+                //掩码相关类型字段
729
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
730
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
731
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
732
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
733
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
734
+                    $email_array = explode("@", $dataInfo[$val['field']]);
735
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
736
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
737
+                    $rs = $prevfix . $str;
738
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
739
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
740
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
741
+                }
742
+            }
743
+        }
744
+
675
         $userModel = new \app\admin\model\User();
745
         $userModel = new \app\admin\model\User();
676
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
746
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
677
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
747
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
695
             foreach ($dataInfo as $key => $value) {
765
             foreach ($dataInfo as $key => $value) {
696
                 if (!$userLevel && !empty($grantData['crm_receivables'])) {
766
                 if (!$userLevel && !empty($grantData['crm_receivables'])) {
697
                     $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
767
                     $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
698
-                    
768
+
699
                     # 查看权限
769
                     # 查看权限
700
                     if ($status['read'] == 0) unset($dataInfo[$key]);
770
                     if ($status['read'] == 0) unset($dataInfo[$key]);
701
                 }
771
                 }
717
         }
787
         }
718
         return $dataInfo;
788
         return $dataInfo;
719
     }
789
     }
720
-    
790
+
721
     /**
791
     /**
722
      * 回款&&合同统计(列表)
792
      * 回款&&合同统计(列表)
723
      * @param
793
      * @param
733
         $perUserIds = $userModel->getUserByPer('bi', 'receivables', 'read'); //权限范围内userIds
803
         $perUserIds = $userModel->getUserByPer('bi', 'receivables', 'read'); //权限范围内userIds
734
         $whereData = $adminModel->getWhere($request, '', $perUserIds); //统计条件
804
         $whereData = $adminModel->getWhere($request, '', $perUserIds); //统计条件
735
         $userIds = $whereData['userIds'];
805
         $userIds = $whereData['userIds'];
736
-        
806
+
737
         if (!$request['year']) {
807
         if (!$request['year']) {
738
             $request['year'] = date('Y');
808
             $request['year'] = date('Y');
739
         }
809
         }
751
             $start = strtotime($request['year'] . '-01-01');
821
             $start = strtotime($request['year'] . '-01-01');
752
             $end = strtotime($next_year . '-01-01');
822
             $end = strtotime($next_year . '-01-01');
753
         }
823
         }
754
-        
824
+
755
         $map['owner_user_id'] = ['in', $userIds];
825
         $map['owner_user_id'] = ['in', $userIds];
756
         //$map['rec.check_status'] = 3;
826
         //$map['rec.check_status'] = 3;
757
         $map['create_time'] = array('between', array($start, $end));
827
         $map['create_time'] = array('between', array($start, $end));
760
         if ($request['type'] == '1') {
830
         if ($request['type'] == '1') {
761
             $map_type['contract.owner_user_id'] = ['in', $userIds];
831
             $map_type['contract.owner_user_id'] = ['in', $userIds];
762
             $map_type['contract.create_time'] = array('between', array($start, $end));
832
             $map_type['contract.create_time'] = array('between', array($start, $end));
763
-            
833
+
764
             $userField = $fieldModel->getFieldByFormType('crm_contract', 'user');
834
             $userField = $fieldModel->getFieldByFormType('crm_contract', 'user');
765
             $structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure');  //部门类型
835
             $structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure');  //部门类型
766
-            
836
+
767
             $list = Db::name('CrmContract')->alias('contract')
837
             $list = Db::name('CrmContract')->alias('contract')
768
                 ->join('__CRM_CUSTOMER__ customer', 'contract.customer_id = customer.customer_id', 'LEFT')
838
                 ->join('__CRM_CUSTOMER__ customer', 'contract.customer_id = customer.customer_id', 'LEFT')
769
                 ->join('__CRM_BUSINESS__ business', 'contract.contract_id = business.business_id', 'LEFT')
839
                 ->join('__CRM_BUSINESS__ business', 'contract.contract_id = business.business_id', 'LEFT')
797
             //$map['rec.check_status'] = 3;
867
             //$map['rec.check_status'] = 3;
798
             $map_rec['receivables.create_time'] = array('between', array($start, $end));
868
             $map_rec['receivables.create_time'] = array('between', array($start, $end));
799
             $map_rec['receivables.check_status'] = 2;
869
             $map_rec['receivables.check_status'] = 2;
800
-            
870
+
801
             $userField = $fieldModel->getFieldByFormType('crm_receivables', 'user');
871
             $userField = $fieldModel->getFieldByFormType('crm_receivables', 'user');
802
             $structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure');  //部门类型
872
             $structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure');  //部门类型
803
-            
873
+
804
             $list = db('crm_receivables')
874
             $list = db('crm_receivables')
805
                 ->alias('receivables')
875
                 ->alias('receivables')
806
                 ->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT')
876
                 ->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT')
828
             return $list;
898
             return $list;
829
         }
899
         }
830
     }
900
     }
831
-    
901
+
832
     /**
902
     /**
833
      * [回款统计] 柱状图
903
      * [回款统计] 柱状图
834
      * @param request [查询条件]
904
      * @param request [查询条件]
868
             $where_receivables['check_status'] = $where_contract['check_status'] = 2; //审核通过
938
             $where_receivables['check_status'] = $where_contract['check_status'] = 2; //审核通过
869
             $contractMoney = db('crm_contract')->where($where_contract)->sum('money');
939
             $contractMoney = db('crm_contract')->where($where_contract)->sum('money');
870
             $receivablesMoney = db('crm_receivables')->where($where_receivables)->sum('money');
940
             $receivablesMoney = db('crm_receivables')->where($where_receivables)->sum('money');
871
-            
941
+
872
             $conQuarterMoney += $charMonthArr[$i]['contractMoney'] = $contractMoney;
942
             $conQuarterMoney += $charMonthArr[$i]['contractMoney'] = $contractMoney;
873
             $reQuarterMoney += $charMonthArr[$i]['receivablesMoney'] = $receivablesMoney;
943
             $reQuarterMoney += $charMonthArr[$i]['receivablesMoney'] = $receivablesMoney;
874
             if (in_array($i, array('3', '4', '6', '9', '12'))) {
944
             if (in_array($i, array('3', '4', '6', '9', '12'))) {
888
         $data['receivablesMoneyTotal'] = $receivablesMoneyTotal ?: 0.00;
958
         $data['receivablesMoneyTotal'] = $receivablesMoneyTotal ?: 0.00;
889
         return $data;
959
         return $data;
890
     }
960
     }
891
-    
961
+
892
     /**
962
     /**
893
      * [合同回款金额]
963
      * [合同回款金额]
894
      * @param contract_id 合同ID
964
      * @param contract_id 合同ID
906
         $data['contractMoney'] = $contractMoney ?: '0.00';
976
         $data['contractMoney'] = $contractMoney ?: '0.00';
907
         return $data;
977
         return $data;
908
     }
978
     }
909
-    
979
+
910
     /**
980
     /**
911
      * 获取系统信息
981
      * 获取系统信息
912
      *
982
      *
919
     public function getSystemInfo($id)
989
     public function getSystemInfo($id)
920
     {
990
     {
921
         # 回款
991
         # 回款
922
-        $receivables = Db::name('crm_receivables')->field(['create_user_id', 'create_time', 'update_time'])->where('receivables_id', $id)->find();
992
+        $receivables = Db::name('crm_receivables')->field(['create_user_id' ,'owner_user_id', 'create_time', 'update_time'])->where('receivables_id', $id)->find();
923
         # 创建人
993
         # 创建人
924
         $realname = Db::name('admin_user')->where('id', $receivables['create_user_id'])->value('realname');
994
         $realname = Db::name('admin_user')->where('id', $receivables['create_user_id'])->value('realname');
925
-        
995
+
996
+        # zjf   20210726
997
+        $userModel   = new \app\admin\model\User();
998
+        $ownerUserInfo = $userModel->getUserById($receivables['owner_user_id']);
999
+        # 负责人部门
1000
+        $ownerStructureName = $ownerUserInfo['structure_name'];
1001
+        # 负责人
1002
+        $ownerUserName = $ownerUserInfo['realname'];
926
         return [
1003
         return [
927
             'create_user_id' => $realname,
1004
             'create_user_id' => $realname,
1005
+            'owner_user_id' => $ownerUserName,
928
             'create_time' => date('Y-m-d H:i:s', $receivables['create_time']),
1006
             'create_time' => date('Y-m-d H:i:s', $receivables['create_time']),
929
-            'update_time' => date('Y-m-d H:i:s', $receivables['update_time'])
1007
+            'update_time' => date('Y-m-d H:i:s', $receivables['update_time']),
1008
+            'owner_user_structure_name' => $ownerStructureName
930
         ];
1009
         ];
931
     }
1010
     }
932
 }
1011
 }

+ 323
- 145
application/crm/model/ReceivablesPlan.php Просмотреть файл

7
 namespace app\crm\model;
7
 namespace app\crm\model;
8
 
8
 
9
 use app\admin\traits\FieldVerificationTrait;
9
 use app\admin\traits\FieldVerificationTrait;
10
+use think\composer\LibraryInstaller;
10
 use think\Db;
11
 use think\Db;
11
 use app\admin\model\Common;
12
 use app\admin\model\Common;
12
 use app\crm\model\Contract as ContractModel;
13
 use app\crm\model\Contract as ContractModel;
15
 
16
 
16
 class ReceivablesPlan extends Common
17
 class ReceivablesPlan extends Common
17
 {
18
 {
18
-    use FieldVerificationTrait;
19
-
20
 	/**
19
 	/**
21
      * 为了数据库的整洁,同时又不影响Model和Controller的名称
20
      * 为了数据库的整洁,同时又不影响Model和Controller的名称
22
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
21
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
23
      */
22
      */
24
-	protected $name = 'crm_receivables_plan';
23
+    protected $name = 'crm_receivables_plan';
25
     protected $createTime = 'create_time';
24
     protected $createTime = 'create_time';
26
     protected $updateTime = 'update_time';
25
     protected $updateTime = 'update_time';
27
-	protected $autoWriteTimestamp = true;
28
-
29
-	/**
26
+    protected $autoWriteTimestamp = true;
27
+    protected $statusArr = [0 =>'待回款', 1=>'完成', 2=>'部分回款', 3=>'已作废', 4=>'已逾期', 5=>'待生效'];
28
+    
29
+    /**
30
      * [getDataList 回款计划list]
30
      * [getDataList 回款计划list]
31
-     * @author Michael_xu
32
      * @param     [string]                   $map [查询条件]
31
      * @param     [string]                   $map [查询条件]
33
      * @param     [number]                   $page     [当前页数]
32
      * @param     [number]                   $page     [当前页数]
34
      * @param     [number]                   $limit    [每页数量]
33
      * @param     [number]                   $limit    [每页数量]
35
      * @param     [string]                   $types    1 未使用的回款计划
34
      * @param     [string]                   $types    1 未使用的回款计划
36
      * @return    [array]                    [description]
35
      * @return    [array]                    [description]
37
-     */		
38
-	public function getDataList($request)
36
+     * @author Michael_xu
37
+     */
38
+    public function getDataList($request)
39
     {
39
     {
40
-    	$userModel = new \app\admin\model\User();
41
-		$search = $request['search'];
42
-    	$user_id = $request['user_id'];
43
-    	$scene_id = (int)$request['scene_id'];
44
-    	$check_status = $request['check_status'];
45
-    	$types = $request['types'];
40
+        $userModel = new \app\admin\model\User();
41
+        $fieldModel = new \app\admin\model\Field();
42
+        $search = $request['search'];
43
+        $user_id = $request['user_id'];
44
+        $scene_id = (int)$request['scene_id'];
45
+        $check_status = $request['check_status'];
46
+        $types = $request['types'];
46
         $getCount = $request['getCount'];
47
         $getCount = $request['getCount'];
47
         $status = isset($request['status']) ? $request['status'] : 1;
48
         $status = isset($request['status']) ? $request['status'] : 1;
48
         $dealt = $request['dealt']; # 待办事项
49
         $dealt = $request['dealt']; # 待办事项
49
-		unset($request['scene_id']);
50
-		unset($request['search']);
51
-		unset($request['user_id']);	    	
52
-		unset($request['check_status']);	    	
53
-		unset($request['types']);
50
+        $order_field = $request['order_field'];
51
+        $order_type = $request['order_type'];
52
+        $is_excel = $request['is_excel'];
53
+        unset($request['scene_id']);
54
+        unset($request['search']);
55
+        unset($request['user_id']);
56
+        unset($request['check_status']);
57
+        unset($request['types']);
54
         unset($request['getCount']);
58
         unset($request['getCount']);
55
         unset($request['status']);
59
         unset($request['status']);
56
         unset($request['dealt']);
60
         unset($request['dealt']);
57
-
58
-        $request = $this->fmtRequest( $request );
59
-        $map = $request['map'] ? : [];
61
+        unset($request['order_field']);
62
+        unset($request['order_type']);
63
+        unset($request['is_excel']);
64
+        
65
+        $request = $this->fmtRequest($request);
66
+        $map = $request['map'] ?: [];
67
+        $sceneModel = new \app\admin\model\Scene();
68
+        $sceneMap = [];
69
+        if (empty($getCount)) {
70
+            if ($scene_id) {
71
+                //自定义场景
72
+                $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'receivables_plan') ?: [];
73
+            } else {
74
+                //默认场景
75
+                $sceneMap = $sceneModel->getDefaultData('crm_receivables_plan', $user_id) ?: [];
76
+            }
77
+        }
60
         if (isset($map['search'])) {
78
         if (isset($map['search'])) {
61
-			//普通筛选
62
-			$map['name'] = ['like', '%'.$map['search'].'%'];
63
-			unset($map['search']);
64
-		} else {
79
+            
80
+            //普通筛选
81
+            $map['name'] = ['like', '%' . $map['search'] . '%'];
82
+            unset($map['search']);
83
+        } else {
65
             // 高级筛选
84
             // 高级筛选
66
-			$map = advancedQuery($map, 'crm', 'receivables_plan', 'index');
67
-		}
68
-		if ($map['receivables_plan.owner_user_id']) {
69
-			$map['contract.owner_user_id'] = $map['receivables_plan.owner_user_id'];
70
-			unset($map['receivables_plan.owner_user_id']);
71
-		}
72
-		$whereData = [];
73
-		if ($check_status) {
74
-			unset($map['receivables_plan.check_status']);
75
-			if ($check_status == 2) {
76
-				$map['receivables.check_status'] = $check_status;
77
-			} else {
78
-				unset($map['receivables_plan.receivables_id']);
79
-				$data = [];
80
-				$data['check_status'] = $check_status;
81
-				$whereData = function($query) use ($data){
82
-					        	$query->where(['receivables_plan.receivables_id'=> ['eq',0]])
83
-						        	->whereOr(['receivables.check_status' => $data['check_status']]);					
84
-								};
85
-			}
86
-		}
87
-		// @ymob 2019-12-11 17:51:54
88
-		// 修改回款时,回款计划选项列表应该包含该回款对应的回款计划 不能过滤
89
-		// 将types改为status,status:可用的回款计划 fanqi
85
+            $map = advancedQuery($map, 'crm', 'receivables_plan', 'index');
86
+        }
87
+        if ($map['receivables_plan.owner_user_id']) {
88
+            $map['contract.owner_user_id'] = $map['receivables_plan.owner_user_id'];
89
+            unset($map['receivables_plan.owner_user_id']);
90
+        }
91
+        $whereData = [];
92
+        if ($check_status) {
93
+            unset($map['receivables_plan.check_status']);
94
+            if ($check_status == 2) {
95
+                $map['receivables.check_status'] = $check_status;
96
+            } else {
97
+                unset($map['receivables_plan.receivables_id']);
98
+                $data = [];
99
+                $data['check_status'] = $check_status;
100
+                $whereData = function ($query) use ($data) {
101
+                    $query->where(['receivables_plan.receivables_id' => ['eq', 0]])
102
+                        ->whereOr(['receivables.check_status' => $data['check_status']]);
103
+                };
104
+            }
105
+        }
106
+        // @ymob 2019-12-11 17:51:54
107
+        // 修改回款时,回款计划选项列表应该包含该回款对应的回款计划 不能过滤
108
+        // 将types改为status,status:可用的回款计划 fanqi
90
         if (empty($dealt)) { # 不是待办事项
109
         if (empty($dealt)) { # 不是待办事项
91
             if ($request['map']['receivables_id']) {
110
             if ($request['map']['receivables_id']) {
92
                 if (!empty($request['map']['contract_id'])) {
111
                 if (!empty($request['map']['contract_id'])) {
102
                 $map['receivables_plan.receivables_id'] = 0;
121
                 $map['receivables_plan.receivables_id'] = 0;
103
             }
122
             }
104
         }
123
         }
105
-
124
+        
125
+        
106
         $dataCount = db('crm_receivables_plan')
126
         $dataCount = db('crm_receivables_plan')
107
             ->alias('receivables_plan')
127
             ->alias('receivables_plan')
108
-            ->join('__CRM_CONTRACT__ contract','receivables_plan.contract_id = contract.contract_id','LEFT')
109
-            ->join('__CRM_CUSTOMER__ customer','receivables_plan.customer_id = customer.customer_id','LEFT')
110
-            ->join('__CRM_RECEIVABLES__ receivables','receivables_plan.plan_id = receivables.plan_id','LEFT')
128
+            ->join('__CRM_CONTRACT__ contract', 'receivables_plan.contract_id = contract.contract_id', 'LEFT')
129
+            ->join('__CRM_CUSTOMER__ customer', 'receivables_plan.customer_id = customer.customer_id', 'LEFT')
130
+            ->join('__CRM_RECEIVABLES__ receivables', 'receivables_plan.plan_id = receivables.plan_id', 'LEFT')
111
             ->where($map)
131
             ->where($map)
132
+            ->where($sceneMap)
112
             ->where($whereData)
133
             ->where($whereData)
113
             ->count('receivables_plan.plan_id');
134
             ->count('receivables_plan.plan_id');
135
+        
136
+        $indexField = $fieldModel->getIndexField('crm_receivables_plan', $user_id, 1) ?: array('name'); // 列表展示字段
137
+        $userField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'user'); // 人员类型
138
+        $structureField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'structure'); // 部门类型
139
+        $datetimeField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'datetime'); // 日期时间类型
140
+        $booleanField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'boolean_value'); // 布尔值类型字段
141
+        $dateIntervalField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'date_interval'); // 日期区间类型字段
142
+        $positionField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'position'); // 地址类型字段
143
+        $handwritingField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'handwriting_sign'); // 手写签名类型字段
114
         if (!empty($getCount) && $getCount == 1) {
144
         if (!empty($getCount) && $getCount == 1) {
115
             $data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
145
             $data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
116
             return $data;
146
             return $data;
117
         }
147
         }
118
-		$list = db('crm_receivables_plan')
119
-				->alias('receivables_plan')
120
-				->join('__CRM_CONTRACT__ contract','receivables_plan.contract_id = contract.contract_id','LEFT')
121
-				->join('__CRM_CUSTOMER__ customer','receivables_plan.customer_id = customer.customer_id','LEFT')
122
-				->join('__CRM_RECEIVABLES__ receivables','receivables_plan.plan_id = receivables.plan_id','LEFT')
123
-        		->limit($request['offset'], $request['length'])
124
-				->field('receivables_plan.*,customer.name as customer_name,contract.num as contract_name,receivables.receivables_id,receivables.check_status')
125
-				->where($map)
126
-				->where($whereData)				
127
-				->select();
128
-        foreach ($list as $k=>$v) {
129
-        	$list[$k]['create_user_id_info'] = $userModel->getUserById($v['create_user_id']);
130
-        	$list[$k]['contract_id_info']['name'] = $v['contract_name'] ? : '';
131
-        	$list[$k]['contract_id_info']['contract_id'] = $v['contract_id'] ? : '';
132
-			$list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : '';
133
-        	$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ? : '';	
148
+        # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
149
+        $temporaryField = str_replace('_name', '', $order_field);
150
+        if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
151
+            $order_field = $temporaryField;
152
+        }
153
+        # 排序
154
+        if ($order_type && $order_field) {
155
+            $order = $fieldModel->getOrderByFormtype('crm_receivables_plan', 'receivables_plan', $order_field, $order_type);
156
+        } else {
157
+            $order = 'receivables_plan.num asc';
158
+        }
159
+        $list = db('crm_receivables_plan')
160
+            ->alias('receivables_plan')
161
+            ->join('__CRM_CONTRACT__ contract', 'receivables_plan.contract_id = contract.contract_id', 'LEFT')
162
+            ->join('__CRM_CUSTOMER__ customer', 'receivables_plan.customer_id = customer.customer_id', 'LEFT')
163
+            ->join('__CRM_RECEIVABLES__ receivables', 'receivables_plan.plan_id = receivables.plan_id', 'LEFT')
164
+            ->limit($request['offset'], $request['length'])
165
+            ->field(array_merge($indexField, [
166
+                'customer.name' => 'customer_name',
167
+                'receivables.receivables_id' => 'receivables_id',
168
+                'receivables.check_status' => 'check_status',
169
+                'contract.num ' => 'contract_name',
170
+                'ifnull(SUM(receivables_plan.money), 0)' => 'done_money',//计划回款总金额
171
+                '(ifnull(SUM(receivables.money), 0)-SUM( real_money))' => 'un_money',//未回款总金额
172
+                'SUM(real_money) AS real_money'//实际回款总金额
173
+            ]))
174
+            ->where($map)
175
+            ->where($sceneMap)
176
+            ->where($whereData)
177
+            ->group('receivables_plan.contract_id')
178
+            ->orderRaw($order)
179
+            ->select();
180
+        $grantData = getFieldGrantData($user_id);
181
+        foreach ($grantData['crm_visit_'] as $key => $value) {
182
+            foreach ($value as $ke => $va) {
183
+                if($va['maskType']!=0){
184
+                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
185
+                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
186
+                    $fieldGrant[$ke]['field'] = $va['field'];
187
+                }
188
+            }
189
+        }
190
+        $readAuthIds = $userModel->getUserByPer('crm', 'receivables_plan', 'read');
191
+        $updateAuthIds = $userModel->getUserByPer('crm', 'receivables_plan', 'update');
192
+        $deleteAuthIds = $userModel->getUserByPer('crm', 'receivables_plan', 'delete');
193
+        $real_money=0.00;
194
+        $receivedMoney=0.00;
195
+        $unReceivedMoney=0.00;
196
+        foreach ($list as $k => $v) {
197
+            $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
198
+            $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
199
+            $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
200
+            $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
201
+            foreach ($userField as $key => $val) {
202
+                if (in_array($val, $indexField)) {
203
+                    $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
204
+                    $list[$k][$val] = implode($usernameField, ',');
205
+                }
206
+            }
207
+            # 部门类型字段
208
+            foreach ($structureField as $key => $val) {
209
+                if (in_array($val, $indexField)) {
210
+                    $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
211
+                    $list[$k][$val] = implode($structureNameField, ',');
212
+                }
213
+            }
214
+            # 日期时间类型字段
215
+            foreach ($datetimeField as $key => $val) {
216
+                $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
217
+            }
218
+            // 布尔值类型字段
219
+            foreach ($booleanField as $key => $val) {
220
+                $list[$k][$val] = !empty($v[$val]) ? (string)$v[$val] : '0';
221
+            }
222
+            // 处理日期区间类型字段的格式
223
+            foreach ($dateIntervalField as $key => $val) {
224
+                $list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
225
+            }
226
+            // 处理地址类型字段的格式
227
+            foreach ($positionField as $key => $val) {
228
+                $list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
229
+            }
230
+            // 手写签名类型字段
231
+            foreach ($handwritingField as $key => $val) {
232
+                $handwritingData = !empty($v[$val]) ? db('admin_file')->where('file_id', $v[$val])->value('file_path') : null;
233
+                $list[$k][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null
234
+                ];
235
+            }
236
+            foreach ($fieldGrant AS $key => $val){
237
+                //掩码相关类型字段
238
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
239
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
240
+                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
241
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
242
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
243
+                    $email_array = explode("@", $v[$val['field']]);
244
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
245
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
246
+                    $rs = $prevfix . $str;
247
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
248
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
249
+                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
250
+                }
251
+            }
252
+            // 状态
253
+            if(strtotime($v['return_date'])>strtotime(date("Y-m-d",strtotime("+1 day")))){
254
+                $list[$k]['status']=4;
255
+            }
256
+            # 时间格式
257
+            $list[$k]['create_time']=!empty($v['create_time'])?date('Y-m-d H:i:s',$v['create_time']):null;
258
+            $list[$k]['update_time']=!empty($v['update_time'])?date('Y-m-d H:i:s',$v['update_time']):null;
259
+            # 权限
260
+            $roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read');
261
+            $rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update');
262
+            $permission = [];
263
+            $is_read = 0;
264
+            $is_update = 0;
265
+            $is_delete = 0;
266
+            if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1;
267
+            if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
268
+            if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
269
+            $permission['is_read'] = $is_read;
270
+            $permission['is_update'] = $is_update;
271
+            $permission['is_delete'] = $is_delete;
272
+            $list[$k]['permission'] = $permission;
273
+            $real_money += $v['real_money'];   //实际回款总金额
274
+            $receivedMoney += $v['done_money'];// 回款总金额
275
+            $unReceivedMoney += $v['un_money'];      // 未回款
134
         }
276
         }
277
+        
135
         $data = [];
278
         $data = [];
136
         $data['list'] = $list;
279
         $data['list'] = $list;
137
-        $data['dataCount'] = $dataCount ? : 0;
138
-        return $data ? : [];
280
+        $data['dataCount'] = $dataCount ?: 0;
281
+        $data['extraData']['money'] = [
282
+            'real_money' => $real_money,    # 实际回款总金额
283
+            'receivedMoney' => $receivedMoney, # 回款总金额
284
+            'unReceivedMoney' => $unReceivedMoney      # 未回款
285
+        ];
286
+        return $data ?: [];
139
     }
287
     }
288
+    
140
 
289
 
141
 	/**
290
 	/**
142
 	 * 创建回款计划信息
291
 	 * 创建回款计划信息
143
 	 * @author Michael_xu
292
 	 * @author Michael_xu
144
 	 * @param  
293
 	 * @param  
145
 	 * @return                            
294
 	 * @return                            
146
-	 */	
295
+	 */
147
 	public function createData($param)
296
 	public function createData($param)
148
 	{
297
 	{
149
 	    $userId = $param['user_id'];
298
 	    $userId = $param['user_id'];
266
                 }
415
                 }
267
             }
416
             }
268
         }
417
         }
269
-
418
+        switch ($res){
419
+            case 1:
420
+                $param['status']=5;
421
+                break;
422
+            case 2:
423
+                $param['status']=0;
424
+                break;
425
+            case 3:
426
+                $param['status']=3;
427
+                break;
428
+            case 6:
429
+                $param['status']=0;
430
+                break;
431
+        }
270
 		if ($this->data($param)->allowField(true)->save()) {
432
 		if ($this->data($param)->allowField(true)->save()) {
271
 			$data = [];
433
 			$data = [];
272
 			$data['plan_id'] = $this->plan_id;
434
 			$data['plan_id'] = $this->plan_id;
422
 	/**
584
 	/**
423
      * 回款计划数据
585
      * 回款计划数据
424
      * @param  $id 回款计划ID
586
      * @param  $id 回款计划ID
425
-     * @return 
426
-     */	
427
-   	public function getDataById($id = '')
428
-   	{   		
429
-   		$map['plan_id'] = $id;
430
-		$dataInfo = $this->where($map)->find();
431
-		if (!$dataInfo) {
432
-			$this->error = '暂无此数据';
433
-			return false;
434
-		}
435
-		$userModel = new \app\admin\model\User();
436
-		$dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
437
-		$dataInfo['plan_id'] = $id;
438
-		return $dataInfo;
439
-   	}
587
+     * @return
588
+     */
589
+    public function getDataById($id = '', $userId = 0, $model='')
590
+    {
591
+        $map['plan_id'] = $id;
592
+        $dataInfo = $this->where($map)->find();
593
+        if (!$dataInfo) {
594
+            $this->error = '暂无此数据';
595
+            return false;
596
+        }
597
+        if(empty($model) && $model!='update'){
598
+            $grantData = getFieldGrantData($userId);
599
+            foreach ($grantData['crm_receivables_plan'] as $key => $value) {
600
+                foreach ($value as $ke => $va) {
601
+                    if($va['maskType']!=0){
602
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
603
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
604
+                        $fieldGrant[$ke]['field'] = $va['field'];
605
+                    }
606
+                }
607
+            }
608
+            foreach ($fieldGrant AS $key => $val){
609
+                //掩码相关类型字段
610
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
611
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
612
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
613
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
614
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
615
+                    $email_array = explode("@", $dataInfo[$val['field']]);
616
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
617
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
618
+                    $rs = $prevfix . $str;
619
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
620
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
621
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
622
+                }
623
+            }
624
+        }
625
+//        $userModel = new \app\admin\model\User();
626
+//        $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
627
+//        $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
628
+//        $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
629
+//        $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
630
+//        $dataInfo['customer_id_info'] = $dataInfo['customer_id'] ? db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find() : [];
631
+//        $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
632
+//        $dataInfo['receivables_id'] = $id;
633
+//        $userModel = new \app\admin\model\User();
634
+//        $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
635
+//        $dataInfo['plan_id'] = $id;
636
+//        # 处理时间格式
637
+//        $fieldModel = new \app\admin\model\Field();
638
+//        $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
639
+//        foreach ($datetimeField as $key => $val) {
640
+//            $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
641
+//        }
642
+//        $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
643
+//        $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
644
+//        // 字段授权
645
+//        if (!empty($userId)) {
646
+//            $grantData = getFieldGrantData($userId);
647
+//            $userLevel = isSuperAdministrators($userId);
648
+//            foreach ($dataInfo as $key => $value) {
649
+//                if (!$userLevel && !empty($grantData['crm_receivables'])) {
650
+//                    $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
651
+//
652
+//                    # 查看权限
653
+//                    if ($status['read'] == 0) unset($dataInfo[$key]);
654
+//                }
655
+//            }
656
+//            if (!$userLevel && !empty($grantData['crm_receivables'])) {
657
+//                # 客户名称
658
+//                $customerStatus = getFieldGrantStatus('customer_id', $grantData['crm_receivables']);
659
+//                if ($customerStatus['read'] == 0) {
660
+//                    $dataInfo['customer_name'] = '';
661
+//                    $dataInfo['customer_id_info'] = [];
662
+//                }
663
+//                # 合同金额
664
+//                $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
665
+//                if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
666
+//                # 合同名称
667
+//                $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
668
+//                if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
669
+//            }
670
+//        }
671
+        return $dataInfo;
672
+    }
440
 
673
 
441
-	//模拟自定义字段返回
442
-	public function getField()
443
-	{	
444
-		$field_arr = [
445
-			'0' => [
446
-				'field' => 'customer_id',
447
-				'name' => '客户名称',
448
-				'form_type' => 'customer',
449
-				'setting' => []
450
-			],
451
-			'1' => [
452
-				'field' => 'contract_id',
453
-				'name' => '合同名称',
454
-				'form_type' => 'contract',
455
-				'setting' => []
456
-			],	
457
-			'2' => [
458
-				'field' => 'money',
459
-				'name' => '计划回款金额',
460
-				'form_type' => 'floatnumber',
461
-				'setting' => []
462
-			],
463
-			'3' => [
464
-				'field' => 'return_date',
465
-				'name' => '计划回款日期',
466
-				'form_type' => 'date',
467
-				'setting' => []
468
-			],
469
-			'4' => [
470
-				'field' => 'return_type',
471
-				'name' => '计划回款方式',
472
-				'form_type' => 'select',
473
-				'setting' => '支付宝\n微信\n转账'
474
-			],
475
-			'5' => [
476
-				'field' => 'remind',
477
-				'name' => '提前几日提醒',
478
-				'form_type' => 'number',
479
-				'setting' => []
480
-			],			
481
-			'6' => [
482
-				'field' => 'remark',
483
-				'name' => '备注',
484
-				'form_type' => 'textarea',
485
-				'setting' => []
486
-			],			
487
-			'7' => [
488
-				'field' => 'file',
489
-				'name' => '附件',
490
-				'form_type' => 'file',
491
-				'setting' => []
492
-			]
493
-		];
494
-		return $field_arr;
495
-	} 	  	
496
 }
674
 }

+ 90
- 0
application/crm/model/Visit.php Просмотреть файл

13
     protected $createTime = 'create_time';
13
     protected $createTime = 'create_time';
14
     protected $updateTime = 'update_time';
14
     protected $updateTime = 'update_time';
15
     protected $autoWriteTimestamp = true;
15
     protected $autoWriteTimestamp = true;
16
+
17
+    /**
18
+     * 回访计划数据
19
+     * @param  $id 回款计划ID
20
+     * @return
21
+     */
22
+    public function getDataById($id = '', $userId = 0, $model='')
23
+    {
24
+        $map['visit_id'] = $id;
25
+        $dataInfo = $this->where($map)->find();
26
+        if (!$dataInfo) {
27
+            $this->error = '暂无此数据';
28
+            return false;
29
+        }
30
+        if(empty($model) && $model!='update'){
31
+            $grantData = getFieldGrantData($userId);
32
+            foreach ($grantData['crm_visit'] as $key => $value) {
33
+                foreach ($value as $ke => $va) {
34
+                    if($va['maskType']!=0){
35
+                        $fieldGrant[$ke]['maskType'] = $va['maskType'];
36
+                        $fieldGrant[$ke]['form_type'] = $va['form_type'];
37
+                        $fieldGrant[$ke]['field'] = $va['field'];
38
+                    }
39
+                }
40
+            }
41
+            foreach ($fieldGrant AS $key => $val){
42
+                //掩码相关类型字段
43
+                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
44
+                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
45
+                    $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
46
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
47
+                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
48
+                    $email_array = explode("@", $dataInfo[$val['field']]);
49
+                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //邮箱前缀
50
+                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
51
+                    $rs = $prevfix . $str;
52
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
53
+                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
54
+                    $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null;
55
+                }
56
+            }
57
+        }
58
+//        $userModel = new \app\admin\model\User();
59
+//        $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
60
+//        $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
61
+//        $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
62
+//        $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
63
+//        $dataInfo['customer_id_info'] = $dataInfo['customer_id'] ? db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find() : [];
64
+//        $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
65
+//        $dataInfo['receivables_id'] = $id;
66
+//        $userModel = new \app\admin\model\User();
67
+//        $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
68
+//        $dataInfo['plan_id'] = $id;
69
+//        # 处理时间格式
70
+//        $fieldModel = new \app\admin\model\Field();
71
+//        $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
72
+//        foreach ($datetimeField as $key => $val) {
73
+//            $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
74
+//        }
75
+//        $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
76
+//        $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
77
+//        // 字段授权
78
+//        if (!empty($userId)) {
79
+//            $grantData = getFieldGrantData($userId);
80
+//            $userLevel = isSuperAdministrators($userId);
81
+//            foreach ($dataInfo as $key => $value) {
82
+//                if (!$userLevel && !empty($grantData['crm_receivables'])) {
83
+//                    $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
84
+//
85
+//                    # 查看权限
86
+//                    if ($status['read'] == 0) unset($dataInfo[$key]);
87
+//                }
88
+//            }
89
+//            if (!$userLevel && !empty($grantData['crm_receivables'])) {
90
+//                # 客户名称
91
+//                $customerStatus = getFieldGrantStatus('customer_id', $grantData['crm_receivables']);
92
+//                if ($customerStatus['read'] == 0) {
93
+//                    $dataInfo['customer_name'] = '';
94
+//                    $dataInfo['customer_id_info'] = [];
95
+//                }
96
+//                # 合同金额
97
+//                $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
98
+//                if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
99
+//                # 合同名称
100
+//                $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
101
+//                if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
102
+//            }
103
+//        }
104
+        return $dataInfo;
105
+    }
16
 }
106
 }

+ 1
- 0
application/oa/controller/Log.php Просмотреть файл

72
         $param = $this->param;
72
         $param = $this->param;
73
         $userInfo = $this->userInfo;
73
         $userInfo = $this->userInfo;
74
         $param['read_user_id'] = $userInfo['id'];
74
         $param['read_user_id'] = $userInfo['id'];
75
+        $param['structure_ids'] = $param['structure_id'];
75
         $param['structure_id'] = $userInfo['structure_id'];
76
         $param['structure_id'] = $userInfo['structure_id'];
76
         $data = model('Log')->getDataList($param);
77
         $data = model('Log')->getDataList($param);
77
         return resultArray(['data' => $data]);
78
         return resultArray(['data' => $data]);

+ 1
- 1
application/oa/model/Event.php Просмотреть файл

360
             }
360
             }
361
         } else {
361
         } else {
362
             $list = db('admin_oa_schedule')->select();
362
             $list = db('admin_oa_schedule')->select();
363
-            foreach ($list as $k=>$v){
363
+            foreach ($list as $k=> $v){
364
                 $list[$k]['is_select'] = 1;
364
                 $list[$k]['is_select'] = 1;
365
             }
365
             }
366
         }
366
         }

+ 9
- 3
application/oa/model/Log.php Просмотреть файл

42
         $recordModel = new \app\admin\model\Record();
42
         $recordModel = new \app\admin\model\Record();
43
         $user_id = $request['read_user_id'];
43
         $user_id = $request['read_user_id'];
44
         $by = $request['by'] ?: '';
44
         $by = $request['by'] ?: '';
45
+        if($request['structure_ids']){
46
+            $user_id = $userModel->getSubUserByStr($request['structure_ids'], 2);
47
+        }
45
         $map = [];
48
         $map = [];
46
         $search = $request['search'];
49
         $search = $request['search'];
47
         if (isset($request['search']) && $request['search']) {
50
         if (isset($request['search']) && $request['search']) {
66
             $map['log.create_time'] = ['between', [$start_time, $end_time]];
69
             $map['log.create_time'] = ['between', [$start_time, $end_time]];
67
         }
70
         }
68
         $requestData = $this->requestData();
71
         $requestData = $this->requestData();
72
+
69
         //获取权限范围内的员工
73
         //获取权限范围内的员工
70
-        $auth_user_ids = getSubUserId();
74
+        $auth_user_ids = getSubUserId(true,0,$user_id);
71
         $dataWhere['user_id'] = $user_id;
75
         $dataWhere['user_id'] = $user_id;
72
         $dataWhere['structure_id'] = $request['structure_id'];
76
         $dataWhere['structure_id'] = $request['structure_id'];
73
         $dataWhere['auth_user_ids'] = $auth_user_ids;
77
         $dataWhere['auth_user_ids'] = $auth_user_ids;
93
                 };
97
                 };
94
                 break;
98
                 break;
95
         }
99
         }
96
-        $list = Db::name('OaLog')
100
+
101
+        $list = Db::name('oa_log')
102
+            ->alias('log')
97
             ->where($map)
103
             ->where($map)
98
             ->where($logMap)
104
             ->where($logMap)
99
             ->where($searchMap)
105
             ->where($searchMap)
100
-            ->alias('log')
101
             ->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT')
106
             ->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT')
102
             ->page($request['page'], $request['limit'])
107
             ->page($request['page'], $request['limit'])
103
             ->field('log.*,user.realname,user.thumb_img')
108
             ->field('log.*,user.realname,user.thumb_img')
104
             ->order('log.update_time desc')
109
             ->order('log.update_time desc')
105
             ->select();
110
             ->select();
111
+
106
         $dataCount = $this->alias('log')->where($map)->where($logMap)->where($searchMap)->count();
112
         $dataCount = $this->alias('log')->where($map)->where($logMap)->where($searchMap)->count();
107
         foreach ($list as $k => $v) {
113
         foreach ($list as $k => $v) {
108
             $list[$k]['create_user_info']['realname'] = $v['realname'] ?: '';
114
             $list[$k]['create_user_info']['realname'] = $v['realname'] ?: '';

+ 3
- 1
config/route_crm.php Просмотреть файл

266
     'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']],
266
     'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']],
267
     //【回款】导出
267
     //【回款】导出
268
     'crm/receivables/excelExport' => ['crm/receivables/excelExport', ['method' => 'POST']],
268
     'crm/receivables/excelExport' => ['crm/receivables/excelExport', ['method' => 'POST']],
269
-
269
+    // 【回款计划】导出
270
+    'crm/receivablesPlan/excelExport' => ['crm/receivablesPlan/excelExport', ['method' => 'POST']],
270
     // 【回款计划】列表
271
     // 【回款计划】列表
271
     'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']],
272
     'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']],
272
     // 【回款计划】创建
273
     // 【回款计划】创建
301
     // 【发票】导出
302
     // 【发票】导出
302
     'crm/invoice/excelExport' => ['crm/invoice/excelExport', ['method' => 'POST']],
303
     'crm/invoice/excelExport' => ['crm/invoice/excelExport', ['method' => 'POST']],
303
     
304
     
305
+    
304
     // 【发票-开户行】列表
306
     // 【发票-开户行】列表
305
     'crm/invoiceInfo/index' => ['crm/invoiceInfo/index', ['method' => 'POST']],
307
     'crm/invoiceInfo/index' => ['crm/invoiceInfo/index', ['method' => 'POST']],
306
     // 【发票-开户行】详情
308
     // 【发票-开户行】详情

+ 2
- 2
config/version.php Просмотреть файл

1
 <?php
1
 <?php
2
 return array(
2
 return array(
3
-'VERSION'=>'11.1.0',
4
-'RELEASE'=>'20210625',
3
+'VERSION'=>'11.1.1',
4
+'RELEASE'=>'20210903',
5
 );
5
 );

+ 32
- 32
public/sql/5kcrm.sql Просмотреть файл

261
 INSERT INTO `5kcrm_admin_field` VALUES (15, 'crm_customer', 0, 'level', '客户级别', 'select', '', 0, 0, 0, '', 'A(重点客户)\nB(普通客户)\nC(非优先客户)', 3, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,0', 2, '', '', '', 'A(重点客户),B(普通客户),C(非优先客户)', 0);
261
 INSERT INTO `5kcrm_admin_field` VALUES (15, 'crm_customer', 0, 'level', '客户级别', 'select', '', 0, 0, 0, '', 'A(重点客户)\nB(普通客户)\nC(非优先客户)', 3, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,0', 2, '', '', '', 'A(重点客户),B(普通客户),C(非优先客户)', 0);
262
 INSERT INTO `5kcrm_admin_field` VALUES (16, 'crm_customer', 0, 'industry', '客户行业', 'select', '', 0, 0, 0, '', 'IT/通信/电子/互联网\n金融业\n房地产\n商业服务\n贸易\n生产\n运输/物流\n服务业\n文化传媒\n政府', 2, 191, 1553788800, 1624439031, 3, '', 0, 50, '0,1', 2, '', '', '', 'IT/通信/电子/互联网,金融业,房地产,商业服务,贸易,生产,运输/物流,服务业,文化传媒,政府', 1025);
262
 INSERT INTO `5kcrm_admin_field` VALUES (16, 'crm_customer', 0, 'industry', '客户行业', 'select', '', 0, 0, 0, '', 'IT/通信/电子/互联网\n金融业\n房地产\n商业服务\n贸易\n生产\n运输/物流\n服务业\n文化传媒\n政府', 2, 191, 1553788800, 1624439031, 3, '', 0, 50, '0,1', 2, '', '', '', 'IT/通信/电子/互联网,金融业,房地产,商业服务,贸易,生产,运输/物流,服务业,文化传媒,政府', 1025);
263
 INSERT INTO `5kcrm_admin_field` VALUES (17, 'crm_customer', 0, 'source', '客户来源', 'select', '', 0, 0, 0, '', '促销活动\n搜索引擎\n广告\n转介绍\n线上注册\n线上询价\n预约上门\n陌拜\n招商资源\n公司资源\n展会资源\n个人资源\n电话咨询\n邮件咨询', 4, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,1', 2, '', '', '', '促销活动,搜索引擎,广告,转介绍,线上注册,线上询价,预约上门,陌拜,招商资源,公司资源,展会资源,个人资源,电话咨询,邮件咨询', 1026);
263
 INSERT INTO `5kcrm_admin_field` VALUES (17, 'crm_customer', 0, 'source', '客户来源', 'select', '', 0, 0, 0, '', '促销活动\n搜索引擎\n广告\n转介绍\n线上注册\n线上询价\n预约上门\n陌拜\n招商资源\n公司资源\n展会资源\n个人资源\n电话咨询\n邮件咨询', 4, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,1', 2, '', '', '', '促销活动,搜索引擎,广告,转介绍,线上注册,线上询价,预约上门,陌拜,招商资源,公司资源,展会资源,个人资源,电话咨询,邮件咨询', 1026);
264
+INSERT INTO `5kcrm_admin_field` VALUES (18, 'crm_customer', 0, 'deal_status', '成交状态', 'select', '未成交', 0, 0, 1, '', '未成交\n已成交', 0, 191, 1553788800, 1553788800, 0, NULL, 0, 100, '', NULL, NULL, NULL, NULL, NULL, NULL);
264
 INSERT INTO `5kcrm_admin_field` VALUES (19, 'crm_customer', 0, 'telephone', '电话', 'text', '', 0, 0, 0, '', '', 5, 191, 1553788800, 1624439032, 1, '', 0, 50, '2,0', 0, '', '', '', '', 1027);
265
 INSERT INTO `5kcrm_admin_field` VALUES (19, 'crm_customer', 0, 'telephone', '电话', 'text', '', 0, 0, 0, '', '', 5, 191, 1553788800, 1624439032, 1, '', 0, 50, '2,0', 0, '', '', '', '', 1027);
265
 INSERT INTO `5kcrm_admin_field` VALUES (20, 'crm_customer', 0, 'website', '网址', 'text', '', 0, 0, 0, '', '', 8, 191, 1553788800, 1624439032, 1, '', 0, 50, '3,1', 0, '', '', '', '', 1028);
266
 INSERT INTO `5kcrm_admin_field` VALUES (20, 'crm_customer', 0, 'website', '网址', 'text', '', 0, 0, 0, '', '', 8, 191, 1553788800, 1624439032, 1, '', 0, 50, '3,1', 0, '', '', '', '', 1028);
266
 INSERT INTO `5kcrm_admin_field` VALUES (21, 'crm_customer', 0, 'next_time', '下次联系时间', 'datetime', '', 0, 0, 0, '', '', 9, 63, 1553788800, 1624439032, 13, '', 0, 50, '4,0', 0, '', '', '', '', 1029);
267
 INSERT INTO `5kcrm_admin_field` VALUES (21, 'crm_customer', 0, 'next_time', '下次联系时间', 'datetime', '', 0, 0, 0, '', '', 9, 63, 1553788800, 1624439032, 13, '', 0, 50, '4,0', 0, '', '', '', '', 1029);
1599
 -- Table structure for 5kcrm_crm_customer
1600
 -- Table structure for 5kcrm_crm_customer
1600
 -- ----------------------------
1601
 -- ----------------------------
1601
 DROP TABLE IF EXISTS `5kcrm_crm_customer`;
1602
 DROP TABLE IF EXISTS `5kcrm_crm_customer`;
1602
-CREATE TABLE `5kcrm_crm_customer`  (
1603
+CREATE TABLE `5kcrm_crm_customer` (
1603
   `customer_id` int(11) NOT NULL AUTO_INCREMENT,
1604
   `customer_id` int(11) NOT NULL AUTO_INCREMENT,
1604
-  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称',
1605
-  `is_lock` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1锁定',
1605
+  `name` varchar(255) DEFAULT NULL COMMENT '客户名称',
1606
+  `is_lock` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1锁定',
1606
   `deal_time` int(11) NOT NULL COMMENT '领取,分配,创建时间',
1607
   `deal_time` int(11) NOT NULL COMMENT '领取,分配,创建时间',
1607
-  `level` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户级别',
1608
-  `industry` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户行业',
1609
-  `source` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户来源',
1610
-  `telephone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '电话',
1611
-  `mobile` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机',
1612
-  `website` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '网址',
1613
-  `remark` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '备注',
1608
+  `level` varchar(500) DEFAULT NULL COMMENT '客户级别',
1609
+  `industry` varchar(500) DEFAULT NULL COMMENT '客户行业',
1610
+  `source` varchar(500) DEFAULT NULL COMMENT '客户来源',
1611
+  `telephone` varchar(255) DEFAULT NULL COMMENT '电话',
1612
+  `mobile` varchar(255) DEFAULT NULL COMMENT '手机',
1613
+  `website` varchar(255) DEFAULT NULL COMMENT '网址',
1614
+  `remark` text COMMENT '备注',
1614
   `create_user_id` int(11) NOT NULL COMMENT '创建人ID',
1615
   `create_user_id` int(11) NOT NULL COMMENT '创建人ID',
1615
   `owner_user_id` int(11) NOT NULL COMMENT '负责人ID',
1616
   `owner_user_id` int(11) NOT NULL COMMENT '负责人ID',
1616
-  `ro_user_id` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '只读权限',
1617
-  `rw_user_id` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '读写权限',
1618
-  `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '省市区',
1619
-  `location` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '定位信息',
1620
-  `detail_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '详细地址',
1621
-  `lng` double(14, 11) NULL DEFAULT NULL COMMENT '地理位置经度',
1622
-  `lat` double(14, 11) NULL DEFAULT NULL COMMENT '地理位置维度',
1623
-  `next_time` int(11) NULL DEFAULT NULL COMMENT '下次联系时间',
1624
-  `follow` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '跟进',
1625
-  `obtain_time` int(10) NOT NULL DEFAULT 0 COMMENT '负责人获取客户时间',
1617
+  `ro_user_id` varchar(500) NOT NULL DEFAULT '' COMMENT '只读权限',
1618
+  `rw_user_id` varchar(500) NOT NULL DEFAULT '' COMMENT '读写权限',
1619
+  `address` varchar(255) NOT NULL DEFAULT '' COMMENT '省市区',
1620
+  `location` varchar(255) NOT NULL DEFAULT '' COMMENT '定位信息',
1621
+  `detail_address` varchar(255) NOT NULL DEFAULT '' COMMENT '详细地址',
1622
+  `lng` double(14,11) DEFAULT NULL COMMENT '地理位置经度',
1623
+  `lat` double(14,11) DEFAULT NULL COMMENT '地理位置维度',
1624
+  `next_time` int(11) DEFAULT NULL COMMENT '下次联系时间',
1625
+  `follow` varchar(20) DEFAULT NULL COMMENT '跟进',
1626
+  `obtain_time` int(10) NOT NULL DEFAULT '0' COMMENT '负责人获取客户时间',
1626
   `create_time` int(11) NOT NULL COMMENT '创建时间',
1627
   `create_time` int(11) NOT NULL COMMENT '创建时间',
1627
   `update_time` int(11) NOT NULL COMMENT '更新时间',
1628
   `update_time` int(11) NOT NULL COMMENT '更新时间',
1628
-  `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;',
1629
-  `is_allocation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是分配给我的客户:1是;0不是',
1630
-  `last_time` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '最后跟进时间',
1631
-  `last_record` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '最后跟进记录',
1632
-  `email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
1633
-  `before_owner_user_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '前负责人',
1634
-  `into_pool_time` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '进入公海时间',
1635
-  `pool_remain` tinyint(1) NOT NULL DEFAULT 0 COMMENT '代办事项待进入公海:1已处理,0未处理',
1636
-  `deal_status` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '未成交' COMMENT '成交状态',
1629
+  `is_dealt` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否已经处理(待办事项):1已处理;0未处理;',
1630
+  `is_allocation` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否是分配给我的客户:1是;0不是',
1631
+  `last_time` int(10) unsigned DEFAULT NULL COMMENT '最后跟进时间',
1632
+  `last_record` varchar(512) DEFAULT NULL COMMENT '最后跟进记录',
1633
+  `email` varchar(255) DEFAULT NULL COMMENT '邮箱',
1634
+  `before_owner_user_id` int(10) unsigned DEFAULT '0' COMMENT '前负责人',
1635
+  `into_pool_time` int(10) unsigned DEFAULT '0' COMMENT '进入公海时间',
1636
+  `pool_remain` tinyint(1) NOT NULL DEFAULT '0' COMMENT '代办事项待进入公海:1已处理,0未处理',
1637
+  `deal_status` varchar(10) NOT NULL DEFAULT '未成交' COMMENT '成交状态',
1637
   PRIMARY KEY (`customer_id`) USING BTREE,
1638
   PRIMARY KEY (`customer_id`) USING BTREE,
1638
-  INDEX `bi_analysis`(`create_time`, `owner_user_id`) USING BTREE
1639
-) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '客户表' ROW_FORMAT = DYNAMIC;
1640
-
1639
+  KEY `bi_analysis` (`create_time`,`owner_user_id`) USING BTREE
1640
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='客户表';
1641
 -- ----------------------------
1641
 -- ----------------------------
1642
 -- Records of 5kcrm_crm_customer
1642
 -- Records of 5kcrm_crm_customer
1643
 -- ----------------------------
1643
 -- ----------------------------

+ 5
- 0
public/sql/update_sql_20210903.sql Просмотреть файл

1
+ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '实际回款金额';
2
+ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_data` date DEFAULT NULL COMMENT '实际回款日期';
3
+ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `un_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '未回金额';
4
+INSERT INTO `5kcrm_admin_field` VALUES (18, 'crm_customer', 0, 'deal_status', '成交状态', 'select', '未成交', 0, 0, 1, '', '未成交\n已成交', 0, 191, 1553788800, 1553788800, 0, NULL, 0, 100, '', NULL, NULL, NULL, NULL, NULL, NULL);
5
+

+ 2
- 2
public/static/js/step2.js Просмотреть файл

88
             localStorage.clear();
88
             localStorage.clear();
89
             window.location = 'step5.html';
89
             window.location = 'step5.html';
90
           } else if (result.code == '400') {
90
           } else if (result.code == '400') {
91
-            alert(result.error);
91
+            // alert(result.error);
92
             window.location.href = 'step6.html';
92
             window.location.href = 'step6.html';
93
           } else {
93
           } else {
94
-            alert(result.error);
94
+            // alert(result.error);
95
             window.location.href = 'step6.html';
95
             window.location.href = 'step6.html';
96
           }
96
           }
97
         },
97
         },

+ 5
- 0
update_sql_20210903.sql Просмотреть файл

1
+ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '实际回款金额';
2
+ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_data` date DEFAULT NULL COMMENT '实际回款日期';
3
+ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `un_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '未回金额';
4
+INSERT INTO `5kcrm_admin_field` VALUES (18, 'crm_customer', 0, 'deal_status', '成交状态', 'select', '未成交', 0, 0, 1, '', '未成交\n已成交', 0, 191, 1553788800, 1553788800, 0, NULL, 0, 100, '', NULL, NULL, NULL, NULL, NULL, NULL);
5
+