SubEmailJobs.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace App\Jobs\Manager\Process;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Facades\Servers\Logs\Log;
  10. use App\Servers\Email\VerifyCode as EmailVerifyCode;
  11. use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
  12. use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
  13. use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
  14. use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
  15. use Illuminate\Support\Carbon;
  16. use App\Models\Manager\Process\ViolationStore as ViolationStoreModel;
  17. use App\Models\Manager\Process\ViolationStoreMember as ViolationStoreMemberModel;
  18. /**
  19. * 订阅邮件通知
  20. * @author 唐远望
  21. * @version 1.0
  22. * @date 2026-03-30
  23. */
  24. class SubEmailJobs implements ShouldQueue
  25. {
  26. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  27. protected $message_data;
  28. /**
  29. * Create a new job instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct(array $message_data)
  34. {
  35. $this->message_data = $message_data;
  36. }
  37. /**
  38. * Execute the job.
  39. *
  40. * @return void
  41. */
  42. public function handle()
  43. {
  44. try {
  45. $notice_type = $this->message_data['notice_type'];
  46. $company_id = $this->message_data['company_id'];
  47. switch ($notice_type) {
  48. case 'low_price_goods':
  49. $this->send_low_price_goods_notice($company_id);
  50. break;
  51. case 'violation_product':
  52. $this->send_violation_product($company_id);
  53. break;
  54. case 'violation_store':
  55. $this->send_violation_store($company_id);
  56. break;
  57. default:
  58. break;
  59. }
  60. } catch (\Exception $e) {
  61. Log::info('job_error', '订阅邮件通知推送队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  62. }
  63. }
  64. /**
  65. * 邮件消息消息订阅推送(低价挂网)
  66. * @author 唐远望
  67. * @version 1.0
  68. * @date 2026-03-04
  69. */
  70. private function send_low_price_goods_notice($company_id)
  71. {
  72. $EmailVerifyCode = new EmailVerifyCode();
  73. $LowPriceGoodsMemberModel = new LowPriceGoodsMemberModel();
  74. $LowPriceGoodsModel = new LowPriceGoodsModel();
  75. //获取今日待处理的商品记录
  76. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  77. $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  78. $lowprice_ids = $LowPriceGoodsModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd], ['company_id', '=', $company_id]])->pluck('id')->toArray();
  79. if (empty($lowprice_ids)) return true;
  80. //获取开启了通知服务的用户
  81. $usert_list = $LowPriceGoodsMemberModel
  82. ->whereIn('lowprice_product_logid', $lowprice_ids)
  83. ->join('personnel_employee', 'process_lowprice_product_member.employee_id', '=', 'personnel_employee.id')
  84. ->where('personnel_employee.open_notice', 0)
  85. ->where('personnel_employee.company_id', $company_id)
  86. ->where([['personnel_employee.email', '!=', ''], ['personnel_employee.email', '!=', null]])
  87. ->select(['process_lowprice_product_member.*', 'personnel_employee.email'])
  88. ->get()->toArray();
  89. if (empty($usert_list)) return true;
  90. //按用户统计待处理的商品数量
  91. $user_data = [];
  92. foreach ($usert_list as $key => $value) {
  93. $user_id = $value['employee_id'];
  94. if (!isset($user_data[$user_id])) {
  95. $user_data[$user_id]['employee_id'] = $user_id;
  96. $user_data[$user_id]['email'] = $value['email'];
  97. $user_data[$user_id]['log_ids'][] = $value['lowprice_product_logid'];
  98. } else {
  99. $user_data[$user_id]['log_ids'][] = $value['lowprice_product_logid'];
  100. }
  101. }
  102. //发送邮件
  103. foreach ($user_data as $key => $value) {
  104. $email_to = $value['email'];
  105. $totle_number = count($value['log_ids']);
  106. $email_title = '低价挂网商品提醒';
  107. $email_content = '今日待处理链接共' . $totle_number . '条,请及时登录智价云系统处理。';
  108. $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
  109. }
  110. }
  111. /**
  112. * 邮件消息消息订阅推送(禁止挂网)
  113. * @author 唐远望
  114. * @version 1.0
  115. * @date 2026-03-04
  116. */
  117. private function send_violation_product($company_id)
  118. {
  119. $EmailVerifyCode = new EmailVerifyCode();
  120. $ViolationProductMemberModel = new ViolationProductMemberModel();
  121. $ViolationProductModel = new ViolationProductModel();
  122. //获取今日待处理的商品记录
  123. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  124. $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  125. $violation_price_ids = $ViolationProductModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd], ['company_id', '=', $company_id]])->pluck('id')->toArray();
  126. if (empty($violation_price_ids)) return true;
  127. //获取开启了通知服务的用户
  128. $usert_list = $ViolationProductMemberModel
  129. ->whereIn('violation_product_logid', $violation_price_ids)
  130. ->join('personnel_employee', 'process_violation_product_member.employee_id', '=', 'personnel_employee.id')
  131. ->where('personnel_employee.open_notice', 0)
  132. ->where('personnel_employee.company_id', $company_id)
  133. ->where([['personnel_employee.email', '!=', ''], ['personnel_employee.email', '!=', null]])
  134. ->select(['process_violation_product_member.*', 'personnel_employee.email'])
  135. ->get()->toArray();
  136. if (empty($usert_list)) return true;
  137. //按用户统计待处理的商品数量
  138. $user_data = [];
  139. foreach ($usert_list as $key => $value) {
  140. $user_id = $value['employee_id'];
  141. if (!isset($user_data[$user_id])) {
  142. $user_data[$user_id]['employee_id'] = $user_id;
  143. $user_data[$user_id]['email'] = $value['email'];
  144. $user_data[$user_id]['log_ids'][] = $value['violation_product_logid'];
  145. } else {
  146. $user_data[$user_id]['log_ids'][] = $value['violation_product_logid'];
  147. }
  148. }
  149. //发送邮件
  150. foreach ($user_data as $key => $value) {
  151. $email_to = $value['email'];
  152. $totle_number = count($value['log_ids']);
  153. $email_title = '禁止挂网商品提醒';
  154. $email_content = '今日待处理链接共' . $totle_number . '条,请及时登录智价云系统处理。';
  155. $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
  156. }
  157. }
  158. /**
  159. * 邮件消息消息订阅推送(禁止店铺)
  160. * @author 唐远望
  161. * @version 1.0
  162. * @date 2026-03-04
  163. */
  164. private function send_violation_store($company_id){
  165. $EmailVerifyCode = new EmailVerifyCode();
  166. $ViolationStoreMemberModel = new ViolationStoreMemberModel();
  167. $ViolationStoreModel = new ViolationStoreModel();
  168. //获取今日待处理的店铺记录
  169. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  170. $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  171. $violation_price_ids = $ViolationStoreModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd], ['company_id', '=', $company_id]])->pluck('id')->toArray();
  172. if (empty($violation_price_ids)) return true;
  173. //获取开启了通知服务的用户
  174. $usert_list = $ViolationStoreMemberModel
  175. ->whereIn('violation_store_logid', $violation_price_ids)
  176. ->join('personnel_employee', 'process_violation_store_member.employee_id', '=', 'personnel_employee.id')
  177. ->where('personnel_employee.open_notice', 0)
  178. ->where('personnel_employee.company_id', $company_id)
  179. ->where([['personnel_employee.email', '!=', ''], ['personnel_employee.email', '!=', null]])
  180. ->select(['process_violation_store_member.*', 'personnel_employee.email'])
  181. ->get()->toArray();
  182. if (empty($usert_list)) return true;
  183. //按用户统计待处理的商品数量
  184. $user_data = [];
  185. foreach ($usert_list as $key => $value) {
  186. $user_id = $value['employee_id'];
  187. if (!isset($user_data[$user_id])) {
  188. $user_data[$user_id]['employee_id'] = $user_id;
  189. $user_data[$user_id]['email'] = $value['email'];
  190. $user_data[$user_id]['log_ids'][] = $value['violation_store_logid'];
  191. } else {
  192. $user_data[$user_id]['log_ids'][] = $value['violation_store_logid'];
  193. }
  194. }
  195. //发送邮件
  196. foreach ($user_data as $key => $value) {
  197. $email_to = $value['email'];
  198. $totle_number = count($value['log_ids']);
  199. $email_title = '禁止挂网店铺提醒';
  200. $email_content = '今日待处理店铺共' . $totle_number . '条,请及时登录智价云系统处理。';
  201. $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
  202. }
  203. }
  204. public function failed(\Throwable $exception)
  205. {
  206. Log::info('job_error', '订阅邮件通知推送队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  207. }
  208. }