| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Jobs;
- use App\Models\Mysql\AgentModel;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- class AgentUpdateChildUidsByAllParentUidsJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * 构造入参.
- * @var array|mixed
- */
- private $params = [];
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($params = [])
- {
- $this->params = $params;
- }
- /**
- * 遍历所有上级的每个对象的字段child_uids,重新更新child_uids内容.
- *
- * @return mixed|void
- */
- public function handle()
- {
- $currUid = $this->params['uid'];
- $agentModel = new AgentModel();
- $item = AgentModel::query()->where(['uid' => $currUid])->first(['id', 'uid', 'parent_uid', 'parent_uids']);
- $strParentUids = $item->parent_uids;
- $arrParentUids = !empty($strParentUids) ? explode(',', $strParentUids) : [];
- if (!empty($arrParentUids)) {
- foreach ($arrParentUids as $parentUid) {
- $tmpObj = AgentModel::query()->where(['uid' => $parentUid])->first(['id', 'uid', 'child_uids']);
- $arrChildUids = $agentModel->findAllChildUids($parentUid);
- $strChildUids = !empty($arrChildUids) ? implode(',', $arrChildUids) : '';
- $tmpObj->child_uids = $strChildUids;
- $tmpObj->save();
- }
- }
- }
- /**
- * 任务失败的处理过程.
- * @param null $exception
- */
- public function fail($exception = null)
- {
- // 失败后的处理,比如发送通知.
- }
- /**
- * 通知.
- */
- private function notify()
- {
- // Todo 发送通知.
- }
- }
|