123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wuzhenke
- * Date: 2019/2/14
- * Time: 13:39
- */
- namespace App\Jobs\Cron;
- use App\Models\Jobs;
- use App\Repositories\JobsRepository;
- use App\Repositories\PromotionRepository;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use mysql_xdevapi\Exception;
- class ClearPromotionJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * ClearPromotionJob constructor.
- */
- public function __construct()
- {
- }
- public function handle(PromotionRepository $promotionRepository, JobsRepository $jobsRepository)
- {
- //职位推广
- $condition[] = ['endtime','<',time()];
- $list = $promotionRepository->findWhere($condition);
- if ($list->isNotEmpty()) {
- $stick_arr = [];
- $emergency_arr = [];
- foreach ($list as $key => $val) {
- if ($val['ptype'] ==1) {
- $stick_arr[] = $val['jobid'];
- } else {
- $emergency_arr[] = $val['jobid'];
- }
- }
- //使用事务原因是,职位的状态没改变,推广的却删掉了,不好排查
- DB::beginTransaction();
- try{
- if ($stick_arr) {
- if (!$jobsRepository->modifyData($stick_arr, ['stick'=>0,'stime'=>0])) {
- Log::error('清除过期职位置顶失败'.json_encode($stick_arr));
- throw new \Exception("error");
- }
- foreach ($stick_arr as $key => $val) {
- event_search_update(Jobs::class, (string)$val, 'update');
- }
- }
- if ($emergency_arr) {
- if (!$jobsRepository->modifyData($emergency_arr, ['emergency'=>0])) {
- Log::error('清除过期职位紧急失败'.json_encode($emergency_arr));
- throw new \Exception("");
- }
- foreach ($emergency_arr as $key => $val) {
- event_search_update(Jobs::class, (string)$val, 'update');
- }
- }
- if (!$promotionRepository->deleteWhere($condition)) {
- Log::error('清除职位推广失败'.json_encode($condition));
- throw new \Exception("");
- }
- DB::commit();
- }catch (\Exception $exception){
- DB::rollback();
- }
- }
- }
- }
|