| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 | <?phpnamespace 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));            $employee_id = array_unique($fz_id);            $wx_map = WxEmployeeOfficial::whereIn('employee_id', $employee_id)                ->pluck('openid','employee_id')                ->toArray();            $send_data = $insert = [];            $customer_id = [];            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,                    ];                    $customer_id[] = $value['customer_id'];                }                $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;                if(empty($open_id_fz)) 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);            }            $c_id = array_column($data,'customer_id');            //清空分配门店            SeeRange::where('del_time',0)                ->whereIn('data_id', $c_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]);            if(! empty($customer_id)) 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'];            }        }    }}
 |