cqp преди 2 месеца
родител
ревизия
d3a051f4fc
променени са 5 файла, в които са добавени 230 реда и са изтрити 21 реда
  1. 136 0
      app/Console/Commands/CustomerRemain.php
  2. 11 0
      app/Model/CustomerRemain.php
  3. 70 15
      app/Service/ImportService.php
  4. 8 5
      app/Service/OaService.php
  5. 5 1
      config/excel/customerTable.php

+ 136 - 0
app/Console/Commands/CustomerRemain.php

@@ -0,0 +1,136 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Model\Customer;
+use App\Model\Depart;
+use App\Model\SeeRange;
+use App\Model\WxEmployeeOfficial;
+use App\Model\CustomerRemain as CrModel;
+use App\Service\OaService;
+use Illuminate\Console\Command;
+
+class CustomerRemain extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'command:customer_remain';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        echo '发送提醒--------start---------------';
+
+        $time = time();
+        $data = CrModel::where("del_time",0)
+            ->select('id','customer_id','fp','fz')
+            ->get()->toArray();
+        if(! empty($data)){
+            $fp_id = array_unique(array_column($data,'fp'));
+            $depart = Depart::where("del_time",0)
+                ->whereIn("id", $fp_id)
+                ->select('id','notify_id')
+                ->get()->toArray();
+            $depart_map = array_column($depart,'notify_id','id');
+            $fp_man_id = array_filter(array_unique(array_column($depart,'notify_id')));
+            $fz_id = array_unique(array_column($data,'fz'));
+            $employee_id = array_unique(array_merge($fp_man_id, $fz_id));
+            $wx_map = WxEmployeeOfficial::whereIn('employee_id', $employee_id)
+                ->pluck('openid','employee_id')
+                ->toArray();
+            $send_data = $insert = [];
+            foreach ($data as $value){
+                if(! empty($value['fp'])) {
+                    $insert[] = [
+                        'data_id' => $value['customer_id'], //客户id
+                        'data_type' => SeeRange::type_one,
+                        'param_id' => $value['fp'], //门店id
+                        'type' => SeeRange::data_three,
+                        'crt_time' => $time,
+                    ];
+                }
+
+                $open_id_fz = $wx_map[$value['fz']] ?? "";
+                $fp_man_t = $depart_map[$value['fp']] ?? 0;
+                $open_id_fp = $wx_map[$fp_man_t] ?? "";
+                //负责人 和 门店负责人都为空跳过
+                if(empty($open_id_fz) && empty($open_id_fp)) continue;
+                //组织发送
+                $this->makeData($send_data, $open_id_fz, $value);
+                $this->makeData($send_data, $open_id_fp, $value);
+            }
+            if(! empty($send_data)){
+                echo "发送中\n";
+                $send_data = array_values($send_data);
+                (new OaService())->sendWxOaCheckMessage($send_data, 1);
+            }
+
+            $customer_id = array_column($data,'customer_id');
+            //清空分配门店
+            SeeRange::where('del_time',0)
+                ->whereIn('data_id', $customer_id)
+                ->where('data_type',SeeRange::type_one)
+                ->where('type',SeeRange::data_three)
+                ->update(['del_time' => $time]);
+            //分配门店
+            if(! empty($insert)) SeeRange::insert($insert);
+            //更新单据
+            CrModel::whereIn('id',array_column($data,'id'))
+                ->update(['del_time' => $time]);
+            Customer::whereIn('id', $customer_id)->update(['fp_time' => $time]);
+        }else{
+            echo "暂无\n";
+        }
+
+        echo '发送提醒--------end---------------';
+    }
+
+    private function makeData(&$send_data, $open_id, $value){
+        if(! empty($open_id)) {
+            if(! isset($send_data[$open_id])){
+                $send_data[$open_id] = [
+                    'employee_id' => 12343215,
+                    'type' => 2,
+                    'state' => 0,
+                    'menu_id' => "16|list",
+                    'openid' => $open_id,
+                    'order_number' => $value['customer_id'],
+                    'tmp_data' => [
+                        time(),
+                        "客资分配提醒",
+                        "已分配",
+                        "T9品牌中心",
+                        date('Y-m-d H:i:s'),
+                    ],
+                ];
+            }else{
+                $tmp = explode(',', $send_data[$open_id]['order_number']);
+                if(! in_array($value['customer_id'], $tmp)) $send_data[$open_id]['order_number'] .= ',' . $value['customer_id'];
+            }
+        }
+    }
+}

+ 11 - 0
app/Model/CustomerRemain.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Model;
+
+class CustomerRemain extends UseScopeBaseModel
+{
+    protected $table = "customer_remain"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+}

+ 70 - 15
app/Service/ImportService.php

@@ -9,6 +9,7 @@ use App\Model\BasicType;
 use App\Model\BasicTypeAllUse;
 use App\Model\Customer;
 use App\Model\CustomerInfo;
+use App\Model\CustomerRemain;
 use App\Model\CustomerRepeat;
 use App\Model\Depart;
 use App\Model\Employee;
@@ -313,7 +314,7 @@ class ImportService extends Service
         //第一次表格数据校验 非空  已经过滤数据
         list($status, $msg) = $this->customerFilterFirst($array, $time);
         if(! $status) return [0, $msg];
-        $contact_info = $msg;
+        list($contact_info, $fz, $fp) = $msg;
 
         if(empty($array)) return [false, '导入数据不能为空'];
 
@@ -358,9 +359,25 @@ class ImportService extends Service
             ->pluck('id','title')
             ->toArray();
 
-        $emp = Employee::where('del_time',0)
-            ->whereIn('number',array_unique(array_column($array,'13')))
-            ->pluck('id','number')
+        $empList = Employee::where('del_time',0)
+            ->when(! empty($fz), function($query) use($fz) {
+                return $query->where(function ($q) use ($fz) {
+                    $q->whereIn('emp_name', $fz)
+                        ->orWhereIn("number", $fz);
+                });
+            })
+            ->select('id','number','emp_name as name')
+            ->get()->toArray();
+        $emp_map = $emp_map1 = [];
+        foreach ($empList as $value){
+            $emp_map[$value['name']][] = $value['id'];
+            $emp_map1[$value['number']] = $value['id'];
+        }
+
+        $depart = Depart::where('del_time',0)
+            ->where('parent_id', 0)
+            ->whereIn('title', $fp)
+            ->pluck('title','id')
             ->toArray();
 
         $top_depart_id = $user['depart_top'][0] ?? [];
@@ -374,9 +391,9 @@ class ImportService extends Service
             ->select('a.contact_info')->get()->toArray();
         $contact_info_array = array_column($contact_info_array,'contact_info');
 
-        list($status, $msg) = $this->customerFilterSecond($array,$time,$head,$user,$contact_info_array,$customer,$basic_list,$emp,$basic_use);
+        list($status, $msg) = $this->customerFilterSecond($array,$time,$head,$user,$contact_info_array,$customer,$basic_list,$emp_map,$emp_map1,$basic_use,$depart);
         if(! $status) return [0, $msg];
-        list($insert, $insert_detail, $insert_detail2) = $msg;
+        list($insert, $insert_detail, $insert_detail2,$insert_detail3) = $msg;
 
         try{
             DB::beginTransaction();
@@ -404,9 +421,15 @@ class ImportService extends Service
                 $value['customer_id'] = $last_insert_id[$key];
                 $insert_detail_2[] = $value;
             }unset($insert_detail2);
+            $insert_detail_3 = [];
+            foreach ($insert_detail3 as $key => $value){
+                $value['customer_id'] = $last_insert_id[$key];
+                $insert_detail_3[] = $value;
+            }unset($insert_detail3);
 
             if(! empty($insert_detail_1)) CustomerInfo::insert($insert_detail_1);
             if(! empty($insert_detail_2)) CustomerInfo::insert($insert_detail_2);
+            if(! empty($insert_detail_3)) CustomerRemain::insert($insert_detail_3);
 
             DB::commit();
         }catch (\Exception $e){
@@ -418,7 +441,7 @@ class ImportService extends Service
     }
 
     function customerFilterFirst(&$array, $time){
-        $array_clean = $contact_info = [];
+        $array_clean = $contact_info = $fz = $fp =[];
 
         $error = [];
         foreach ($array as $key => $value){
@@ -458,6 +481,12 @@ class ImportService extends Service
                     }
                 }
 
+                if(empty($value[13])) {
+                    $error[] = $line . '负责人名或负责人工号必须填写';
+                }else{
+                    if(! in_array($value[13], $fz)) $fz[] = $value[13];
+                }
+
                 if(! empty($value[14])){
                     list($status, $msg) = $this->convertExcelCellToDate($value[14]);
                     if(! $status) {
@@ -469,6 +498,12 @@ class ImportService extends Service
                     $value[14] = $time;
                 }
 
+                if(empty($value[15])) {
+                    $error[] = $line . '分配门店必须填写';
+                }else{
+                    if(! in_array($value[15], $fp)) $fp[] = $value[15];
+                }
+
                 $array[$key] = $value;
             }
         }unset($array_clean);
@@ -478,11 +513,11 @@ class ImportService extends Service
             return [false, $error];
         }
 
-        return [true, $contact_info];
+        return [true, [$contact_info, $fz, $fp]];
     }
 
-    function customerFilterSecond($array, $time, $head, $user, $contact_info_array,$customer,$basic_list,$emp,$basic_use){
-        $error = $insert = $insert_detail = $insert_detail2 = $repeat_array = [];
+    function customerFilterSecond($array, $time, $head, $user, $contact_info_array,$customer,$basic_list,$emp_name,$emp_number,$basic_use,$depart){
+        $error = $insert = $insert_detail = $insert_detail2 = $insert_detail3 = $repeat_array = [];
         foreach ($array as $key => $value){
             $line = '第' . $key . '行';
             $tmp = [
@@ -587,12 +622,26 @@ class ImportService extends Service
                 $error[] = $line . '联系方式内容:' . $value['12'] . '已存在';
             }
             $man = 0;
-            if($value['13']){
-                if(empty($emp[$value['13']])) {
-                    $error[] = $line . '负责人:' . $value['13'] . '不存在';
+            if(! empty($emp_name[$value['13']])){
+                $name = $emp_name[$value['13']];
+                if(count($name) > 1) {
+                    $error[] = $line . '负责人名:' . $value['13'] . '在系统中多次出现,请填写工号精准定位负责人';
                 }else{
-                    $man = $emp[$value['13']];
+                    $man = $name[0];
                 }
+            }else{
+                if(! empty($emp_number[$value['13']])){
+                    $man = $emp_number[$value['13']];
+                }else{
+                    $error[] = $line . '负责人工号:' . $value['13'] . '不存在';
+                }
+            }
+
+            $fp = 0;
+            if(empty($depart[$value['15']])) {
+                $error[] = $line . '分配门店:' . $value['15'] . '不存在';
+            }else{
+                $fp = $depart[$value['15']];
             }
 
             $insert[] = $tmp;
@@ -609,6 +658,12 @@ class ImportService extends Service
                 'crt_time' => $time,
                 'type' => CustomerInfo::type_two
             ];
+            $insert_detail3[] = [
+                'customer_id' => 0,
+                'fp' => $fp,
+                'fz' => $man,
+                'crt_time' => $time,
+            ];
             if($repeat){
                 $tmp['contact_type'] = $contact_id;
                 $tmp['contact'] = $value['12'];
@@ -625,7 +680,7 @@ class ImportService extends Service
             return [false, $error];
         }
 
-        return [true, [$insert, $insert_detail, $insert_detail2]];
+        return [true, [$insert, $insert_detail, $insert_detail2, $insert_detail3]];
     }
 
     function convertExcelCellToDate($cellValue) {

+ 8 - 5
app/Service/OaService.php

@@ -904,7 +904,7 @@ class OaService extends Service
     }
 
     //发送公众号消息
-    public function sendWxOaCheckMessage($send_data){
+    public function sendWxOaCheckMessage($send_data, $type = 0){
         if(empty($send_data)) return ;
         $config = config('morequery');
         $path = $config['detail_message'] ?? [];
@@ -917,7 +917,7 @@ class OaService extends Service
             $menu_id = $this->getSubstringBeforePipe($value['menu_id']);
 
             //发送
-            $this->sendWxMsg($value['employee_id'],$value['type'],$value['state'],$menu_id,$value['tmp_data'],$tmp_path,$openid);
+            $this->sendWxMsg($value['employee_id'],$value['type'],$value['state'],$menu_id,$value['tmp_data'],$tmp_path,$openid,$type);
         }
     }
 
@@ -1222,11 +1222,14 @@ class OaService extends Service
         return [true,['time'=>'20小时10分钟']];
     }
 
-    public function sendWxMsg($user_id,$type,$state,$menu_id,$order_data,$pagepath = "", $openid = ""){
+    public function sendWxMsg($user_id,$type,$state,$menu_id,$order_data,$pagepath = "", $openid = "",$m_type = 0){
+        $filename = $m_type ? 'msg_result1_txt' : 'msg_result.txt';
+        $filepath = storage_path("logs/{$filename}");
+
         $service = new WxSendMessageService();
-        file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "入参:" . json_encode([$user_id,$type,$state,$menu_id,$order_data,$pagepath]). PHP_EOL,8);
+        file_put_contents($filepath,date('Y-m-d H:i:s') . "入参:" . json_encode([$user_id,$type,$state,$menu_id,$order_data,$pagepath]). PHP_EOL,8);
         list($status, $msg) = $service->wx_sendMsg($user_id,$type,$state,$menu_id,$order_data,$pagepath,$openid);
-        file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "结果:" .  $msg . PHP_EOL,8);
+        file_put_contents($filepath,date('Y-m-d H:i:s') . "结果:" .  $msg . PHP_EOL,8);
     }
 
     public function getConstructionOaOrderState($order_no, $user, $menu_id)

+ 5 - 1
config/excel/customerTable.php

@@ -58,7 +58,7 @@ return [
     ],
     [
         'key' =>'man_fz_number',
-        'value' =>'负责人工号',
+        'value' =>'负责人名或工号',
     ],
     [
         'key' =>'enter_time',
@@ -68,4 +68,8 @@ return [
 //        'key' =>'man_xt',
 //        'value' =>'协同人',
 //    ],
+    [
+        'key' =>'fp',
+        'value' => '分配门店',
+    ],
 ];