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.

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