SystemFormDataJob.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\jobs\system;
  3. use app\services\system\form\SystemFormDataServices;
  4. use crmeb\basic\BaseJobs;
  5. use crmeb\traits\QueueTrait;
  6. use think\facade\Log;
  7. /**
  8. * 系统表单数据收集
  9. * Class SystemFormDataJob
  10. * @package app\jobs\system
  11. */
  12. class SystemFormDataJob extends BaseJobs
  13. {
  14. use QueueTrait;
  15. /**
  16. * @param $order
  17. * @param $type
  18. * @return bool
  19. */
  20. public function doJob($data, $type = 1)
  21. {
  22. if (!$data || !(int)$type) {
  23. return true;
  24. }
  25. $form = [];
  26. try {
  27. switch ($type) {
  28. case '1'://订单
  29. $form = [
  30. 'type' => 1,
  31. 'relation_id' => $data['id'] ?? 0,
  32. 'uid' => $data['uid'] ?? 0,
  33. 'system_form_id' => $data['system_form_id'] ?? 0,
  34. 'value' => is_string($data['custom_form']) ? json_decode($data['custom_form'], true) : $data['custom_form']
  35. ];
  36. break;
  37. }
  38. if ($form) {
  39. /** @var SystemFormDataServices $systemFormDataServices */
  40. $systemFormDataServices = app()->make(SystemFormDataServices::class);
  41. $systemFormDataServices->setFormData($form, (int)$type);
  42. }
  43. } catch (\Throwable $e) {
  44. Log::error('写入系统表单收集数据失败,错误:' . $e->getMessage());
  45. }
  46. return true;
  47. }
  48. }