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() ]; } } }