|
|
@@ -3,12 +3,14 @@
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
use App\Model\Customer;
|
|
|
+use App\Model\CustomerAccessFlat;
|
|
|
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;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class CustomerRemain extends Command
|
|
|
{
|
|
|
@@ -94,6 +96,20 @@ class CustomerRemain extends Command
|
|
|
}
|
|
|
|
|
|
$c_id = array_column($data,'customer_id');
|
|
|
+ $top_depart_id_map = Customer::whereIn('id', $c_id)->pluck('top_depart_id','id')->all();
|
|
|
+
|
|
|
+ $see_id = SeeRange::where('del_time',0)
|
|
|
+ ->whereIn('data_id', $c_id)
|
|
|
+ ->where('data_type',SeeRange::type_one)
|
|
|
+ ->where('type',SeeRange::data_three)
|
|
|
+ ->pluck('id')
|
|
|
+ ->all();
|
|
|
+ if(! empty($see_id)) {
|
|
|
+ CustomerAccessFlat::where('source_type', CustomerAccessFlat::source_type_two)
|
|
|
+ ->whereIn('source_id', $see_id)
|
|
|
+ ->delete();
|
|
|
+ }
|
|
|
+
|
|
|
//清空分配门店
|
|
|
SeeRange::where('del_time',0)
|
|
|
->whereIn('data_id', $c_id)
|
|
|
@@ -101,7 +117,23 @@ class CustomerRemain extends Command
|
|
|
->where('type',SeeRange::data_three)
|
|
|
->update(['del_time' => $time]);
|
|
|
//分配门店
|
|
|
- if(! empty($insert)) SeeRange::insert($insert);
|
|
|
+ if(! empty($insert)) {
|
|
|
+ SeeRange::insert($insert);
|
|
|
+
|
|
|
+ // 新增
|
|
|
+ $insertArray2 = SeeRange::whereIn('data_id', $c_id)
|
|
|
+ ->where('crt_time', $time)
|
|
|
+ ->where('type', SeeRange::data_three)
|
|
|
+ ->where('data_type', SeeRange::type_one)
|
|
|
+ ->select('id as source_id',DB::raw(CustomerAccessFlat::source_type_two .' as source_type'), 'data_id as customer_id','param_id as target_id',DB::raw(CustomerAccessFlat::type_three .' as type'))
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ foreach ($insertArray2 as $key => $value){
|
|
|
+ $insertArray2[$key]['top_depart_id'] = $top_depart_id_map[$value['customer_id']];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($insertArray2)) CustomerAccessFlat::insert($insertArray2);
|
|
|
+ }
|
|
|
//更新单据
|
|
|
CrModel::whereIn('id',array_column($data,'id'))
|
|
|
->update(['del_time' => $time]);
|