ShopApplyForm.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: 凯
  9. * @Date: 2021-04-26 17:20:17
  10. * @LastEditTime: 2021-04-26 17:43:35
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\client\models\v1\ShopApplyForm.php
  14. */
  15. namespace app\modules\client\models\v1;
  16. use app\models\Shop;
  17. use app\models\ShopPic;
  18. use app\modules\client\models\ApiModel;
  19. class ShopApplyForm extends ApiModel
  20. {
  21. public $id;
  22. public $name;
  23. public $mobile;
  24. public $address;
  25. public $longitude;
  26. public $latitude;
  27. public $cover_url;
  28. public $province;
  29. public $city;
  30. public $district;
  31. public function rules()
  32. {
  33. return [
  34. [['id'], 'integer'],
  35. [['name', 'mobile', 'address', 'longitude', 'latitude', 'cover_url', 'province', 'city', 'district'], 'string'],
  36. [['name', 'mobile', 'address', 'longitude', 'latitude', 'cover_url', 'province', 'city', 'district'], 'required']
  37. ];
  38. }
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'name' => '名称',
  43. 'mobile' => '联系电话',
  44. 'address' => '详细地址',
  45. 'longitude' => '经纬度',
  46. 'latitude' => '经纬度',
  47. 'cover_url' => '头像',
  48. 'province' => '省',
  49. 'city' => '市',
  50. 'district' => '区',
  51. ];
  52. }
  53. public function search()
  54. {
  55. if (!$this->validate()) {
  56. return [
  57. 'code' => 1,
  58. 'msg' => $this->getErrorSummary(false)[0],
  59. ];
  60. }
  61. $shop = Shop::findOne(['user_id' => get_user_id(), 'is_delete' => 0]);
  62. if(empty($shop)) {
  63. $shop = new Shop();
  64. $shop->store_id = get_store_id();
  65. $shop->user_id = get_user_id();
  66. }
  67. $shop->shop_audit = 0;
  68. $shop->address = $this->address;
  69. $shop->name = $this->name;
  70. $shop->mobile = $this->mobile;
  71. $shop->cover_url = $this->cover_url;
  72. $shop->pic_url = $this->cover_url;
  73. $shop->province = $this->province;
  74. $shop->city = $this->city;
  75. $shop->district = $this->district;
  76. $shop->longitude = $this->longitude;
  77. $shop->latitude = $this->latitude;
  78. if ($shop->save()) {
  79. return [
  80. 'code' => 0,
  81. 'msg' => '保存成功'
  82. ];
  83. } else {
  84. return [
  85. 'code' => 1,
  86. 'msg' => $shop->errors[0]
  87. ];
  88. }
  89. }
  90. }