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.

85 lines
3.3 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. /**
  9. * @AutoController()
  10. * Class StoreController
  11. * @package App\Controller
  12. */
  13. class StoreController extends BaseController
  14. {
  15. public function infoEdit()
  16. {
  17. $id = $this->request->input('id');
  18. if (empty($id)) {
  19. return $this->result(1, [], 'id不能为空');
  20. }
  21. if ($this->request->isMethod('post')) {
  22. $logo = $this->request->input('logo');
  23. $name = $this->request->input('name');
  24. $tel = $this->request->input('tel');
  25. $address = $this->request->input('address');
  26. $coordinates = $this->request->input('coordinates');
  27. $capita = $this->request->input('capita');
  28. $start_at = $this->request->input('start_at');
  29. $announcement = $this->request->input('announcement');
  30. $environment = $this->request->input('environment');
  31. //>>1上传logo到阿里云oss
  32. //>>2.上传商家环境到阿里云oss
  33. //>>3.保存数据到数据库存
  34. $fileNameLogo = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0, 9999999999999999) . '.jpg';
  35. $fileUpload = new FileUpload();
  36. $resLogo = $fileUpload->ossUpload($logo, $fileNameLogo);
  37. if (isset($resLogo['info']['http_code']) && $resLogo['info']['http_code'] == 200) {
  38. $logo_url = $fileNameLogo;
  39. } else {
  40. return $this->result(1, []);
  41. }
  42. $environments = explode(',', $environment);
  43. $envPaths = [];
  44. foreach ($environments as $env) {
  45. $fileNameEnv = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0, 9999999999999999) . '.jpg';
  46. $resEnv = $fileUpload->ossUpload($env, $fileNameEnv);
  47. if (isset($resEnv['info']['http_code']) && $resLogo['info']['http_code'] == 200) {
  48. $envPaths[] = $fileNameEnv;
  49. }
  50. }
  51. if (count($envPaths)) {
  52. $envPath = implode(',', $envPaths);
  53. }
  54. $res = Db::table('ims_cjdc_store')->where('id', $id)->update([
  55. 'logo' => $logo_url ?? "",
  56. 'name' => $name,
  57. 'tel' => $tel,
  58. 'address' => $address,
  59. 'coordinates' => $coordinates,
  60. 'capita' => $capita,
  61. 'start_at' => $start_at,
  62. 'announcement' => $announcement,
  63. 'environment' => $envPath ?? "",
  64. ]);
  65. return $this->success($res);
  66. }
  67. //'id','name','logo','tel','address','coordinates','capita','start_at','announcement','environment'
  68. //获取店铺信息
  69. $data = Db::table('ims_cjdc_store')
  70. ->select(['id','name','logo','tel','address','coordinates','capita','start_at','announcement','environment'])
  71. ->where('id',$id)
  72. ->first();
  73. if ($data){
  74. $data->site = env('SITE_HOST');
  75. }
  76. return $this->success($data);
  77. }
  78. }