Michael_xu 4 년 전
부모
커밋
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,7 +274,7 @@ class ExamineFlow extends ApiCommon
274 274
     {
275 275
         $param = $this->param;
276 276
         $userInfo = $this->userInfo;
277
-       $data= $this->checkFlow($param,$userInfo);
277
+        $data= $this->checkFlow($param,$userInfo);
278 278
         return resultArray(['data' => $data]);
279 279
     }
280 280
     
@@ -287,18 +287,18 @@ class ExamineFlow extends ApiCommon
287 287
      * @version     1.0 版本号
288 288
      * @since       2021/3/15 0015 13:37
289 289
      */
290
-    public function checkFlow($param,$userInfo){
290
+    public function checkFlow($param,$userInfo)
291
+    {
291 292
         $examineStepModel = model('ExamineStep');
292 293
         $examineFlowModel = model('ExamineFlow');
293 294
         $check_user_id = $userInfo['id'];
294 295
         $flow_id = $param['flow_id'];
295 296
         $types = $param['types'];
296 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 299
         if (!$types || !in_array($types, $typesArr)) {
299 300
             return resultArray(['error' => '参数错误']);
300 301
         }
301
-    
302 302
         if ($flow_id) {
303 303
             $examineFlowData = $examineFlowModel->getDataById($param['flow_id']);
304 304
             if (!$examineFlowData) {

+ 54
- 28
application/admin/controller/Field.php 파일 보기

@@ -145,6 +145,21 @@ class Field extends ApiCommon
145 145
                 $errorMessage = '数字字段类型的小数配置错误!';
146 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 164
             if ($v['field_id']) {
150 165
                 if (isset($v['is_deleted']) && $v['is_deleted'] == '1') {
@@ -164,7 +179,6 @@ class Field extends ApiCommon
164 179
                 $saveParam[$k]['types_id'] = $types_id;
165 180
             }
166 181
         }
167
-
168 182
         # 必填的字段不可以隐藏
169 183
         if ($errorMessage) return resultArray(['error' => $errorMessage]);
170 184
 
@@ -174,14 +188,12 @@ class Field extends ApiCommon
174 188
         foreach ($deleteIds AS $key => $value) {
175 189
             if (!in_array($value, $delParam)) $delParam[] = $value;
176 190
         }
177
-
178 191
         # 新增
179 192
         if (!empty($saveParam)) {
180 193
             if (!$data = $fieldModel->createData($types, $saveParam)) {
181 194
                 $errorMessage[] = $fieldModel->getError();
182 195
             }
183 196
         }
184
-        
185 197
         # 编辑
186 198
         if (!empty($updateParam)) {
187 199
             if (!$data = $fieldModel->updateDataById($updateParam, $types)) {
@@ -259,10 +271,14 @@ class Field extends ApiCommon
259 271
         if ($action == 'read' || $action == 'update') {
260 272
             //获取详情数据
261 273
             if (($param['action'] == 'update' || $param['action'] == 'read') && $param['action_id']) {
274
+                $model='';
275
+                if($param['action'] == 'update'){
276
+                    $model='update';
277
+                }
262 278
                 switch ($param['types']) {
263 279
                     case 'crm_customer' : 
264 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 283
                         $auth_user_ids = $userModel->getUserByPer('crm', 'customer', $param['action']);
268 284
                         //读写权限
@@ -278,9 +294,10 @@ class Field extends ApiCommon
278 294
                         break;
279 295
                     case 'crm_leads' : 
280 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 299
                         $auth_user_ids = $userModel->getUserByPer('crm', 'leads', $param['action']);
300
+
284 301
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
285 302
                             header('Content-Type:application/json; charset=utf-8');
286 303
                             exit(json_encode(['code'=>102,'error'=>'无权操作']));
@@ -288,7 +305,7 @@ class Field extends ApiCommon
288 305
                         break;  
289 306
                     case 'crm_contacts' : 
290 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 310
                         $auth_user_ids = $userModel->getUserByPer('crm', 'contacts', $param['action']);
294 311
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
@@ -298,7 +315,7 @@ class Field extends ApiCommon
298 315
                         break;
299 316
                     case 'crm_business' :
300 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 320
                         $auth_user_ids = $userModel->getUserByPer('crm', 'business', $param['action']);
304 321
                         //读写权限
@@ -311,7 +328,7 @@ class Field extends ApiCommon
311 328
                         break;
312 329
                     case 'crm_contract' : 
313 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 333
                         $auth_user_ids = $userModel->getUserByPer('crm', 'contract', $param['action']);
317 334
                         //读写权限
@@ -324,7 +341,7 @@ class Field extends ApiCommon
324 341
                         break;
325 342
                     case 'crm_product' : 
326 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 347
                         $auth_user_ids = $userModel->getUserByPer('crm', 'product', $param['action']);
@@ -335,7 +352,7 @@ class Field extends ApiCommon
335 352
                         break;
336 353
                     case 'crm_receivables' : 
337 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 357
                         $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', $param['action']);
341 358
                         if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
@@ -345,7 +362,13 @@ class Field extends ApiCommon
345 362
                         break;
346 363
                     case 'crm_receivables_plan' : 
347 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 372
                         break; 
350 373
                     case 'oa_examine' :
351 374
                         $examineModel = new \app\oa\model\Examine();  
@@ -362,7 +385,7 @@ class Field extends ApiCommon
362 385
                         break;
363 386
                     case 'crm_visit' :
364 387
                         $visit = new \app\crm\model\Visit();
365
-                        $dataInfo = $visit->getDataById(intval($param['action_id']));
388
+                        $dataInfo = $visit->getDataById($param['action_id'],'',$model);
366 389
                         $fieldModel = new \app\admin\model\Field();
367 390
                         $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
368 391
                         foreach ($datetimeField as $key => $val) {
@@ -379,8 +402,8 @@ class Field extends ApiCommon
379 402
                         }
380 403
                         break;
381 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 407
                         $fieldModel = new \app\admin\model\Field();
385 408
                         $datetimeField = $fieldModel->getFieldByFormType('crm_invoice', 'datetime'); //日期时间类型
386 409
                         foreach ($datetimeField as $key => $val) {
@@ -400,7 +423,6 @@ class Field extends ApiCommon
400 423
         $param['user_id'] = $user_id;
401 424
         $action_id = $param['action_id'] ? : '';
402 425
         $data = $fieldModel->field($param, $dataInfo) ? : [];
403
-
404 426
         # 多公海数据详情
405 427
         if (!empty($param['pool_id']) && $param['action'] == 'read') {
406 428
             $data = $this->setPoolDetailData($data, $param['pool_id'], $param['action_id']);
@@ -511,10 +533,10 @@ class Field extends ApiCommon
511 533
                 case 'crm_leads' :
512 534
                     $leadsModel = new Leads();
513 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 538
                     foreach ($leadsData AS $key => $value) {
517
-                        if (empty($leadsArray[$key])) continue;
539
+                        if (empty($leadsArray[$key]) ) continue;
518 540
 
519 541
                         $data[] = [
520 542
                             'field'     => $key,
@@ -528,8 +550,7 @@ class Field extends ApiCommon
528 550
                 case 'crm_customer' :
529 551
                     $customerModel = new Customer();
530 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 554
                     foreach ($customerData AS $key => $value) {
534 555
                         if (empty($customerArray[$key]) || (!empty($param['pool_id']) && in_array($key, ['obtain_time', 'owner_user_id']))) continue;
535 556
 
@@ -545,7 +566,7 @@ class Field extends ApiCommon
545 566
                 case 'crm_contacts' :
546 567
                     $contactsModel = new Contacts();
547 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 571
                     foreach ($contactsData AS $key => $value) {
551 572
                         if (empty($contactsArray[$key])) continue;
@@ -562,7 +583,7 @@ class Field extends ApiCommon
562 583
                 case 'crm_business' :
563 584
                     $businessModel = new Business();
564 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 588
                     foreach ($businessData AS $key => $value) {
568 589
                         if (empty($businessArray[$key])) continue;
@@ -579,7 +600,7 @@ class Field extends ApiCommon
579 600
                 case 'crm_contract' :
580 601
                     $contractModel = new Contract();
581 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 605
                     foreach ($contractData AS $key => $value) {
585 606
                         if (empty($contractArray[$key])) continue;
@@ -596,7 +617,7 @@ class Field extends ApiCommon
596 617
                 case 'crm_receivables' :
597 618
                     $receivablesModel = new Receivables();
598 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 622
                     foreach ($receivablesData AS $key => $value) {
602 623
                         if (empty($receivablesArray[$key])) continue;
@@ -613,7 +634,7 @@ class Field extends ApiCommon
613 634
                 case 'crm_product' :
614 635
                     $productModel = new Product();
615 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 639
                     foreach ($productData AS $key => $value) {
619 640
                         if (empty($productArray[$key])) continue;
@@ -630,7 +651,7 @@ class Field extends ApiCommon
630 651
                 case 'crm_visit' :
631 652
                     $visitLogic = new VisitLogic();
632 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 656
                     foreach ($visitData AS $key => $value) {
636 657
                         if (empty($visitArray[$key])) continue;
@@ -646,18 +667,23 @@ class Field extends ApiCommon
646 667
                     break;
647 668
                 case 'crm_invoice' :
648 669
                     $invoiceData = db('crm_invoice')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('invoice_id', $action_id)->find();
670
+                    
649 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 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 673
                     $data[] = ['field' => 'create_time', 'name' => '创建时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['create_time']), 'system' => 1];
654 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 686
         $data = $fieldModel->resetField($user_id, $param['types'], $param['action'], $data);
660
-
661 687
         # 处理自定义字段分组排序
662 688
         if (in_array($param['action'], ['save', 'update', 'relative']) && $format == 2) $data = getFieldGroupOrderData($data);
663 689
 

+ 5
- 1
application/admin/controller/Index.php 파일 보기

@@ -63,9 +63,13 @@ class Index extends ApiCommon
63 63
             if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
64 64
         }
65 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 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 73
         return resultArray(['data' => $field_arr]);
70 74
     }
71 75
 

+ 303
- 248
application/admin/logic/FieldGrantLogic.php 파일 보기

@@ -47,9 +47,14 @@ class FieldGrantLogic
47 47
             'number', 'visit_time', 'owner_user_id', 'shape', 'customer_id', 'contacts_id', 'contract_id', 'satisfaction',
48 48
             'feedback', 'create_user_id', 'create_time', 'update_time'
49 49
         ],
50
+
50 51
         'invoice' => [
51 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,7 +75,6 @@ class FieldGrantLogic
70 75
         };
71 76
 
72 77
         $count = Db::name('admin_field_grant')->where($where)->count();
73
-
74 78
         # 如果该角色下没有字段授权数据则自动添加
75 79
         if ($count == 0 && Db::name('admin_group')->where('id', $param['role_id'])->find()) {
76 80
             $this->createCrmFieldGrant($param['role_id']);
@@ -113,6 +117,9 @@ class FieldGrantLogic
113 117
         $this->createVisitFieldGrant($roleId);
114 118
         # 添加发票字段授权信息
115 119
         $this->createInvoiceFieldGrant($roleId);
120
+
121
+        # 添加回款计划字段授权信息
122
+        $this->createReceivablesPlanFieldGrant($roleId);
116 123
     }
117 124
 
118 125
     /**
@@ -157,12 +164,12 @@ class FieldGrantLogic
157 164
 
158 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 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 173
                 'create_time' => time(),
167 174
                 'update_time' => time()
168 175
             ];
@@ -192,7 +199,7 @@ class FieldGrantLogic
192 199
         # 查询自定义字段表
193 200
         $fieldBaseData = [];
194 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 204
             if (in_array($value['field'], $this->except[$typesArray[1]])) continue;
198 205
 
@@ -203,11 +210,11 @@ class FieldGrantLogic
203 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 215
             $fieldData = $fieldBaseData;
209 216
 
210
-            foreach ($content AS $k => $v) {
217
+            foreach ($content as $k => $v) {
211 218
                 # 只处理自定义字段
212 219
                 if ($v['is_diy'] == 0) continue;
213 220
 
@@ -216,7 +223,7 @@ class FieldGrantLogic
216 223
                     unset($content[(int)$k]);
217 224
                 } else {
218 225
                     # 【处理更新:】如果在$fieldData找到,则进行同步更新。
219
-                    $content[$k]['name']  = $fieldData[$v['field']]['name'];
226
+                    $content[$k]['name'] = $fieldData[$v['field']]['name'];
220 227
                     $content[$k]['field'] = $fieldData[$v['field']]['field'];
221 228
 
222 229
                     # 删除$fieldData的数据,方便统计新增的自定义字段。
@@ -227,15 +234,15 @@ class FieldGrantLogic
227 234
 
228 235
             # 【处理新增】如果$fieldData还有数据,说明是新增的,则进行同步新增。
229 236
             if (!empty($fieldData)) {
230
-                foreach ($fieldData AS $k => $v) {
237
+                foreach ($fieldData as $k => $v) {
231 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 244
                         'write_operation' => 1,
238
-                        'is_diy'          => 1
245
+                        'is_diy' => 1
239 246
                     ];
240 247
                 }
241 248
             }
@@ -257,46 +264,46 @@ class FieldGrantLogic
257 264
     {
258 265
         # 固定字段
259 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 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 289
             if (in_array($value['field'], $this->except['leads'])) continue;
283 290
 
284 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 298
                 'write_operation' => 1,
291
-                'is_diy'          => 1
299
+                'is_diy' => 1
292 300
             ];
293 301
         }
294
-
295 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 307
             'create_time' => time(),
301 308
             'update_time' => time()
302 309
         ]);
@@ -313,50 +320,50 @@ class FieldGrantLogic
313 320
     {
314 321
         # 固定字段
315 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 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 349
             if (in_array($value['field'], $this->except['customer'])) continue;
343 350
 
344 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 357
                 'write_operation' => 1,
351
-                'is_diy'          => 1
358
+                'is_diy' => 1
352 359
             ];
353 360
         }
354 361
 
355 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 367
             'create_time' => time(),
361 368
             'update_time' => time()
362 369
         ]);
@@ -373,46 +380,46 @@ class FieldGrantLogic
373 380
     {
374 381
         # 固定字段
375 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 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 405
             if (in_array($value['field'], $this->except['contacts'])) continue;
399 406
 
400 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 413
                 'write_operation' => 1,
407
-                'is_diy'          => 1
414
+                'is_diy' => 1
408 415
             ];
409 416
         }
410 417
 
411 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 423
             'create_time' => time(),
417 424
             'update_time' => time()
418 425
         ]);
@@ -429,42 +436,42 @@ class FieldGrantLogic
429 436
     {
430 437
         # 固定字段
431 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 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 457
             if (in_array($value['field'], $this->except['business'])) continue;
451 458
 
452 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 465
                 'write_operation' => 1,
459
-                'is_diy'          => 1
466
+                'is_diy' => 1
460 467
             ];
461 468
         }
462 469
 
463 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 475
             'create_time' => time(),
469 476
             'update_time' => time()
470 477
         ]);
@@ -481,50 +488,50 @@ class FieldGrantLogic
481 488
     {
482 489
         # 固定字段
483 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 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 517
             if (in_array($value['field'], $this->except['contract'])) continue;
511 518
 
512 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 525
                 'write_operation' => 1,
519
-                'is_diy'          => 1
526
+                'is_diy' => 1
520 527
             ];
521 528
         }
522 529
 
523 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 535
             'create_time' => time(),
529 536
             'update_time' => time()
530 537
         ]);
@@ -541,44 +548,44 @@ class FieldGrantLogic
541 548
     {
542 549
         # 固定字段
543 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 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 571
             if (in_array($value['field'], $this->except['receivables'])) continue;
565 572
 
566 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 579
                 'write_operation' => 1,
573
-                'is_diy'          => 1
580
+                'is_diy' => 1
574 581
             ];
575 582
         }
576 583
 
577 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 589
             'create_time' => time(),
583 590
             'update_time' => time()
584 591
         ]);
@@ -595,41 +602,41 @@ class FieldGrantLogic
595 602
     {
596 603
         # 固定字段
597 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 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 622
             if (in_array($value['field'], $this->except['product'])) continue;
616 623
 
617 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 630
                 'write_operation' => 1,
624
-                'is_diy'          => 1
631
+                'is_diy' => 1
625 632
             ];
626 633
         }
627 634
 
628 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 640
             'create_time' => time(),
634 641
             'update_time' => time()
635 642
         ]);
@@ -645,49 +652,49 @@ class FieldGrantLogic
645 652
     private function createVisitFieldGrant($roleId)
646 653
     {
647 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 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 673
             if (in_array($value['field'], $this->except['visit'])) continue;
667 674
 
668 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 681
                 'write_operation' => 1,
675
-                'is_diy'          => 1
682
+                'is_diy' => 1
676 683
             ];
677 684
         }
678 685
 
679 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 691
             'create_time' => time(),
685 692
             'update_time' => time()
686 693
         ]);
687 694
     }
688 695
 
689 696
     /**
690
-     * 处理回访字段授权信息
697
+     * 处理发票字段授权信息
691 698
      *
692 699
      * @param $roleId
693 700
      * @author fanqi
@@ -696,38 +703,86 @@ class FieldGrantLogic
696 703
     private function createInvoiceFieldGrant($roleId)
697 704
     {
698 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 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 720
             if (in_array($value['field'], $this->except['invoice'])) continue;
714 721
 
715 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 728
                 'write_operation' => 1,
722
-                'is_diy'          => 1
729
+                'is_diy' => 1
723 730
             ];
724 731
         }
725 732
 
726 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 786
             'create_time' => time(),
732 787
             'update_time' => time()
733 788
         ]);

+ 12
- 12
application/admin/logic/PrintingLogic.php 파일 보기

@@ -207,12 +207,12 @@ class PrintingLogic
207 207
     {
208 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 213
         foreach ($businessList AS $key => $value) {
214 214
             if ($value['field'] == 'customer_id') continue;
215
-
215
+            if ($value['form_type']=='detail_table') continue;
216 216
             $result[] = [
217 217
                 'name'  => $value['name'],
218 218
                 'field' => $value['field']
@@ -240,13 +240,13 @@ class PrintingLogic
240 240
     {
241 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 246
         foreach ($customerList AS $key => $value) {
247 247
             if (in_array($value['field'], ['next_time'])) continue;
248 248
             if (in_array($type, [5, 6]) && in_array($value['field'], ['deal_status'])) continue;
249
-
249
+            if ($value['form_type']=='detail_table') continue;
250 250
             $result[] = [
251 251
                 'name'  => $value['name'],
252 252
                 'field' => $value['field']
@@ -274,13 +274,13 @@ class PrintingLogic
274 274
     {
275 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 280
         foreach ($productList AS $key => $value) {
281 281
             if (in_array($value['field'], ['status'])) continue;
282 282
             if (in_array($type, [5, 6]) && in_array($value['field'], ['description'])) continue;
283
-
283
+            if ($value['form_type']=='detail_table') continue;
284 284
             $result[] = [
285 285
                 'name'  => $value['name'],
286 286
                 'field' => $value['field']
@@ -310,13 +310,13 @@ class PrintingLogic
310 310
     {
311 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 316
         foreach ($contractList AS $key => $value) {
317 317
             if (in_array($type, [6, 7]) && in_array($value['field'], ['customer_id'])) continue;
318 318
             if ($type == 7 && in_array($value['field'], ['business_id'])) continue;
319
-
319
+            if ($value['form_type']=='detail_table') continue;
320 320
             $result[] = [
321 321
                 'name'  => $value['name'],
322 322
                 'field' => $value['field']
@@ -347,12 +347,12 @@ class PrintingLogic
347 347
     {
348 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 353
         foreach ($contactsList AS $key => $value) {
354 354
             if ($value['field'] == 'next_time') continue;
355
-
355
+            if ($value['form_type']=='detail_table') continue;
356 356
             $result[] = [
357 357
                 'name'  => $value['name'],
358 358
                 'field' => $value['field']
@@ -374,13 +374,13 @@ class PrintingLogic
374 374
     {
375 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 380
         foreach ($receivablesList AS $key => $value) {
381 381
             if (in_array($value['field'], ['contract_id'])) continue;
382 382
             if (in_array($type, [7]) && in_array($value['field'], ['contract_id'])) continue;
383
-
383
+            if ($value['form_type']=='detail_table') continue;
384 384
             $result[] = [
385 385
                 'name'  => $value['name'],
386 386
                 'field' => $value['field']

+ 14
- 2
application/admin/model/ActionRecord.php 파일 보기

@@ -16,7 +16,7 @@ class ActionRecord extends Common
16 16
      * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
17 17
      */
18 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 22
 	 * [getDataList 获取列表]
@@ -91,7 +91,19 @@ class ActionRecord extends Common
91 91
 				break;	
92 92
 			case 'crm_visit' :
93 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 108
 		if ($checkRes !== false) {
97 109
 			return true;

+ 18
- 1
application/admin/model/Common.php 파일 보기

@@ -295,9 +295,9 @@ class Common extends Model
295 295
      */
296 296
     public function exportHandle($list, $field_list, $type = '')
297 297
     {
298
-        
299 298
         foreach ($list as &$val) {
300 299
             foreach ($field_list as $field) {
300
+                // p($field);
301 301
                 switch ($field['form_type']) {
302 302
                     case 'user':
303 303
                         if (isset($val[$field['field'] . 'name'])) {
@@ -320,6 +320,16 @@ class Common extends Model
320 320
                     case 'contacts':
321 321
                         $val[$field['field']] = $val[$field['field'] . '_info']['name'];
322 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 333
                     default :
324 334
                         switch ($field['field']) {
325 335
                             // 商机销售阶段、商机状态组
@@ -337,6 +347,13 @@ class Common extends Model
337 347
                             case 'plan_id' :
338 348
                                 $val[$field['field']] = $val[$field['field'] . '_info'];
339 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,7 +22,7 @@ class ExamineFlow extends Common
22 22
     protected $createTime = 'create_time';
23 23
     protected $updateTime = 'update_time';
24 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 28
      * [getDataList 审批流程list]

+ 10
- 1
application/admin/model/ExamineRecord.php 파일 보기

@@ -57,13 +57,22 @@ class ExamineRecord extends Common
57 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 61
             $model      = db($param['types']);
62 62
             $primaryKey = null;
63 63
             if ($param['types'] == 'crm_contract')    $primaryKey = 'contract_id';
64 64
             if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
65 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 76
             $info     = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
68 77
             $userInfo = $userModel->getUserById($info['owner_user_id']);
69 78
 

+ 9
- 1
application/admin/model/ExamineStep.php 파일 보기

@@ -180,7 +180,15 @@ class ExamineStep extends Common
180 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 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 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 192
         $stepInfo = [];
185 193
         if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) {
186 194
             //固定审批流

+ 32
- 31
application/admin/model/Excel.php 파일 보기

@@ -399,15 +399,15 @@ class Excel extends Common
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 413
         if ($temp_file === null) {
@@ -468,7 +468,7 @@ class Excel extends Common
468 468
                         if (is_numeric($val[$rule['field']]) && strlen($val[$rule['field']]) > 15) {
469 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 474
                 fputcsv($fp, $rows);
@@ -519,11 +519,7 @@ class Excel extends Common
519 519
             $queue->dequeue();
520 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 524
         $queue = new Queue(self::IMPORT_QUEUE, 50000000);
529 525
         $import_queue_index = input('import_queue_index');
@@ -687,6 +683,7 @@ class Excel extends Common
687 683
             $fieldModel = new \app\admin\model\Field();
688 684
             $fieldParam['types'] = $types;
689 685
             $fieldParam['action'] = 'excel';
686
+          
690 687
             if (!empty($param['pool_id'])) {
691 688
                 $list = [];
692 689
                 $field_list = db('crm_customer_pool_field_setting')->where(['pool_id' => $param['pool_id'], 'is_hidden' => 0,
@@ -765,6 +762,7 @@ class Excel extends Common
765 762
                     }
766 763
                 }
767 764
             }
765
+           
768 766
             // 每次导入条数
769 767
             $page_size = 100;
770 768
             
@@ -812,6 +810,7 @@ class Excel extends Common
812 810
                     'update_time' => time(),
813 811
                 ];
814 812
             }
813
+         
815 814
             if ($temp !== count($field_list)) {
816 815
                 @unlink($save_path);
817 816
                 $queue->dequeue();
@@ -920,7 +919,7 @@ class Excel extends Common
920 919
                         $userId = db('admin_user')->where('realname', $val[2])->value('id');
921 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 923
                     $auth = db('admin_access')->where('user_id', $param['create_user_id'])->column('group_id');
925 924
                     // 数据重复时
926 925
                     if ($old_data_id_list) {
@@ -933,11 +932,7 @@ class Excel extends Common
933 932
                                 $up_success_count = 0;
934 933
                                 foreach ($old_data_id_list as $id) {
935 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 936
                                             if (!$dataModel->updateDataById($data, $id)) {
942 937
                                                 $temp_error = $dataModel->getError();
943 938
                                                 if ($temp_error == '无权操作') {
@@ -947,6 +942,10 @@ class Excel extends Common
947 942
                                                 $dataModel->rollback();
948 943
                                                 break;
949 944
                                             }
945
+                                            break;
946
+                                        } else {
947
+                                            $temp_error = '当前导入人员对该公海数据,无导入权限';
948
+                                            $error_data_func($val, $temp_error);
950 949
                                         }
951 950
                                     } else {
952 951
                                         if (!$dataModel->updateDataById($data, $id)) {
@@ -985,15 +984,16 @@ class Excel extends Common
985 984
                         }
986 985
                     } else {
987 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 989
                                 $data = array_merge($data, $default_data);
993 990
                                 $data['excel'] = 1;
994 991
                                 if (!$resData = $dataModel->createData($data)) {
995 992
                                     $error_data_func($val, $dataModel->getError());
996 993
                                 }
994
+                            } else {
995
+                                $temp_error = '当前导入人员对该公海数据,无导入权限';
996
+                                $error_data_func($val, $temp_error);
997 997
                             }
998 998
                         } else {
999 999
                             $data = array_merge($data, $default_data);
@@ -2013,7 +2013,7 @@ class Excel extends Common
2013 2013
             }
2014 2014
             
2015 2015
             // 开始行  +2 跳过表头
2016
-            $start_row = ($page - 1) * $page_size + 2;
2016
+            $start_row = ($page - 1) * $page_size + 3;
2017 2017
             // 结束行
2018 2018
             $end_row = $start_row + $page_size - 1;
2019 2019
             if ($end_row > $max_row) {
@@ -2032,10 +2032,14 @@ class Excel extends Common
2032 2032
             ];
2033 2033
             // 开始导入数据
2034 2034
             foreach ($dataList as $val) {
2035
+                $data = [];
2036
+                $empty_count = 0;
2037
+                $not_null_field = [];
2038
+                $fk = 0;
2035 2039
                 foreach ($field_list as $field) {
2036 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 2043
                     $data[$field['field']] = $temp_value;
2040 2044
                     if ($temp_value == '') {
2041 2045
                         if ($field['is_null']) {
@@ -2053,8 +2057,6 @@ class Excel extends Common
2053 2057
                     $error_data_func($val, '空行');
2054 2058
                     continue;
2055 2059
                 }
2056
-                $data = [];
2057
-                $fk = 0;
2058 2060
                 $classData = db('work_task_class')->where(['name' => $val[6], 'work_id' => $param['work_id']])->order('class_id', 'asc')->select();
2059 2061
                 $max_order_id = db('work_task_class')->where(['work_id' => $param['work_id'], 'status' => 1])->max('order_id');
2060 2062
                 if ($classData[0]['class_id'] != '') {
@@ -2071,7 +2073,6 @@ class Excel extends Common
2071 2073
                     $data['class_id'] = db('work_task_class')->insertGetId($item);
2072 2074
                 }
2073 2075
                 $dataModel = new \app\work\model\Task();
2074
-                
2075 2076
                 $data = array_merge($data, $default_data);
2076 2077
                 if (!$resData = $dataModel->createTask($data)) {
2077 2078
                     $error_data_func($val, $dataModel->getError());
@@ -2445,7 +2446,7 @@ class Excel extends Common
2445 2446
                 $this->batchTaskImportData('', $excelData);
2446 2447
             } elseif ($base == 'ActivityImport') {
2447 2448
                 $this->ActivityImport('', $excelData);
2448
-            } else {
2449
+            } elseif($base == 'batchImportData') {
2449 2450
                 $this->batchImportData('', $excelData);
2450 2451
             }
2451 2452
             $data = 0;

+ 570
- 178
application/admin/model/Field.php
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 74
- 1
application/admin/model/File.php 파일 보기

@@ -40,7 +40,19 @@ class File extends Common
40 40
         'crm_invoice',
41 41
         'crm_activity',
42 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,6 +147,18 @@ class File extends Common
135 147
                             case 'crm_activity': $r = db('crm_activity_file'); $r_name = 'activity_id'; break;
136 148
                             case 'crm_visit': $r = db('crm_visit_file'); $r_name = 'visit_id'; break;
137 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 162
 		            		default : break;
139 163
 		            	}
140 164
 		            	$rData = [];
@@ -293,6 +317,18 @@ class File extends Common
293 317
             case 'crm_activity' : $r = db('crm_activity_file'); $module = db('crm_activity'); break;
294 318
             case 'crm_visit' : $r = db('crm_visit_file'); $module = db('crm_visit'); break;
295 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 332
 			default : break;
297 333
 		}
298 334
 		if ($r) {
@@ -526,6 +562,43 @@ class File extends Common
526 562
                 case 'crm_receivables' :
527 563
                     $r = db('crm_receivables_file');
528 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 602
         		default : break;
530 603
         	}
531 604
         	$rWhere = [];

+ 1
- 1
application/admin/model/LoginRecord.php 파일 보기

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

+ 171
- 0
application/admin/model/Message.php 파일 보기

@@ -169,6 +169,103 @@ class Message extends Common
169 169
      * 移除队成员
170 170
      */
171 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,6 +423,32 @@ class Message extends Common
326 423
             self::BUSINESS_PASS,
327 424
             self::CUSTOMER_PASS,
328 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,6 +591,54 @@ class Message extends Common
468 591
             case self::BUSINESS_PASS:
469 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 644
         return '';

+ 70
- 1
application/admin/model/Scene.php 파일 보기

@@ -21,7 +21,7 @@ class Scene extends Common
21 21
 	protected $updateTime = false;
22 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 26
 	protected $type = [
27 27
         'data'    =>  'array',
@@ -467,6 +467,7 @@ class Scene extends Common
467 467
                 $map['is_end'] = ['condition' => 'is', 'value' => [2], 'form_type' => 'text'];
468 468
                 break;
469 469
             case 'star' :
470
+                # 我的关注
470 471
                 $where = $this->getStarParam($types, $user_id);
471 472
                 if (!empty($where)) $map = $where;
472 473
                 break;
@@ -482,11 +483,79 @@ class Scene extends Common
482 483
                 # 下架的产品
483 484
                 $map['status'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'status'];
484 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 494
     		default :
486 495
                 # 全部
487 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 559
     	$auth_user_ids = $auth_user_ids ? : [];
491 560
 
492 561
     	if ($auth_user_ids) {

+ 17
- 5
application/admin/model/Structure.php 파일 보기

@@ -28,18 +28,30 @@ class Structure extends Common
28 28
 	{	
29 29
 		$cat = new \com\Category('admin_structure', array('id', 'pid', 'name', 'title'));
30 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 36
 		// 若type为tree,则返回树状结构
32 37
 		if ($type == 'tree') {
33 38
 			$tree = new \com\Tree();
34 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 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 56
 	*根据字符串展示参与部门 use by work
45 57
 	*add by yykun

+ 53
- 6
application/admin/model/User.php 파일 보기

@@ -80,6 +80,12 @@ class User extends Common
80 80
             'name' => '岗位',
81 81
             'form_type' => 'text',
82 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,7 +280,18 @@ class User extends Common
274 280
                 $temp[$val['field']] = $param[$val['field']];
275 281
             }
276 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 295
             if (db('admin_user')->where('username', $param['username'])->find()) {
279 296
                 $this->error = '手机号已存在';
280 297
                 return false;
@@ -457,6 +474,18 @@ class User extends Common
457 474
                     }
458 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 489
                 $param['userId']=!empty($param['create_user_id'])?:$param['owner_user_id'];
461 490
                 unset($param['owner_user_id']);
462 491
                 unset($param['create_user_id']);
@@ -755,7 +784,11 @@ class User extends Common
755 784
             if ($v['name'] == 'market') {
756 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 793
         // $menuMap['status'] = 1;
761 794
         // $menuMap['rule_id'] = array('in',$newRuleIds);
@@ -765,6 +798,7 @@ class User extends Common
765 798
         $tree = new \com\Tree();
766 799
         //处理规则成树状
767 800
         $rulesList = $tree->list_to_tree($rules, 'id', 'pid', 'child', 0, true, array('pid'));
801
+
768 802
         //权限数组
769 803
         $authList = rulesListToArray($rulesList, $newRuleIds);
770 804
         //应用控制
@@ -817,6 +851,11 @@ class User extends Common
817 851
         if (in_array('calendar', $adminConfig)) {
818 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 860
         $structureId = db('admin_user')->where('id', $u_id)->value('structure_id');
822 861
         $poolStatus = db('crm_customer_pool')->where('status', 1)->where(function ($requery) use ($u_id, $structureId, $adminTypes) {
@@ -825,8 +864,9 @@ class User extends Common
825 864
             if (!in_array(1, $adminTypes)) $requery->whereOr('department_ids', 'like', '%,' . $structureId . ',%');
826 865
         })->value('pool_id');
827 866
         if (!empty($poolStatus)) $authList['crm']['pool'] = ['index' => true];
828
-        
867
+
829 868
         $ret['authList'] = $this->resetAuthorityFiled($authList);
869
+
830 870
         $res['manage'] = $rules;
831 871
         return $ret;
832 872
     }
@@ -988,7 +1028,11 @@ class User extends Common
988 1028
         
989 1029
         $authList['email'] = (object)[];
990 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 1036
         $authList['knowledge'] = (object)[];
993 1037
         
994 1038
         return $authList;
@@ -1084,6 +1128,7 @@ class User extends Common
1084 1128
      */
1085 1129
     public function getSubUserByStr($structure_id, $type = 1)
1086 1130
     {
1131
+        // p($structure_id);die;
1087 1132
         $allStrIds = (array)$structure_id;
1088 1133
         if ($type == 2) {
1089 1134
             $structureModel = new \app\admin\model\Structure();
@@ -1433,10 +1478,12 @@ class User extends Common
1433 1478
         foreach ($ids as $v) {
1434 1479
             $data['id'] = $v;
1435 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 1487
         } else {
1441 1488
             $this->error = '修改失败,请稍后重试';
1442 1489
             return false;

+ 79
- 50
application/admin/traits/FieldVerificationTrait.php 파일 보기

@@ -2,6 +2,7 @@
2 2
 /**
3 3
  * 字段验证(线索、客户、联系人、商机、合同、回款、回访、产品、办公审批)
4 4
  */
5
+
5 6
 namespace app\admin\traits;
6 7
 
7 8
 trait FieldVerificationTrait
@@ -15,9 +16,9 @@ trait FieldVerificationTrait
15 16
      * @param string $types 自定义表栏目类型:crm_leads、crm_customer ...
16 17
      * @param int $dataId 编辑时,相应的模块数据的ID
17 18
      * @param int $typesId 自定义表栏目类型ID
18
-     * @author fanqi
19
-     * @since 2021-05-18
20 19
      * @return string
20
+     * @since 2021-05-18
21
+     * @author fanqi
21 22
      */
22 23
     public function fieldDataValidate($param, $types, $userId, $dataId = 0, $typesId = 0)
23 24
     {
@@ -28,18 +29,18 @@ trait FieldVerificationTrait
28 29
 
29 30
         # 查询自定义字段表数据
30 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 36
             if (!$userLevel && !empty($grantData[$types])) {
36 37
                 $status = getFieldGrantStatus($value['field'], $grantData[$types]);
37 38
 
38 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 44
                 $error = $value['name'] . '字段不能为空!';
44 45
                 break;
45 46
             }
@@ -62,29 +63,27 @@ trait FieldVerificationTrait
62 63
                 break;
63 64
             }
64 65
 
66
+            
65 67
             # 验证明细表格不能为空
66 68
             if (!empty($value['is_null']) && $value['form_type'] == 'detail_table' && isset($param[$value['field']]) && empty($param[$value['field']])) {
67 69
                 $error = $value['name'] . '数据不能为空!';
68 70
             }
69 71
             # 验证明细表格可以为空,明细表格里的字段不能为空的情况。
70 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 76
                             $error = $value['name'] . '中的' . $v['name'] . '字段不能为空!';
75 77
                             break;
76 78
                         }
77 79
                     }
78 80
                 }
79 81
             }
80
-
81 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 86
             $uniqueStatus = false;
87
-
88 87
             # 验证唯一性
89 88
             if ($value['form_type'] == 'date_interval' && !empty($param[$value['field']])) {
90 89
                 // 日期区间
@@ -95,8 +94,15 @@ trait FieldVerificationTrait
95 94
             } elseif ($value['form_type'] == 'location' && !empty($param[$value['field']])) {
96 95
                 // 定位
97 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 103
             } else {
99 104
                 if (!empty($param[$value['field']])) $uniqueStatus = $this->checkDataUniqueForCommon($types, $value['field'], $param[$value['field']], $dataId);
105
+
100 106
             }
101 107
 
102 108
             if (!empty($uniqueStatus)) {
@@ -104,7 +110,6 @@ trait FieldVerificationTrait
104 110
                 break;
105 111
             }
106 112
         }
107
-
108 113
         return $error;
109 114
     }
110 115
 
@@ -117,9 +122,9 @@ trait FieldVerificationTrait
117 122
      * @param string $field 字段名称
118 123
      * @param string $value 字段值
119 124
      * @param int $dataId 更新时,传来的数据ID
120
-     * @author fanqi
121
-     * @since 2021-05-18
122 125
      * @return float|mixed|string
126
+     * @since 2021-05-18
127
+     * @author fanqi
123 128
      */
124 129
     private function checkDataUniqueForCommon($types, $field, $value, $dataId = 0)
125 130
     {
@@ -142,9 +147,9 @@ trait FieldVerificationTrait
142 147
      * @param string $field 字段名称
143 148
      * @param array $value 字段值
144 149
      * @param int $dataId 更新时,传来的数据ID
145
-     * @author fanqi
146
-     * @since 2021-05-18
147 150
      * @return float|mixed|string
151
+     * @since 2021-05-18
152
+     * @author fanqi
148 153
      */
149 154
     private function checkDataUniqueForDateInterval($types, $field, $value, $dataId = 0)
150 155
     {
@@ -167,9 +172,9 @@ trait FieldVerificationTrait
167 172
      * @param string $field 字段名称
168 173
      * @param array $value 字段值
169 174
      * @param int $dataId 更新时,传来的数据ID
170
-     * @author fanqi
171
-     * @since 2021-05-18
172 175
      * @return float|mixed|string
176
+     * @since 2021-05-18
177
+     * @author fanqi
173 178
      */
174 179
     private function checkDataUniqueForPosition($types, $field, $value, $dataId = 0)
175 180
     {
@@ -192,9 +197,9 @@ trait FieldVerificationTrait
192 197
      * @param string $field 字段名称
193 198
      * @param array $value 字段值
194 199
      * @param int $dataId 更新时,传来的数据ID
195
-     * @author fanqi
196
-     * @since 2021-05-18
197 200
      * @return float|mixed|string
201
+     * @since 2021-05-18
202
+     * @author fanqi
198 203
      */
199 204
     private function checkDataUniqueForLocation($types, $field, $value, $dataId = 0)
200 205
     {
@@ -210,46 +215,69 @@ trait FieldVerificationTrait
210 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 269
      * @param string $types 自定义表栏目类型:crm_leads、crm_customer ...
242 270
      * @param int $typesId 自定义表栏目类型ID
243
-     * @author fanqi
244
-     * @since 2021-05-18
245 271
      * @return bool|\PDOStatement|string|\think\Collection
272
+     * @since 2021-05-18
273
+     * @author fanqi
246 274
      */
247 275
     private function getFieldList($types, $typesId)
248 276
     {
249 277
         # 查询条件
250 278
         $where = [
251
-            'types'     => $types,
252
-            'types_id'  => $typesId,
279
+            'types' => $types,
280
+            'types_id' => $typesId,
253 281
             'is_hidden' => 0,
254 282
             'form_type' => ['neq', 'desc_text']
255 283
         ];
@@ -259,4 +287,5 @@ trait FieldVerificationTrait
259 287
 
260 288
         return db('admin_field')->field($fields)->where($where)->select();
261 289
     }
290
+
262 291
 }

+ 203
- 137
application/common.php 파일 보기

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

+ 29
- 1
application/common/command/PoolCommand.php 파일 보기

@@ -112,8 +112,36 @@ class PoolCommand extends Command
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 146
     protected function execute(Input $input, Output $output)
119 147
     {

+ 2
- 0
application/common/command/Team.php 파일 보기

@@ -71,6 +71,7 @@ class Team extends Command
71 71
     {
72 72
         $this->timer = Timer::add(1, function () {
73 73
             # 只在凌晨12点至6点间执行
74
+
74 75
             if ((int)date('H') >= 0 && (int)date('H') < 6) {
75 76
             # 团队成员过滤规则
76 77
             db('crm_team')->where('target_time',0)->delete();
@@ -125,6 +126,7 @@ class Team extends Command
125 126
                         }
126 127
                         $upData = db($types)->where([$data_name => $v['target_id']])->update($data);
127 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 131
                     Db::commit();
130 132
                 } catch (\Exception $e) {

+ 9
- 6
application/crm/controller/Contract.php 파일 보기

@@ -116,7 +116,10 @@ class Contract extends ApiCommon
116 116
                 $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
117 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,7 +215,7 @@ class Contract extends ApiCommon
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 219
             return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
217 220
         }
218 221
 
@@ -260,10 +263,10 @@ class Contract extends ApiCommon
260 263
         $examineFlowWheres['status'] = 1;
261 264
         $examineFlowWheres['is_deleted'] = 0;
262 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 271
         if ($contractExamineCount == 0 && !empty($param['is_draft'])) $param['check_status'] = 5;
269 272
 

+ 119
- 159
application/crm/controller/Customer.php 파일 보기

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

+ 3
- 1
application/crm/controller/CustomerPool.php 파일 보기

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

+ 1
- 1
application/crm/controller/Index.php 파일 보기

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

+ 2
- 2
application/crm/controller/Invoice.php 파일 보기

@@ -135,7 +135,7 @@ class Invoice extends ApiCommon
135 135
             $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
136 136
         } else {
137 137
             # 审批流停用,将状态改为审核通过
138
-            $param['check_status'] = 2;
138
+            $param['check_status'] = 7;
139 139
         }
140 140
 
141 141
         // 数据验证
@@ -350,7 +350,7 @@ class Invoice extends ApiCommon
350 350
         // }            
351 351
         
352 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 356
         $numberInfo = [];

+ 3
- 0
application/crm/controller/Leads.php 파일 보기

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

+ 2
- 1
application/crm/controller/Message.php 파일 보기

@@ -490,11 +490,12 @@ class Message extends ApiCommon
490 490
         switch ($type) {
491 491
             case '1' :
492 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 494
                 break;
495 495
             case '2' : $param['end_time'] = array('lt',date('Y-m-d',time())); break;
496 496
         }
497 497
         $data = $contractModel->getDataList($param);
498
+//        p($contractModel->getLastSql());
498 499
         if ($types == 'list') {
499 500
             return resultArray(['data' => $data]);
500 501
         }

+ 19
- 5
application/crm/controller/Receivables.php 파일 보기

@@ -74,7 +74,7 @@ class Receivables extends ApiCommon
74 74
         $excelModel = new \app\admin\model\Excel();
75 75
         // 导出的字段列表
76 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 79
         $file_name = '5kcrm_receivables_' . date('Ymd');
80 80
         $model = model('Receivables');
@@ -148,7 +148,10 @@ class Receivables extends ApiCommon
148 148
             $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
149 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 157
         $res = $receivablesModel->createData($param);
@@ -224,7 +227,7 @@ class Receivables extends ApiCommon
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 231
             return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
229 232
         }
230 233
         
@@ -271,7 +274,6 @@ class Receivables extends ApiCommon
271 274
                 }
272 275
             }
273 276
         }
274
-        
275 277
         $res = $receivablesModel->updateDataById($param, $param['id']);
276 278
         if ($res) {
277 279
             //将审批记录至为无效
@@ -474,7 +476,19 @@ class Receivables extends ApiCommon
474 476
             
475 477
             //审批记录
476 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 492
             if ($is_end == 1 && !empty($status)) {
479 493
                 //发送站内信 通过
480 494
                 (new Message())->send(

+ 38
- 1
application/crm/controller/ReceivablesPlan.php 파일 보기

@@ -161,5 +161,42 @@ class ReceivablesPlan extends ApiCommon
161 161
         } else {
162 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,13 +442,15 @@ class ActivityLogic
442 442
         $param['type']           = 1;
443 443
         $param['next_time']      = !empty($param['next_time'])    ? strtotime($param['next_time'])        : 0;
444 444
         $param['business_ids']   = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : '';
445
-        $param['create_time']    = time();
445
+       
446 446
         $param['update_time']    = time();
447 447
         if(empty($param['excel'])){
448 448
             if (!empty($param['contacts_ids'])) $param['contacts_ids'] = ',' . $param['contacts_ids'] . ',';
449 449
         }else{
450
+            $param['create_time']    = $param['create_time'];
450 451
             unset($param['excel']);
451 452
         }
453
+       
452 454
         $activityJson = Activity::create($param);
453 455
         if (empty($activityJson)) return false;
454 456
 

+ 52
- 61
application/crm/logic/IndexLogic.php 파일 보기

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

+ 128
- 52
application/crm/logic/InvoiceLogic.php 파일 보기

@@ -17,7 +17,7 @@ class InvoiceLogic
17 17
 {
18 18
     private $invoiceType = ['增值税专用发票', '增值税普通发票', '国税通用机打发票', '地税通用机打发票', '收据'];
19 19
     private $check_status = ['待审核', '审核中', '审核通过', '审核未通过', '撤回'];
20
-    
20
+
21 21
     /**
22 22
      * 列表
23 23
      *
@@ -45,7 +45,7 @@ class InvoiceLogic
45 45
         $scene_id = $param['scene_id'];
46 46
         $isMessage = !empty($param['isMessage']);
47 47
         $common = new Common();
48
-        
48
+
49 49
         unset($param['getCount']);
50 50
 //        unset($param['limit']); 导出使用 暂未发现为何去掉分页参数
51 51
 //        unset($param['page']);
@@ -60,11 +60,11 @@ class InvoiceLogic
60 60
         unset($param['isMessage']);
61 61
         $request = $common->fmtRequest($param);
62 62
         $where = [];
63
-       
63
+
64 64
         # 高级搜索
65 65
         $requestMap = !empty($request['map']) ? $request['map'] : [];
66 66
         unset($requestMap['search']);
67
-        
67
+
68 68
         # 场景
69 69
         $sceneMap = [];
70 70
         $sceneModel = new \app\admin\model\Scene();
@@ -94,13 +94,13 @@ class InvoiceLogic
94 94
         # 替换掉字段前缀,不修改公共函数
95 95
         foreach ($map as $key => $value) {
96 96
             $k = str_replace('invoice.', '', $key);
97
-            
97
+
98 98
             $where[$k] = $value;
99 99
         }
100 100
         # 待办事项查询参数
101 101
         $dealtWhere = [];
102 102
         if (!empty($invoiceIdArray)) $dealtWhere['invoice.invoice_id'] = ['in', $invoiceIdArray];
103
-        
103
+
104 104
         # 权限,不是待办事项,则加上列表权限
105 105
         $auth = [];
106 106
         $userModel = new \app\admin\model\User();
@@ -154,7 +154,7 @@ class InvoiceLogic
154 154
             ->limit($request['offset'], $request['length'])
155 155
             ->orderRaw($order)
156 156
             ->select();
157
-        
157
+
158 158
         $dataCount = db('crm_invoice')
159 159
             ->alias('invoice')
160 160
             ->join($join)
@@ -176,21 +176,35 @@ class InvoiceLogic
176 176
         $positionField = $fieldModel->getFieldByFormType('crm_invoice', 'position'); // 地址类型字段
177 177
         $handwritingField = $fieldModel->getFieldByFormType('crm_invoice', 'handwriting_sign'); // 手写签名类型字段
178 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 183
         $extraData = [];
182 184
         $invoice_id_list = !empty($list) ? array_column($list, 'invoice_id') : [];
183 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 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 200
         foreach ($list as $key => $value) {
190 201
             $list[$key]['check_status_info'] = $this->check_status[$value['check_status']];
191 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 208
             foreach ($userField as $k => $val) {
195 209
                 $usernameField = !empty($value[$val]) ? db('admin_user')->whereIn('id', stringToArray($value[$val]))->column('realname') : [];
196 210
                 $list[$key][$val] = implode($usernameField, ',');
@@ -214,7 +228,7 @@ class InvoiceLogic
214 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 232
                 $handwritingData = !empty($value[$val]) ? db('admin_file')->where('file_id', $value[$val])->value('file_path') : null;
219 233
                 $list[$key][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
220 234
             }
@@ -222,24 +236,51 @@ class InvoiceLogic
222 236
             foreach ($locationField as $k => $val) {
223 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 275
      * @param $param
236 276
      * @return Invoice|int|string
237 277
      */
238
-    public function save($param)
278
+    public
279
+    function save($param) 
239 280
     {
240 281
         return db('crm_invoice')->insert($param, false, true);
241 282
     }
242
-    
283
+
243 284
     /**
244 285
      * 详情
245 286
      *
@@ -250,27 +291,53 @@ class InvoiceLogic
250 291
      * @throws \think\db\exception\ModelNotFoundException
251 292
      * @throws \think\exception\DbException
252 293
      */
253
-    public function read($invoiceId, $isUpdate)
294
+    public
295
+    function read($invoiceId, $isUpdate)
254 296
     {
255 297
         $apiCommon = new ApiCommon();
256
-        
298
+
257 299
         $userId = $apiCommon->userInfo['id'];
258 300
         $result = [];
259 301
         $dataObject = Invoice::with(['toCustomer', 'toContract'])->where('invoice_id', $invoiceId)->find();
260
-        
302
+
261 303
         if (empty($dataObject)) return $result;
262
-        
304
+
263 305
         $dataArray = $dataObject->toArray();
264
-        
306
+
265 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 334
         # 主键ID
268 335
         $result['invoice_id'] = $dataArray['invoice_id'];
269
-        
336
+
270 337
         # 是否显示撤回按钮
271 338
         $result['isShowRecall'] = 0;
272 339
         if ($userId == $dataArray['owner_user_id'] && $dataArray['check_status'] == 0) $result['isShowRecall'] = 1;
273
-        
340
+
274 341
         $result['customer_name'] = $dataArray['customer_name'];     # 客户名称
275 342
         $result['invoice_money'] = $dataArray['invoice_money'];     # 开票金额
276 343
         $result['invoice_number'] = $dataArray['invoice_number'];    # 发票号码
@@ -296,7 +363,7 @@ class InvoiceLogic
296 363
             'customer_id' => $dataArray['customer_id'],
297 364
             'check_status' => $check[$dataArray['check_status']]
298 365
         ];
299
-        
366
+
300 367
         # 发票信息
301 368
         $result['invoice'] = [
302 369
             'title_type' => $dataArray['title_type'],
@@ -307,39 +374,41 @@ class InvoiceLogic
307 374
             'deposit_address' => $dataArray['deposit_address'],
308 375
             'phone' => $dataArray['phone']
309 376
         ];
310
-        
377
+
311 378
         # 邮寄信息
312 379
         $result['posting'] = [
313 380
             'contacts_name' => $dataArray['contacts_name'],
314 381
             'contacts_mobile' => $dataArray['contacts_mobile'],
315 382
             'contacts_address' => $dataArray['contacts_address']
316 383
         ];
317
-        
384
+
318 385
         return $result;
319 386
     }
320
-    
387
+
321 388
     /**
322 389
      * 编辑
323 390
      *
324 391
      * @param $param
325 392
      * @return Invoice
326 393
      */
327
-    public function update($param)
394
+    public
395
+    function update($param)
328 396
     {
329 397
         return Invoice::update($param);
330 398
     }
331
-    
399
+
332 400
     /**
333 401
      * 删除
334 402
      *
335 403
      * @param $where
336 404
      * @return int
337 405
      */
338
-    public function delete($where)
406
+    public
407
+    function delete($where)
339 408
     {
340 409
         return Invoice::destroy($where);
341 410
     }
342
-    
411
+
343 412
     /**
344 413
      * 获取审批状态
345 414
      *
@@ -350,17 +419,18 @@ class InvoiceLogic
350 419
      * @throws \think\db\exception\ModelNotFoundException
351 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 426
         if ($isDelete) {
357 427
             return Invoice::field(['check_status'])->whereIn('invoice_id', $invoiceId)->select();
358 428
         }
359
-        
429
+
360 430
         # 编辑
361 431
         return Invoice::where('invoice_id', $invoiceId)->value('check_status');
362 432
     }
363
-    
433
+
364 434
     /**
365 435
      * 转移(变更负责人)
366 436
      *
@@ -368,22 +438,24 @@ class InvoiceLogic
368 438
      * @param $ownerUserId
369 439
      * @return Invoice
370 440
      */
371
-    public function transfer($invoiceIds, $ownerUserId)
441
+    public
442
+    function transfer($invoiceIds, $ownerUserId)
372 443
     {
373 444
         return Invoice::whereIn('invoice_id', $invoiceIds)->update(['owner_user_id' => $ownerUserId]);
374 445
     }
375
-    
446
+
376 447
     /**
377 448
      * 设置开票
378 449
      *
379 450
      * @param $param
380 451
      * @return Invoice
381 452
      */
382
-    public function setInvoice($param)
453
+    public
454
+    function setInvoice($param)
383 455
     {
384 456
         return Invoice::update($param);
385 457
     }
386
-    
458
+
387 459
     /**
388 460
      * 获取发票审核信息
389 461
      *
@@ -393,24 +465,26 @@ class InvoiceLogic
393 465
      * @throws \think\db\exception\ModelNotFoundException
394 466
      * @throws \think\exception\DbException
395 467
      */
396
-    public function getExamineInfo($invoiceId)
468
+    public
469
+    function getExamineInfo($invoiceId)
397 470
     {
398 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 473
         return Invoice::field($field)->where('invoice_id', $invoiceId)->find();
401 474
     }
402
-    
475
+
403 476
     /**
404 477
      * 设置审批信息
405 478
      *
406 479
      * @param $data
407 480
      * @return Invoice
408 481
      */
409
-    public function setExamineInfo($data)
482
+    public
483
+    function setExamineInfo($data)
410 484
     {
411 485
         return Invoice::update($data);
412 486
     }
413
-    
487
+
414 488
     /**
415 489
      * 添加撤销审核记录
416 490
      *
@@ -420,7 +494,8 @@ class InvoiceLogic
420 494
      * @param $content
421 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 500
         $data = [
426 501
             'types' => 'crm_invoice',
@@ -432,17 +507,18 @@ class InvoiceLogic
432 507
             'status' => 2,
433 508
             'content' => !empty($content) ? $content : $realname . ' 撤销了审核',
434 509
         ];
435
-        
510
+
436 511
         Db::name('admin_examine_record')->insert($data);
437 512
     }
438
-    
513
+
439 514
     /**
440 515
      * 检查发票编号是否重复
441 516
      *
442 517
      * @param $where
443 518
      * @return int|mixed|string|null
444 519
      */
445
-    public function getInvoiceId($where)
520
+    public
521
+    function getInvoiceId($where)
446 522
     {
447 523
         return Db::name('crm_invoice')->where($where)->value('invoice_id');
448 524
     }

+ 82
- 2
application/crm/logic/VisitLogic.php 파일 보기

@@ -100,6 +100,9 @@ class VisitLogic extends Common
100 100
         $positionField = $fieldModel->getFieldByFormType('crm_visit', 'position'); // 地址类型字段
101 101
         $handwritingField = $fieldModel->getFieldByFormType('crm_visit', 'handwriting_sign'); // 手写签名类型字段
102 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 106
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
104 107
         $temporaryField = str_replace('_name', '', $order_field);
105 108
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@@ -147,12 +150,26 @@ class VisitLogic extends Common
147 150
         foreach ($extraList AS $key => $value) {
148 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 163
         foreach ($list as $k => $v) {
151 164
             $list[$k]['contract_num'] = $v['contract_number'];
152 165
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
153 166
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
154 167
             $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
155 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 173
             foreach ($userField as $key => $val) {
157 174
                 $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
158 175
                 $list[$k][$val.'_name'] = implode($usernameField, ',');
@@ -184,6 +201,31 @@ class VisitLogic extends Common
184 201
             foreach ($locationField AS $key => $val) {
185 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 229
             $list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
188 230
             $list[$k]['contract_id_info']['name'] = $v['contract_name'];
189 231
             $list[$k]['customer_id_info']['customer_id'] = $v['create_user_id'];
@@ -226,6 +268,32 @@ class VisitLogic extends Common
226 268
             $this->error = '暂无此数据';
227 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 297
         $userModel = new \app\admin\model\User();
230 298
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
231 299
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@@ -584,13 +652,25 @@ class VisitLogic extends Common
584 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 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 668
         return [
591 669
             'create_user_id' => $realname,
670
+            'owner_user_id' => $ownerUserName,
592 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,6 +161,9 @@ class Business extends Common
161 161
         $positionField = $fieldModel->getFieldByFormType('crm_business', 'position'); // 地址类型字段
162 162
         $handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); // 手写签名类型字段
163 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 167
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
165 168
         $temporaryField = str_replace('_name', '', $order_field);
166 169
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@@ -224,6 +227,16 @@ class Business extends Common
224 227
         foreach ($extraList AS $key => $value) {
225 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 240
         foreach ($list as $k => $v) {
228 241
             $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
229 242
             $list[$k]['customer_id_info']['name'] = $v['customer_name'];
@@ -262,6 +275,31 @@ class Business extends Common
262 275
             foreach ($locationField AS $key => $val) {
263 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 303
             $statusInfo = [];
266 304
             $status_count = 0;
267 305
             if (!$v['is_end']) {
@@ -301,6 +339,9 @@ class Business extends Common
301 339
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
302 340
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
303 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 346
         $data = [];
306 347
         $data['list'] = $list ?: [];
@@ -633,13 +674,41 @@ class Business extends Common
633 674
      * @throws \think\db\exception\ModelNotFoundException
634 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 679
         $dataInfo = db('crm_business')->where('business_id', $id)->find();
639 680
         if (!$dataInfo) {
640 681
             $this->error = '暂无此数据';
641 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 712
         $userModel = new \app\admin\model\User();
644 713
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
645 714
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@@ -902,15 +971,24 @@ class Business extends Common
902 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 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 985
         return [
910 986
             'create_user_id' => $realname,
987
+            'owner_user_id' => $ownerUserName,
911 988
             'create_time' => date('Y-m-d H:i:s', $business['create_time']),
912 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,6 +136,9 @@ class Contacts extends Common
136 136
         $positionField = $fieldModel->getFieldByFormType('crm_contacts', 'position'); // 地址类型字段
137 137
         $handwritingField = $fieldModel->getFieldByFormType('crm_contacts', 'handwriting_sign'); // 手写签名类型字段
138 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 142
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
140 143
         $temporaryField = str_replace('_name', '', $order_field);
141 144
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@@ -187,6 +190,16 @@ class Contacts extends Common
187 190
         foreach ($extraList as $key => $value) {
188 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 203
         foreach ($list as $k => $v) {
191 204
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
192 205
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@@ -223,6 +236,31 @@ class Contacts extends Common
223 236
             foreach ($locationField AS $key => $val) {
224 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 265
             $permission = [];
228 266
             $is_read = 0;
@@ -248,6 +286,9 @@ class Contacts extends Common
248 286
             $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
249 287
             # 负责人
250 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 293
         $data = [];
253 294
         $data['list'] = $list;
@@ -586,7 +627,7 @@ class Contacts extends Common
586 627
      * @throws \think\db\exception\ModelNotFoundException
587 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 632
         $map['contacts_id'] = $id;
592 633
         $dataInfo = db('crm_contacts')->where($map)->find();
@@ -594,6 +635,35 @@ class Contacts extends Common
594 635
             $this->error = '暂无此数据';
595 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 667
         $userModel = new \app\admin\model\User();
598 668
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
599 669
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@@ -694,15 +764,25 @@ class Contacts extends Common
694 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 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 779
         return [
702 780
             'create_user_id' => $realname,
781
+            'owner_user_id' => $ownerUserName,
703 782
             'create_time' => date('Y-m-d H:i:s', $contacts['create_time']),
704 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,7 +23,7 @@ class Contract extends Common
23 23
     protected $createTime = 'create_time';
24 24
     protected $updateTime = 'update_time';
25 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 29
      * [getDataList 合同list]
@@ -36,6 +36,9 @@ class Contract extends Common
36 36
      */
37 37
 	public function getDataList($request)
38 38
     {
39
+        // if($param['check_status'] == 2){
40
+        //     die('11');
41
+        // }
39 42
     	$userModel = new \app\admin\model\User();
40 43
     	$structureModel = new \app\admin\model\Structure();
41 44
     	$fieldModel = new \app\admin\model\Field();
@@ -62,8 +65,8 @@ class Contract extends Common
62 65
         unset($request['isMessage']);
63 66
 
64 67
         $request = $this->fmtRequest( $request );
65
-
66 68
         $requestMap = $request['map'] ? : [];
69
+
67 70
 		$sceneModel = new \app\admin\model\Scene();
68 71
         # getCount是代办事项传来的参数,代办事项不需要使用场景
69 72
         $sceneMap = [];
@@ -148,6 +151,9 @@ class Contract extends Common
148 151
         $positionField = $fieldModel->getFieldByFormType('crm_contract', 'position'); // 地址类型字段
149 152
         $handwritingField = $fieldModel->getFieldByFormType('crm_contract', 'handwriting_sign'); // 手写签名类型字段
150 153
         $locationField = $fieldModel->getFieldByFormType('crm_contract', 'location'); // 定位类型字段
154
+        $boxField = $fieldModel->getFieldByFormType('crm_contract', 'checkbox'); // 多选类型字段
155
+        $floatField = $fieldModel->getFieldByFormType('crm_contract', 'floatnumber'); // 货币类型字段
156
+
151 157
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
152 158
         $temporaryField = str_replace('_name', '', $order_field);
153 159
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@@ -188,6 +194,12 @@ class Contract extends Common
188 194
             if ($vv == 'contract.customer_name') unset($indexField[(int)$kk]);
189 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 203
 		$list = db('crm_contract')
192 204
 				->alias('contract')
193 205
 				->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT')		
@@ -218,6 +230,16 @@ class Contract extends Common
218 230
         foreach ($extraList AS $key => $value) {
219 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 243
         foreach ($list as $k=>$v) {
222 244
         	$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
223 245
         	$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@@ -253,6 +275,31 @@ class Contract extends Common
253 275
             // 定位类型字段
254 276
             foreach ($locationField AS $key => $val) {
255 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 304
         	$list[$k]['business_id_info']['business_id'] = $v['business_id'];
258 305
         	$list[$k]['business_id_info']['name'] = $v['business_name'];
@@ -260,6 +307,7 @@ class Contract extends Common
260 307
         	$list[$k]['customer_id_info']['name'] = $v['customer_name'];
261 308
 			$list[$k]['contacts_id_info']['contacts_id'] = $v['contacts_id'];
262 309
         	$list[$k]['contacts_id_info']['name'] = $v['contacts_name'];
310
+
263 311
             $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
264 312
         	$moneyInfo = [];
265 313
         	$moneyInfo = $receivablesModel->getMoneyByContractId($v['contract_id']);
@@ -298,6 +346,9 @@ class Contract extends Common
298 346
             $list[$k]['order_user_name'] = implode(',', $orderNames);
299 347
             unset($list[$k]['order_user_id']);
300 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 353
         $data = [];
303 354
         $data['list'] = $list;
@@ -749,7 +800,7 @@ class Contract extends Common
749 800
      * @throws \think\db\exception\ModelNotFoundException
750 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 805
    		$receivablesModel = new \app\crm\model\Receivables();
755 806
    		$userModel = new \app\admin\model\User();	
@@ -759,6 +810,35 @@ class Contract extends Common
759 810
 			$this->error = '暂无此数据';
760 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 842
 		$dataInfo['create_user_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
763 843
 		$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; 
764 844
 		$dataInfo['create_user_name'] = !empty($dataInfo['create_user_info']['realname']) ? $dataInfo['create_user_info']['realname'] : '';
@@ -903,20 +983,32 @@ class Contract extends Common
903 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 1000
         $receivablesModel = new Receivables();
911 1001
         $receivables = $receivablesModel->getMoneyByContractId($id);
912 1002
 
913 1003
         return [
914 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 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,7 +70,6 @@ class Customer extends Common
70 70
         $request    = $this->fmtRequest( $request );
71 71
         $requestMap = $request['map'] ? : [];
72 72
 		$sceneModel = new \app\admin\model\Scene();
73
-
74 73
 		# 客户默认条件
75 74
         $customerMap = $this->getWhereByCustomer();
76 75
 
@@ -105,11 +104,12 @@ class Customer extends Common
105 104
             unset($map['team_id']);
106 105
         }else{
107 106
             $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
107
+          
108 108
         }
109
+      
109 110
 		# 高级筛选
110 111
 		$map = advancedQuery($map, 'crm', 'customer', 'index');
111 112
 		
112
-		
113 113
         # 工作台仪表盘
114 114
         $requestData = $this->requestData();
115 115
         $dashboardWhere = [];
@@ -204,13 +204,16 @@ class Customer extends Common
204 204
         $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); // 地址类型字段
205 205
         $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); // 手写签名类型字段
206 206
         $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); // 定位类型字段
207
+        $boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
208
+        $floatField = $fieldModel->getFieldByFormType('crm_customer', 'floatnumber'); // 货币类型字段
207 209
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
208 210
         $temporaryField = str_replace('_name', '', $order_field);
209 211
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
210 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 217
 			$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
215 218
 		} else {
216 219
 			$order = 'customer.update_time desc';
@@ -229,7 +232,9 @@ class Customer extends Common
229 232
         		->limit($request['offset'], $request['length'])
230 233
         		->field($indexField)
231 234
         		->orderRaw($order)
235
+                // ->fetchSql()
232 236
 				->select();
237
+//	p(db('crm_customer')->getLastSql());
233 238
         $readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read');
234 239
         $updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update');
235 240
 		$deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete');
@@ -245,23 +250,37 @@ class Customer extends Common
245 250
 				])
246 251
 				->group('customer_id')
247 252
 				->select();
253
+    
248 254
 			$business_count = array_column($business_count, null, 'customer_id');
249 255
 			$field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id);
250 256
 			$field_list = array_column($field_list, 'field');
257
+   
251 258
 			# 扩展数据
252 259
             $extraData = [];
253 260
             $extraList = db('crm_customer_data')->whereIn('customer_id', $customer_id_list)->select();
254 261
             foreach ($extraList AS $key => $value) {
255 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 275
             $poolDays = $this->getPoolDay($customer_id_list);
259 276
             # 整理数据
260 277
 			foreach ($list AS $k => $v) {
278
+          
261 279
 	        	$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
262 280
 				$list[$k]['owner_user_id_info']  = isset($v['owner_user_id'])  ? $userModel->getUserById($v['owner_user_id'])  : [];
263 281
 				$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
264 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 285
 				foreach ($userField AS $key => $val) {
267 286
 					if (in_array($val, $indexField)) {
@@ -300,6 +319,31 @@ class Customer extends Common
300 319
                 // 定位类型字段
301 320
                 foreach ($locationField AS $key => $val) {
302 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 349
 				$list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0;
@@ -331,6 +375,9 @@ class Customer extends Common
331 375
                 # 进入公海天数
332 376
                 $list[$k]['pool_day'] = isset($poolDays[$v['customer_id']]) ? $poolDays[$v['customer_id']] : '';
333 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 383
         $data = [];
@@ -423,10 +470,11 @@ class Customer extends Common
423 470
         $locationField     = $fieldModel->getFieldByFormType('crm_customer', 'location');
424 471
         $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval');
425 472
         $detailTableField  = $fieldModel->getFieldByFormType('crm_customer', 'detail_table');
473
+        $dateField  = $fieldModel->getFieldByFormType('crm_customer', 'date');
426 474
         foreach ($param AS $key => $value) {
427 475
             // 处理地址类型字段数据
428 476
             if (in_array($key, $positionField)) {
429
-                if (!empty($value)) {
477
+                if (!empty($value) && is_array($value)) {
430 478
                     $customerData[] = [
431 479
                         'field'       => $key,
432 480
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
@@ -434,33 +482,45 @@ class Customer extends Common
434 482
                     ];
435 483
                     $positionNames = array_column($value, 'name');
436 484
                     $param[$key] = implode(',', $positionNames);
437
-                } else {
485
+                } elseif(!empty($value) && !is_array($value)){
486
+                    $param[$key] = $value;
487
+                }else{
438 488
                     $param[$key] = '';
439 489
                 }
440 490
             }
441 491
             // 处理定位类型字段数据
442 492
             if (in_array($key, $locationField)) {
443
-                if (!empty($value)) {
493
+                if (!empty($value) && isset($value['address'])) {
444 494
                     $customerData[] = [
445 495
                         'field'       => $key,
446 496
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
447 497
                         'create_time' => time()
448 498
                     ];
449 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 509
                     $param[$key] = '';
452 510
                 }
453 511
             }
454 512
             // 处理日期区间类型字段数据
455 513
             if (in_array($key, $dateIntervalField)) {
456
-                if (!empty($value)) {
514
+                if (!empty($value) && is_array($value)) {
457 515
                     $customerData[] = [
458 516
                         'field'       => $key,
459 517
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
460 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 524
                     $param[$key] = '';
465 525
                 }
466 526
             }
@@ -477,12 +537,26 @@ class Customer extends Common
477 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 556
         if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
484 557
         $pool_id = !empty($param['pool_id']) ? $param['pool_id'] : 0;
485 558
         unset($param['pool_id']);
559
+
486 560
         if ($this->data($param)->allowField(true)->isUpdate(false)->save()) {
487 561
             $data['customer_id'] = $this->customer_id;
488 562
             $data['name'] = $param['name'];
@@ -647,12 +721,14 @@ class Customer extends Common
647 721
             // 处理日期区间类型字段数据
648 722
             if (in_array($key, $dateIntervalField)) {
649 723
                 if (!empty($value)) {
724
+
650 725
                     $customerData[] = [
651 726
                         'field'       => $key,
652 727
                         'content'     => json_encode($value, JSON_NUMERIC_CHECK),
653 728
                         'create_time' => time()
654 729
                     ];
655
-                    $param[$key] = implode('_', $value);
730
+
731
+                    $param[$key] =implode('_',  $value);
656 732
                 } else {
657 733
                     $param[$key] = '';
658 734
                 }
@@ -671,7 +747,6 @@ class Customer extends Common
671 747
                 }
672 748
             }
673 749
         }
674
-
675 750
         // 设置今日需联系客户
676 751
         if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
677 752
 
@@ -709,13 +784,41 @@ class Customer extends Common
709 784
      * @throws \think\db\exception\ModelNotFoundException
710 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 789
 		$dataInfo = db('crm_customer')->where(['customer_id' => $id])->find();
715 790
 		if (!$dataInfo) {
716 791
 			$this->error = '数据不存在或已删除';
717 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 822
 		$userModel = new \app\admin\model\User();
720 823
 		$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
721 824
 		$dataInfo['owner_user_id_info'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@@ -1608,22 +1711,24 @@ class Customer extends Common
1608 1711
      */
1609 1712
     public function getNearbyList($param)
1610 1713
     {
1714
+        $apiCommon = new ApiCommon();
1611 1715
         $userModel = new \app\admin\model\User();
1612 1716
 
1613
-        # 客户条件
1717
+        $poolStatus = checkPerByAction('crm', 'customer', 'pool');
1718
+
1719
+        # 客户
1720
+        $customerAuth = [];
1614 1721
         $customerWhere = [];
1615
-        if (!empty($param['type']) && $param['type'] == 2) {
1722
+        if ((!empty($param['type']) && $param['type'] == 2) || !$poolStatus) {
1616 1723
             $customerWhere = $this->getWhereByCustomer();
1617 1724
         }
1618 1725
 
1619
-        # 公海条件
1726
+        # 公海
1620 1727
         $poolWhere = [];
1621
-        if (!empty($param['type']) && $param['type'] == 9) {
1728
+        if (!empty($param['type']) && $param['type'] == 9 && $poolStatus) {
1622 1729
             $poolWhere = ['customer.owner_user_id' => 0];
1623
-            $model = '公海客户管理模块';
1624 1730
         }
1625
-
1626
-        # 距离条件
1731
+        # 附近
1627 1732
         $lngLatRange = $this->getLngLatRange($param['lng'], $param['lat'], $param['distance']);
1628 1733
         $lngLatWhere = function ($query) use ($lngLatRange) {
1629 1734
             $query->where(['lng' => ['egt', $lngLatRange['minLng']]]);
@@ -1643,23 +1748,31 @@ class Customer extends Common
1643 1748
             ->where($customerWhere)
1644 1749
             ->where($poolWhere)
1645 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 1753
             ->order('update_time', 'desc')
1648 1754
             ->select();
1649 1755
 
1650 1756
         # 组装数据
1651 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 1760
             $ownerUserName = !empty($ownerUserInfo['realname']) ? $ownerUserInfo['realname'] : '';
1654 1761
             $list[$key]['owner_user_name'] = !empty($ownerUserName) ? $ownerUserName : '暂无负责人';
1655 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 1772
         return ['list' => $list, 'count' => $count];
1661 1773
     }
1662 1774
 
1775
+
1663 1776
     /**
1664 1777
      * 计算两点地理坐标之间的距离
1665 1778
      *
@@ -1737,9 +1850,15 @@ class Customer extends Common
1737 1850
         $customer = Db::name('crm_customer')->field($field)->where('customer_id', $id)->find();
1738 1851
         # 创建人
1739 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 1862
         return [
1744 1863
             'obtain_time' => !empty($customer['obtain_time']) ? date('Y-m-d H:i:s', $customer['obtain_time']) : '',
1745 1864
             'last_record' => !empty($customer['last_record']) ? $customer['last_record'] : '',
@@ -1748,7 +1867,8 @@ class Customer extends Common
1748 1867
             'create_time' => date('Y-m-d H:i:s', $customer['create_time']),
1749 1868
             'update_time' => date('Y-m-d H:i:s', $customer['update_time']),
1750 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,4 +51,97 @@ class Invoice extends Common
51 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,6 +112,8 @@ class Leads extends Common
112 112
         $positionField = $fieldModel->getFieldByFormType('crm_leads', 'position'); // 地址类型字段
113 113
         $handwritingField = $fieldModel->getFieldByFormType('crm_leads', 'handwriting_sign'); // 手写签名类型字段
114 114
         $locationField = $fieldModel->getFieldByFormType('crm_leads', 'location'); // 定位类型字段
115
+        $boxField = $fieldModel->getFieldByFormType('crm_leads', 'checkbox'); // 多选类型字段
116
+        $floatField = $fieldModel->getFieldByFormType('crm_leads', 'floatnumber'); // 货币类型字段
115 117
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
116 118
         $temporaryField = str_replace('_name', '', $order_field);
117 119
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@@ -153,7 +155,6 @@ class Leads extends Common
153 155
             ->field(implode(',', $indexField))
154 156
             ->orderRaw($order)
155 157
             ->select();
156
-//        echo db('crm_leads')->getLastSql();exit;
157 158
         # 扩展数据
158 159
         $extraData = [];
159 160
         $leads_id_list = !empty($list) ? array_column($list, 'leads_id') : [];
@@ -161,6 +162,17 @@ class Leads extends Common
161 162
         foreach ($extraList AS $key => $value) {
162 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 176
         foreach ($list as $k => $v) {
165 177
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
166 178
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@@ -197,6 +209,36 @@ class Leads extends Common
197 209
             foreach ($locationField AS $key => $val) {
198 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 243
             $permission = [];
202 244
             $is_read = 0;
@@ -217,6 +259,9 @@ class Leads extends Common
217 259
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
218 260
             $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
219 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 266
         $data = [];
222 267
         $data['list'] = $list;
@@ -362,7 +407,7 @@ class Leads extends Common
362 407
                 'type'             => 2,
363 408
                 'activity_type'    => 1,
364 409
                 'activity_type_id' => $this->leads_id,
365
-                'content'          => $param['name'],
410
+                'content'          => $param['name']?:'',
366 411
                 'create_user_id'   => $param['create_user_id'],
367 412
                 'update_time'      => time(),
368 413
                 'create_time'      => time(),
@@ -542,7 +587,7 @@ class Leads extends Common
542 587
      * @throws \think\db\exception\ModelNotFoundException
543 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 592
         $map['leads_id'] = $id;
548 593
         $dataInfo = db('crm_leads')->where($map)->find();
@@ -550,6 +595,35 @@ class Leads extends Common
550 595
             $this->error = '暂无此数据';
551 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 627
         $userModel = new \app\admin\model\User();
554 628
         $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
555 629
         $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@@ -592,19 +666,28 @@ class Leads extends Common
592 666
      * @throws \think\db\exception\ModelNotFoundException
593 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 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 684
         return [
604 685
             'create_user_id' => $realname,
686
+            'owner_user_id' => $ownerUserName,
605 687
             'create_time' => date('Y-m-d H:i:s', $leads['create_time']),
606 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,6 +107,9 @@ class Product extends Common
107 107
         $positionField = $fieldModel->getFieldByFormType('crm_product', 'position'); // 地址类型字段
108 108
         $handwritingField = $fieldModel->getFieldByFormType('crm_product', 'handwriting_sign'); // 手写签名类型字段
109 109
         $locationField = $fieldModel->getFieldByFormType('crm_product', 'location'); // 定位类型字段
110
+        $boxField = $fieldModel->getFieldByFormType('crm_product', 'checkbox'); // 多选类型字段
111
+        $floatField = $fieldModel->getFieldByFormType('crm_product', 'floatnumber'); // 货币类型字段
112
+
110 113
         # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
111 114
         $temporaryField = str_replace('_name', '', $order_field);
112 115
         if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@@ -142,6 +145,16 @@ class Product extends Common
142 145
         foreach ($extraList AS $key => $value) {
143 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 158
         foreach ($list as $k => $v) {
146 159
             $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
147 160
             $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@@ -178,11 +191,39 @@ class Product extends Common
178 191
             foreach ($locationField AS $key => $val) {
179 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 220
             $list[$k]['category_id_info'] = $v['category_name'];
183 221
             # 处理日期格式
184 222
             $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
185 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 228
         $data = [];
188 229
         $data['list'] = $list;
@@ -503,7 +544,7 @@ class Product extends Common
503 544
      * @throws \think\db\exception\ModelNotFoundException
504 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 549
         $map['product_id'] = $id;
509 550
         $map['delete_user_id'] = 0;
@@ -512,7 +553,35 @@ class Product extends Common
512 553
             $this->error = '暂无此数据';
513 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 586
         $dataInfo['cover_images'] = $this->getProductImages($dataInfo['cover_images']);
518 587
         # 获取详情图片
@@ -947,14 +1016,25 @@ class Product extends Common
947 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 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 1032
         return [
955 1033
             'create_user_id' => $realname,
1034
+            'owner_user_id' => $ownerUserName,
956 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,8 +120,9 @@ class ProductCategory extends Common
120 120
 		if (db('crm_product')->where(['category_id' => $param['id']])->find()) {
121 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 126
 			if($childIds){
126 127
 				if (db('crm_product')->where(['category_id' => ['in',$childIds]])->find()) {
127 128
 					$resDel = false;
@@ -132,6 +133,7 @@ class ProductCategory extends Common
132 133
 			$this->error = '请先移除该类型及子类下的相关产品';
133 134
 			return false;			
134 135
 		}
136
+
135 137
         $data=db('crm_product_category')->where('category_id' , $param['id'])->find();
136 138
 		//提交事务
137 139
 		$this->startTrans();
@@ -145,7 +147,7 @@ class ProductCategory extends Common
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 151
             $this->commit();
150 152
 			return true;
151 153
 		} catch(\Exception $e) {

+ 130
- 51
application/crm/model/Receivables.php 파일 보기

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

+ 1
- 1
application/oa/model/Event.php 파일 보기

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

+ 9
- 3
application/oa/model/Log.php 파일 보기

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

+ 3
- 1
config/route_crm.php 파일 보기

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

+ 2
- 2
config/version.php 파일 보기

@@ -1,5 +1,5 @@
1 1
 <?php
2 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,6 +261,7 @@ INSERT INTO `5kcrm_admin_field` VALUES (14, 'crm_customer', 0, 'name', '客户
261 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 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 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 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 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 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,45 +1600,44 @@ CREATE TABLE `5kcrm_crm_contract_product`  (
1599 1600
 -- Table structure for 5kcrm_crm_customer
1600 1601
 -- ----------------------------
1601 1602
 DROP TABLE IF EXISTS `5kcrm_crm_customer`;
1602
-CREATE TABLE `5kcrm_crm_customer`  (
1603
+CREATE TABLE `5kcrm_crm_customer` (
1603 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 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 1615
   `create_user_id` int(11) NOT NULL COMMENT '创建人ID',
1615 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 1627
   `create_time` int(11) NOT NULL COMMENT '创建时间',
1627 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 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 1642
 -- Records of 5kcrm_crm_customer
1643 1643
 -- ----------------------------

+ 5
- 0
public/sql/update_sql_20210903.sql 파일 보기

@@ -0,0 +1,5 @@
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,10 +88,10 @@ $('.next').click(function () {
88 88
             localStorage.clear();
89 89
             window.location = 'step5.html';
90 90
           } else if (result.code == '400') {
91
-            alert(result.error);
91
+            // alert(result.error);
92 92
             window.location.href = 'step6.html';
93 93
           } else {
94
-            alert(result.error);
94
+            // alert(result.error);
95 95
             window.location.href = 'step6.html';
96 96
           }
97 97
         },

+ 5
- 0
update_sql_20210903.sql 파일 보기

@@ -0,0 +1,5 @@
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
+