SyncSharerListJob.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\jobs;
  3. use app\models\StoreMini;
  4. use app\modules\admin\models\VideoShopForm;
  5. use app\modules\admin\models\VideoShopOrderForm;
  6. use app\utils\Wechat\WechatMini;
  7. use yii\base\BaseObject;
  8. use yii\queue\JobInterface;
  9. use app\models\Store;
  10. use app\modules\admin\models\publicRanking\PublicRankingForm;
  11. /**
  12. * 同步微信视频号小店 商品 订单 分享员
  13. */
  14. class SyncSharerListJob extends BaseObject implements JobInterface
  15. {
  16. public $store_id;
  17. public $type = 0;//0分享员 1商品 2订单 3达人
  18. public function execute($queue)
  19. {
  20. $time = time();
  21. $type = intval($this->type);
  22. if (!in_array($type, [0, 1, 2, 3])) {
  23. return;
  24. }
  25. $storeList = [];
  26. if(is_null($this->store_id)){
  27. $storeList = Store::find()->where(['is_delete' => 0])->andWhere(['OR', ['>', 'end_time', $time], ['<=', 'end_time', '0']])->select('id')->column();//只查询未到期的店铺
  28. }else{
  29. $store = Store::findOne($this->store_id);
  30. if ($store->end_time > $time || $store->end_time <= 0) {
  31. $storeList = [$this->store_id];
  32. }
  33. }
  34. foreach ($storeList as $store_id){
  35. $base_ = new WechatMini();
  36. $store_mini = StoreMini::find()->where(['store_id' => $store_id, 'fuwu_type' => 1, 'is_cancle' => 0])->select('id')->column();
  37. foreach ($store_mini as $mini_item) {
  38. $miniProgram = $base_::getWechatConfig($store_id, $mini_item, 1);
  39. if ($miniProgram) {
  40. if (in_array($type, [0, 2])) {
  41. $form = new VideoShopForm();
  42. $form->miniProgram = $miniProgram;
  43. $form->store_id = $store_id;
  44. $form->mini_id = $base_::$mini_id;
  45. $form->getApplySharerInfo();
  46. $form->syncSharerList();
  47. }
  48. if ($type === 1) {
  49. $goods_form = new \app\modules\admin\models\VideoShopGoodsForm();
  50. $goods_form->miniProgram = $miniProgram;
  51. $goods_form->store_id = $store_id;
  52. $goods_form->mini_id = $base_::$mini_id;
  53. $goods_form->syncGoodsList();
  54. }
  55. if ($type === 2) {
  56. $form_ = new VideoShopOrderForm();
  57. $form_->miniProgram = $miniProgram;
  58. $form_->store_id = $store_id;
  59. $form_->mini_id = $base_::$mini_id;
  60. $form_->end_time = time();
  61. $form_->start_time = time() - (60 * 60 * 24 * 2);
  62. $form_->syncOrderList();
  63. }
  64. if ($type === 3) {
  65. PublicRankingForm::syncPromoter($store_id);
  66. }
  67. }
  68. }
  69. }
  70. debug_log(['SyncSharerListJob--end', time() - $time], 'debug_task_execute.log');
  71. }
  72. }