| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\jobs;
- use app\models\StoreMini;
- use app\modules\admin\models\VideoShopForm;
- use app\modules\admin\models\VideoShopOrderForm;
- use app\utils\Wechat\WechatMini;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- use app\models\Store;
- use app\modules\admin\models\publicRanking\PublicRankingForm;
- /**
- * 同步微信视频号小店 商品 订单 分享员
- */
- class SyncSharerListJob extends BaseObject implements JobInterface
- {
- public $store_id;
- public $type = 0;//0分享员 1商品 2订单 3达人
- public function execute($queue)
- {
- $time = time();
- $type = intval($this->type);
- if (!in_array($type, [0, 1, 2, 3])) {
- return;
- }
- $storeList = [];
- if(is_null($this->store_id)){
- $storeList = Store::find()->where(['is_delete' => 0])->andWhere(['OR', ['>', 'end_time', $time], ['<=', 'end_time', '0']])->select('id')->column();//只查询未到期的店铺
- }else{
- $store = Store::findOne($this->store_id);
- if ($store->end_time > $time || $store->end_time <= 0) {
- $storeList = [$this->store_id];
- }
- }
- foreach ($storeList as $store_id){
- $base_ = new WechatMini();
- $store_mini = StoreMini::find()->where(['store_id' => $store_id, 'fuwu_type' => 1, 'is_cancle' => 0])->select('id')->column();
- foreach ($store_mini as $mini_item) {
- $miniProgram = $base_::getWechatConfig($store_id, $mini_item, 1);
- if ($miniProgram) {
- if (in_array($type, [0, 2])) {
- $form = new VideoShopForm();
- $form->miniProgram = $miniProgram;
- $form->store_id = $store_id;
- $form->mini_id = $base_::$mini_id;
- $form->getApplySharerInfo();
- $form->syncSharerList();
- }
- if ($type === 1) {
- $goods_form = new \app\modules\admin\models\VideoShopGoodsForm();
- $goods_form->miniProgram = $miniProgram;
- $goods_form->store_id = $store_id;
- $goods_form->mini_id = $base_::$mini_id;
- $goods_form->syncGoodsList();
- }
- if ($type === 2) {
- $form_ = new VideoShopOrderForm();
- $form_->miniProgram = $miniProgram;
- $form_->store_id = $store_id;
- $form_->mini_id = $base_::$mini_id;
- $form_->end_time = time();
- $form_->start_time = time() - (60 * 60 * 24 * 2);
- $form_->syncOrderList();
- }
- if ($type === 3) {
- PublicRankingForm::syncPromoter($store_id);
- }
- }
- }
- }
- debug_log(['SyncSharerListJob--end', time() - $time], 'debug_task_execute.log');
- }
- }
|