ShopForm.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1;
  8. use app\cyy\ApiResponse;
  9. use app\models\Shop;
  10. use app\models\ShopPic;
  11. use app\modules\client\models\ApiModel;
  12. class ShopForm extends ApiModel
  13. {
  14. public $store_id;
  15. public $user;
  16. public $shop_id;
  17. public function rules()
  18. {
  19. return [
  20. [['shop_id'], 'integer']
  21. ];
  22. }
  23. public function search()
  24. {
  25. if (!$this->validate()) {
  26. return [
  27. 'code' => 1,
  28. 'msg' => $this->getErrorSummary(false)[0]
  29. ];
  30. }
  31. $shop = Shop::find()->where([
  32. 'store_id' => $this->store_id, 'id' => $this->shop_id, 'is_delete' => 0
  33. ])->asArray()->one();
  34. if (!$shop) {
  35. // return new ApiResponse(1, '店铺不存在');
  36. return [
  37. 'code' => 1,
  38. 'msg' => '店铺不存在'
  39. ];
  40. }
  41. $shop_pic = ShopPic::find()->select(['pic_url'])->where(['store_id' => $this->store_id, 'shop_id' => $shop['id'], 'is_delete' => 0])->column();
  42. $shop['pic_list'] = $shop_pic;
  43. if (!$shop_pic) {
  44. $shop['pic_list'] = [$shop['pic_url']];
  45. }
  46. foreach ($shop as $index => &$value) {
  47. if (!$value) {
  48. if (in_array($index, ['pic_url', 'cover_url', 'pic_list'])) {
  49. continue;
  50. }
  51. $shop[$index] = "暂无设置";
  52. }
  53. if ($index == 'content') {
  54. $value = str_replace("&amp;nbsp;", " ", $value);
  55. $value = str_replace("&nbsp;", " ", $value);
  56. }
  57. }
  58. // return new ApiResponse(0, 'success', ['shop'=>$shop]);
  59. return [
  60. 'code' => 0,
  61. 'msg' => 'success',
  62. 'data' => ['shop'=>$shop]
  63. ];
  64. }
  65. }