87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
|
|
|
|
namespace Yunshop\Commission\Jobs;
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Yunshop\Commission\admin\model\Agents;
|
|
use Yunshop\Commission\admin\model\MemberShopInfo;
|
|
|
|
class DataIdenticalJob implements ShouldQueue
|
|
{
|
|
|
|
use InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $uniacid;
|
|
|
|
public function __construct($uniacid)
|
|
{
|
|
$this->uniacid = $uniacid;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
ini_set("memory_limit","-1");
|
|
$uniacid = $this->uniacid;
|
|
// 获取需要操作的会员
|
|
$members = MemberShopInfo::select(['yz_member.uniacid','yz_member.parent_id','yz_member.member_id','yz_member.relation','yz_member.agent_time'])
|
|
->withoutGlobalScopes()
|
|
->leftJoin('yz_agents', function ($join)use($uniacid) {
|
|
$join->on('yz_member.member_id', '=', 'yz_agents.member_id')
|
|
->where('yz_member.uniacid',$uniacid)
|
|
// ->on('yz_member.uniacid', '=', 'yz_agents.uniacid')
|
|
;
|
|
})
|
|
->where('yz_member.status','=',2)
|
|
->where('yz_member.is_agent','=',1)
|
|
->where('yz_member.uniacid','=',$this->uniacid)
|
|
->whereNull('yz_agents.member_id')
|
|
->get();
|
|
|
|
\Log::debug("分销数据同步");
|
|
if (empty($members)) {
|
|
return ;
|
|
}
|
|
$insert_data = [];
|
|
|
|
|
|
$members->each(function ($v)use(&$insert_data){
|
|
$insert_data[] = [
|
|
'uniacid'=>$v->uniacid,
|
|
'parent_id'=>$v->parent_id,
|
|
'member_id'=>$v->member_id,
|
|
'parent'=>$v->relation,
|
|
'created_at'=>$v->agent_time,
|
|
];
|
|
});
|
|
|
|
$insert_data = array_chunk($insert_data, 2000);
|
|
foreach ($insert_data as &$insert) {
|
|
Agents::insert($insert);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// // 将会员数据增加到代理表
|
|
// foreach ($members as $member) {
|
|
// $insert_data[] = [
|
|
// 'uniacid'=>$member->uniacid,
|
|
// ];
|
|
// $arrMember = $member->toArray();
|
|
// $arrAgent['uniacid'] = $arrMember['uniacid'];
|
|
// $arrAgent['parent_id'] = $arrMember['parent_id'];
|
|
// $arrAgent['member_id'] = $arrMember['member_id'];
|
|
// $arrAgent['parent'] = $arrMember['relation'];
|
|
// $arrAgent['created_at'] = $arrMember['agent_time'];
|
|
// $agent = new Agents();
|
|
// $agent->fill($arrAgent);
|
|
// $agent->save();
|
|
// }
|
|
}
|
|
} |