| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1\admin;
- use app\models\District;
- use app\models\Mch;
- use app\models\MchCommonCat;
- use app\models\User;
- class MchForm extends \yii\base\Model
- {
- public $sort;
- public $name;
- public $model;
- public $user_id;
- public $is_delete;
- public $is_open;
- public $is_lock;
- public $review_status;
- public $review_result;
- public $review_time;
- public $realname;
- public $tel;
- public $province_id;
- public $city_id;
- public $district_id;
- public $address;
- public $mch_common_cat_id;
- public $service_tel;
- public $logo;
- public $header_bg;
- public $transfer_rate;
- public $account_money;
- public $wechat_name;
- public $is_recommend;
- public $longitude;
- public $latitude;
- public $main_content;
- public $summary;
- public $business;
- public $card_front;
- public $card_obverse;
- public $business_hours;
- public $store_id;
- public $platform;
- public $keyword;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [['user_id', 'realname', 'tel', 'name', 'address', 'mch_common_cat_id', 'service_tel'], 'required'],
- [['user_id', 'is_delete', 'is_open', 'is_lock', 'is_recommend',
- 'review_status', 'review_time', 'province_id', 'city_id', 'district_id', 'mch_common_cat_id',
- 'transfer_rate', 'sort', 'province_id', 'city_id', 'district_id', 'platform', 'store_id'], 'integer'],
- [['review_result', 'logo', 'header_bg', 'keyword'], 'string'],
- [['account_money'], 'number'],
- [['realname', 'tel', 'name', 'wechat_name', 'longitude', 'latitude', 'main_content', 'summary',
- 'business', 'card_front', 'card_obverse', 'business_hours'], 'string', 'max' => 255],
- [['address', 'service_tel'], 'string', 'max' => 1000],
- [[], 'default', 'value'=>0]
- ];
- }
- /**
- * 保存商户
- * @return array
- */
- public function save()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0]
- ];
- }
- $this->model->name = $this->name;
- $this->model->sort = $this->sort;
- $this->model->store_id = get_store_id();
- $this->review_status = post_params('review_status', 1);
- $attributes = $this->attributes;
- $attributes['store_id'] = get_store_id();
- $attributes['user_id'] = get_user_id();
- $this->model->attributes = $attributes;
- $location = post_params('location','0,0');
- $this->model->longitude = explode(',', $location)[0];
- $this->model->latitude = explode(',', $location)[1];
- if ($this->model->save()) {
- return [
- 'code' => 0,
- 'msg' => '提交成功'
- ];
- } else {
- return [
- 'code' => 0,
- 'msg' => '保存失败',
- 'err' => $this->model->getErrors()
- ];
- }
- }
- /**
- * 获取商待审核列表
- * @return array
- */
- public function getList()
- {
- $query = Mch::find()->alias('m')->leftJoin(['u' => User::tableName()], 'm.user_id=u.id')
- ->where([
- 'm.is_delete' => 0,
- 'm.store_id' => $this->store_id,
- ]);
- if ($this->keyword) {
- $query->andWhere([
- 'OR',
- ['LIKE', 'm.realname', $this->keyword],
- ['LIKE', 'm.tel', $this->keyword],
- ['LIKE', 'm.name', $this->keyword],
- ['LIKE', 'u.nickname', $this->keyword],
- ]);
- }
- $query->andWhere([
- 'm.review_status' => Mch::REVIEW_STATUS_WAIT
- ]);
-
- $query->orderBy('m.sort, m.created_at DESC')
- ->select('m.*, u.nickname, u.platform, u.avatar_url');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach ($list as $key => &$mch) {
- $mch['cat'] = MchCommonCat::findOne(['store_id' => $this->store_id,
- 'id' => $mch['mch_common_cat_id']])->name;
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ];
- }
- /**
- * 获取商待审核列表
- * @return array
- */
- public function getMch($id)
- {
- $query = Mch::find()->alias('m')->leftJoin(['u' => User::tableName()], 'm.user_id=u.id')
- ->where([
- 'm.is_delete' => 0,
- 'm.store_id' => $this->store_id,
- ]);
- $query->andWhere([
- 'm.id' => $id
- ]);
-
- $query->orderBy('m.sort, m.created_at DESC')
- ->select('m.*, u.nickname, u.platform, u.avatar_url');
- $mch = $query->asArray()->one();
- $mch['cat'] = MchCommonCat::findOne(['store_id' => $this->store_id,
- 'id' => $mch['mch_common_cat_id']])->name;
- $mch['city'] = District::findOne($mch['city_id'])->name;
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $mch,
- ];
- }
- /**
- * 审核
- * @return array
- */
- public function apply()
- {
- if (!$this->model) {
- return [
- 'code' => 1,
- 'msg' => '参数错误'
- ];
- }
- $this->model->transfer_rate =post_params('transfer_rate', 0);
- $this->model->review_status = post_params('review_status', 0);
- if ($this->model->save()) {
- return [
- 'code' => 0,
- 'msg' => '提交成功'
- ];
- } else {
- return [
- 'code' => 0,
- 'msg' => '保存失败',
- 'err' => $this->model->getErrors()
- ];
- }
- }
- }
|