You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.2 KiB

  1. <?php
  2. namespace App\Service;
  3. use App\Constants\LogLabel;
  4. use App\Constants\SsdbKeysPrefix;
  5. use App\Model\Store;
  6. use App\TaskWorker\SSDBTask;
  7. use Hyperf\DbConnection\Db;
  8. use Hyperf\Di\Annotation\Inject;
  9. use Hyperf\Utils\ApplicationContext;
  10. use League\Flysystem\Filesystem;
  11. class StoreService implements StoreServiceInterface
  12. {
  13. /**
  14. * @Inject
  15. * @var AttachmentServiceInterface
  16. */
  17. protected $attachmentService;
  18. /**
  19. * @Inject
  20. * @var Filesystem
  21. */
  22. protected $filesystem;
  23. public function entry($data)
  24. {
  25. Db::beginTransaction();
  26. try {
  27. // 文件上传
  28. $logo = $this->attachmentService->formUpload($data['logo'], 'storelogo', $this->filesystem);
  29. $fm_img = $this->attachmentService->formUpload($data['fm_img'], 'idcard', $this->filesystem);
  30. $zm_img = $this->attachmentService->formUpload($data['zm_img'], 'idcard', $this->filesystem);
  31. $yyzz = $this->attachmentService->formUpload($data['yyzz'], 'storelicense', $this->filesystem);
  32. // 商户信息入库(需审核)
  33. $store = Store::query()->updateOrCreate(
  34. ['id' => $data['id']],
  35. [
  36. 'name' => $data['name'],
  37. 'market_id' => $data['market_id'],
  38. 'md_type' => $data['md_type'],
  39. 'address' => $data['address'],
  40. 'coordinates' => $data['coordinates'],
  41. 'details' => $data['details'],
  42. 'link_name' => $data['link_name'],
  43. 'link_tel' => $data['link_tel'],
  44. 'tel' => $data['link_tel'],
  45. 'logo' => $logo,
  46. 'fm_img' => $fm_img,
  47. 'zm_img' => $zm_img,
  48. 'yyzz' => $yyzz,
  49. 'user_id' => $data['user_id'],
  50. 'sq_id' => $data['user_id'],
  51. 'admin_id' => $data['user_id'],
  52. 'rz_time' => $data['rz_time'],
  53. 'mm_user_id' => $data['mm_user_id'],
  54. 'sq_time' => date('Y-m-d H:i:s'),
  55. 'rzdq_time' => date('Y-m-d H:i:s', time() + 1000 * 24 * 3600),
  56. 'state' => 1,
  57. 'is_open' => 1,
  58. 'money' => 0,
  59. 'code' => time() . rand(1000, 9999) . $data['user_id'],
  60. 'uniacid' => 2,
  61. 'zf_state' => 2,
  62. ]
  63. );
  64. Db::commit();
  65. // 商户新用户等统计信息入SSDB
  66. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  67. if (!$ssdb->exec('hexists', SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'count')) {
  68. if(false === $ssdb->exec('hset', SsdbKeysPrefix::STORE_NEW_USER.$store->id, ['count', 0])) {
  69. $this->log->event(
  70. LogLabel::SSDB_LOG,
  71. ['method' => 'hset-'.SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'key' => SsdbKeysPrefix::STORE_NEW_USER.$store->id]
  72. );
  73. }
  74. }
  75. return true;
  76. } catch (\Exception $e) {
  77. Db::rollBack();
  78. return $e->getMessage();
  79. }
  80. }
  81. }