MchForm.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1\admin;
  8. use app\models\District;
  9. use app\models\Mch;
  10. use app\models\MchCommonCat;
  11. use app\models\User;
  12. class MchForm extends \yii\base\Model
  13. {
  14. public $sort;
  15. public $name;
  16. public $model;
  17. public $user_id;
  18. public $is_delete;
  19. public $is_open;
  20. public $is_lock;
  21. public $review_status;
  22. public $review_result;
  23. public $review_time;
  24. public $realname;
  25. public $tel;
  26. public $province_id;
  27. public $city_id;
  28. public $district_id;
  29. public $address;
  30. public $mch_common_cat_id;
  31. public $service_tel;
  32. public $logo;
  33. public $header_bg;
  34. public $transfer_rate;
  35. public $account_money;
  36. public $wechat_name;
  37. public $is_recommend;
  38. public $longitude;
  39. public $latitude;
  40. public $main_content;
  41. public $summary;
  42. public $business;
  43. public $card_front;
  44. public $card_obverse;
  45. public $business_hours;
  46. public $store_id;
  47. public $platform;
  48. public $keyword;
  49. /**
  50. * @return array
  51. */
  52. public function rules()
  53. {
  54. return [
  55. [['user_id', 'realname', 'tel', 'name', 'address', 'mch_common_cat_id', 'service_tel'], 'required'],
  56. [['user_id', 'is_delete', 'is_open', 'is_lock', 'is_recommend',
  57. 'review_status', 'review_time', 'province_id', 'city_id', 'district_id', 'mch_common_cat_id',
  58. 'transfer_rate', 'sort', 'province_id', 'city_id', 'district_id', 'platform', 'store_id'], 'integer'],
  59. [['review_result', 'logo', 'header_bg', 'keyword'], 'string'],
  60. [['account_money'], 'number'],
  61. [['realname', 'tel', 'name', 'wechat_name', 'longitude', 'latitude', 'main_content', 'summary',
  62. 'business', 'card_front', 'card_obverse', 'business_hours'], 'string', 'max' => 255],
  63. [['address', 'service_tel'], 'string', 'max' => 1000],
  64. [[], 'default', 'value'=>0]
  65. ];
  66. }
  67. /**
  68. * 保存商户
  69. * @return array
  70. */
  71. public function save()
  72. {
  73. if (!$this->validate()) {
  74. return [
  75. 'code' => 1,
  76. 'msg' => $this->getErrorSummary(false)[0]
  77. ];
  78. }
  79. $this->model->name = $this->name;
  80. $this->model->sort = $this->sort;
  81. $this->model->store_id = get_store_id();
  82. $this->review_status = post_params('review_status', 1);
  83. $attributes = $this->attributes;
  84. $attributes['store_id'] = get_store_id();
  85. $attributes['user_id'] = get_user_id();
  86. $this->model->attributes = $attributes;
  87. $location = post_params('location','0,0');
  88. $this->model->longitude = explode(',', $location)[0];
  89. $this->model->latitude = explode(',', $location)[1];
  90. if ($this->model->save()) {
  91. return [
  92. 'code' => 0,
  93. 'msg' => '提交成功'
  94. ];
  95. } else {
  96. return [
  97. 'code' => 0,
  98. 'msg' => '保存失败',
  99. 'err' => $this->model->getErrors()
  100. ];
  101. }
  102. }
  103. /**
  104. * 获取商待审核列表
  105. * @return array
  106. */
  107. public function getList()
  108. {
  109. $query = Mch::find()->alias('m')->leftJoin(['u' => User::tableName()], 'm.user_id=u.id')
  110. ->where([
  111. 'm.is_delete' => 0,
  112. 'm.store_id' => $this->store_id,
  113. ]);
  114. if ($this->keyword) {
  115. $query->andWhere([
  116. 'OR',
  117. ['LIKE', 'm.realname', $this->keyword],
  118. ['LIKE', 'm.tel', $this->keyword],
  119. ['LIKE', 'm.name', $this->keyword],
  120. ['LIKE', 'u.nickname', $this->keyword],
  121. ]);
  122. }
  123. $query->andWhere([
  124. 'm.review_status' => Mch::REVIEW_STATUS_WAIT
  125. ]);
  126. $query->orderBy('m.sort, m.created_at DESC')
  127. ->select('m.*, u.nickname, u.platform, u.avatar_url');
  128. $pagination = pagination_make($query);
  129. $list = $pagination['list'];
  130. foreach ($list as $key => &$mch) {
  131. $mch['cat'] = MchCommonCat::findOne(['store_id' => $this->store_id,
  132. 'id' => $mch['mch_common_cat_id']])->name;
  133. }
  134. return [
  135. 'code' => 0,
  136. 'msg' => 'success',
  137. 'data' => [
  138. 'data' => $list,
  139. 'pageNo' => $pagination['pageNo'],
  140. 'totalCount' => $pagination['totalCount']
  141. ],
  142. ];
  143. }
  144. /**
  145. * 获取商待审核列表
  146. * @return array
  147. */
  148. public function getMch($id)
  149. {
  150. $query = Mch::find()->alias('m')->leftJoin(['u' => User::tableName()], 'm.user_id=u.id')
  151. ->where([
  152. 'm.is_delete' => 0,
  153. 'm.store_id' => $this->store_id,
  154. ]);
  155. $query->andWhere([
  156. 'm.id' => $id
  157. ]);
  158. $query->orderBy('m.sort, m.created_at DESC')
  159. ->select('m.*, u.nickname, u.platform, u.avatar_url');
  160. $mch = $query->asArray()->one();
  161. $mch['cat'] = MchCommonCat::findOne(['store_id' => $this->store_id,
  162. 'id' => $mch['mch_common_cat_id']])->name;
  163. $mch['city'] = District::findOne($mch['city_id'])->name;
  164. return [
  165. 'code' => 0,
  166. 'msg' => 'success',
  167. 'data' => $mch,
  168. ];
  169. }
  170. /**
  171. * 审核
  172. * @return array
  173. */
  174. public function apply()
  175. {
  176. if (!$this->model) {
  177. return [
  178. 'code' => 1,
  179. 'msg' => '参数错误'
  180. ];
  181. }
  182. $this->model->transfer_rate =post_params('transfer_rate', 0);
  183. $this->model->review_status = post_params('review_status', 0);
  184. if ($this->model->save()) {
  185. return [
  186. 'code' => 0,
  187. 'msg' => '提交成功'
  188. ];
  189. } else {
  190. return [
  191. 'code' => 0,
  192. 'msg' => '保存失败',
  193. 'err' => $this->model->getErrors()
  194. ];
  195. }
  196. }
  197. }