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.

115 lines
3.9 KiB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use Hyperf\DbConnection\Db;
  5. use Hyperf\HttpServer\Annotation\AutoController;
  6. use OSS\Core\OssException;
  7. use OSS\OssClient;
  8. use App\Constants\ErrorCode;
  9. use App\Request\StoreApplyEntryRequest;
  10. use App\Service\StoreServiceInterface;
  11. use Hyperf\Di\Annotation\Inject;
  12. /**
  13. * @AutoController()
  14. * Class StoreController
  15. * @package App\Controller
  16. */
  17. class StoreController extends BaseController
  18. {
  19. /**
  20. * @Inject
  21. * @var StoreServiceInterface
  22. */
  23. protected $storeService;
  24. /**
  25. * 申请入驻
  26. * 商户信息入驻+市场经理拉新记录
  27. */
  28. public function applyEntry(StoreApplyEntryRequest $request)
  29. {
  30. $data = $request->validated();
  31. $res = $this->storeService->entry($data);
  32. if ($res !== true) {
  33. return $this->result(ErrorCode::SAVE_FAILURE, $res, '申请失败,请稍后重试');
  34. }
  35. return $this->success('');
  36. }
  37. public function infoEdit()
  38. {
  39. $id = $this->request->input('id');
  40. if (empty($id)) {
  41. return $this->result(1, [], 'id不能为空');
  42. }
  43. if ($this->request->isMethod('post')) {
  44. $logo = $this->request->input('logo');
  45. $name = $this->request->input('name');
  46. $tel = $this->request->input('tel');
  47. $address = $this->request->input('address');
  48. $coordinates = $this->request->input('coordinates');
  49. $capita = $this->request->input('capita');
  50. $start_at = $this->request->input('start_at');
  51. $announcement = $this->request->input('announcement');
  52. $environment = $this->request->input('environment');
  53. //>>1上传logo到阿里云oss
  54. //>>2.上传商家环境到阿里云oss
  55. //>>3.保存数据到数据库存
  56. $fileNameLogo = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0, 9999999999999999) . '.jpg';
  57. $fileUpload = new FileUpload();
  58. $resLogo = $fileUpload->ossUpload($logo, $fileNameLogo);
  59. if (isset($resLogo['info']['http_code']) && $resLogo['info']['http_code'] == 200) {
  60. $logo_url = $fileNameLogo;
  61. } else {
  62. return $this->result(1, []);
  63. }
  64. $environments = explode(',', $environment);
  65. $envPaths = [];
  66. foreach ($environments as $env) {
  67. $fileNameEnv = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0, 9999999999999999) . '.jpg';
  68. $resEnv = $fileUpload->ossUpload($env, $fileNameEnv);
  69. if (isset($resEnv['info']['http_code']) && $resLogo['info']['http_code'] == 200) {
  70. $envPaths[] = $fileNameEnv;
  71. }
  72. }
  73. if (count($envPaths)) {
  74. $envPath = implode(',', $envPaths);
  75. }
  76. $res = Db::table('ims_cjdc_store')->where('id', $id)->update([
  77. 'logo' => $logo_url ?? "",
  78. 'name' => $name,
  79. 'tel' => $tel,
  80. 'address' => $address,
  81. 'coordinates' => $coordinates,
  82. 'capita' => $capita,
  83. 'start_at' => $start_at,
  84. 'announcement' => $announcement,
  85. 'environment' => $envPath ?? "",
  86. ]);
  87. return $this->success($res);
  88. }
  89. //'id','name','logo','tel','address','coordinates','capita','start_at','announcement','environment'
  90. //获取店铺信息
  91. $data = Db::table('ims_cjdc_store')
  92. ->select(['id','name','logo','tel','address','coordinates','capita','start_at','announcement','environment'])
  93. ->where('id',$id)
  94. ->first();
  95. if ($data){
  96. $data->site = config('site_host');
  97. }
  98. return $this->success($data);
  99. }
  100. }