| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\job;
- use app\api\controller\OrderSuperLoss;
- use think\Db;
- use think\Log;
- class OrderSuperLossJob
- {
- /**
- * 队列消费入口(ThinkPHP queue fire)
- * @param $job
- * @param array $data
- */
- public function fire($job, $data)
- {
- try {
- if (empty($data['gdbh']) || empty($data['yjno'])) {
- Log::error('超节损队列参数缺失: ' . json_encode($data, JSON_UNESCAPED_UNICODE));
- $job->delete();
- return;
- }
- $api = new OrderSuperLoss();
- $result = $api->OneOrderSuperLoss($data['gdbh'], $data['yjno']);
- if (empty($result) || !is_array($result)) {
- Log::warning('超节损队列无可写入数据: ' . $data['gdbh'] . '-' . $data['yjno']);
- $job->delete();
- return;
- }
- Db::name('工单_质量考核汇总')
- ->where('Gy0_gdbh', $data['gdbh'])
- ->where('印件及工序', $data['yjno'])
- ->delete();
- $insertSql = Db::name('工单_质量考核汇总')
- ->fetchSql(true)
- ->insertAll($result);
- $insertRes = Db::query($insertSql);
- if ($insertRes === false) {
- throw new \RuntimeException('超节损队列写入失败');
- }
- $job->delete();
- } catch (\Throwable $e) {
- Log::error('超节损队列执行失败: ' . $e->getMessage() . '; data=' . json_encode($data, JSON_UNESCAPED_UNICODE));
- if ($job->attempts() >= 3) {
- $job->delete();
- } else {
- $job->release(10);
- }
- }
- }
- }
|