MemberAddupVipJob.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dingran
  5. * Date: 2018/11/4
  6. * Time: 下午3:44
  7. */
  8. namespace app\Jobs;
  9. use app\common\models\member\ParentOfMember;
  10. use Illuminate\Bus\Queueable;
  11. use Illuminate\Contracts\Queue\ShouldQueue;
  12. use Illuminate\Queue\InteractsWithQueue;
  13. use Illuminate\Queue\SerializesModels;
  14. use Illuminate\Support\Facades\DB;
  15. use Yunshop\Mryt\models\MrytMemberAddUpVipModel;
  16. use Yunshop\Mryt\models\MrytMemberModel;
  17. class MemberAddupVipJob implements ShouldQueue
  18. {
  19. use InteractsWithQueue, Queueable, SerializesModels;
  20. protected $uid;
  21. protected $uniacid;
  22. protected $curr_date;
  23. public $MrytMemberAddUpVipModel;
  24. public $parentMemberModel;
  25. public function __construct($uid, $uniacid)
  26. {
  27. $this->uid = $uid;
  28. $this->uniacid = $uniacid;
  29. $this->curr_date = date('Ym', time());
  30. }
  31. public function handle()
  32. {
  33. \Log::debug('---------add up vip------');
  34. $insert_ids = [];
  35. $uids = [];
  36. $ExistsIds = [];
  37. $noExistsIds = [];
  38. $this->MrytMemberAddUpVipModel = new MrytMemberAddUpVipModel($this->uniacid);
  39. $this->parentMemberModel = new ParentOfMember();
  40. //查询uid所有父类id
  41. $parent = $this->parentMemberModel->getParentOfMember($this->uid);
  42. if (!$parent->isEmpty()) {
  43. foreach ($parent as $val) {
  44. $insert_ids[] = $val->parent_id;
  45. }
  46. //mrytVVIP会员
  47. $mryt_vvip_ids = MrytMemberModel::getMemberInfosWithLevel($insert_ids, $this->uniacid);
  48. if (!is_null($mryt_vvip_ids)) {
  49. foreach ($mryt_vvip_ids as $rows) {
  50. $uids[] = $rows->uid;
  51. }
  52. $exists_parent = $this->MrytMemberAddUpVipModel->QueryCurrentMonthRecord($uids, $this->curr_date);
  53. if (!$exists_parent->isEmpty()) {
  54. foreach ($exists_parent as $item) {
  55. $ExistsIds [] = $item->uid;
  56. }
  57. foreach ($mryt_vvip_ids as $rows) {
  58. if (!in_array($rows->uid, $ExistsIds)) {
  59. $noExistsIds[] = $rows;
  60. }
  61. }
  62. DB::transaction(function () use ($ExistsIds, $noExistsIds) {
  63. $this->UpdateDate($ExistsIds, $this->curr_date);
  64. $this->InsertDate($noExistsIds);
  65. });
  66. } else {
  67. $this->InsertDate($mryt_vvip_ids);
  68. }
  69. }
  70. }
  71. }
  72. public function InsertDate($no_exists_ids)
  73. {
  74. foreach ($no_exists_ids as $ids) {
  75. $attr[] = [
  76. 'uniacid' => $this->uniacid,
  77. 'uid' => $ids->uid,
  78. 'nums' => 1,
  79. 'curr_date' => $this->curr_date,
  80. 'created_at' => time(),
  81. 'updated_at' => time()
  82. ];
  83. }
  84. $this->MrytMemberAddUpVipModel->CreateData($attr);
  85. }
  86. public function UpdateDate($exists_ids, $curr_date)
  87. {
  88. $this->MrytMemberAddUpVipModel->UpdateIncrementNums($exists_ids, $curr_date);
  89. }
  90. }