| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace addons\Mch\backend\controllers;
- use addons\Mch\common\enums\MchEnum;
- use addons\Mch\common\models\Mch;
- use addons\Mch\common\models\MchCate;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\models\common\Region;
- use common\models\user\User;
- class StoreAuditController extends BaseController
- {
- public function actionIndex()
- {
- if (!\Yii::$app->request->isAjax) {
- $upload_license_image = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_MCH, 'enter.upload_license_image');
- if(empty($upload_license_image)) $upload_license_image= 0;
- return $this->render('/store-audit/index',['upload_license_image'=>$upload_license_image]);
- }
- if (\Yii::$app->request->isGet) {
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $tabname = \Yii::$app->request->get('tabname', 'waiting-audit');
- if (!in_array($tabname, ['waiting-audit', 'reject'])) {
- return $this->error('参数错误');
- }
- if ('waiting-audit' == $tabname) {
- $check_status = MchEnum::CHECK_WAITING;
- } else {
- $check_status = MchEnum::CHECK_FAILED;
- }
- $store_name = \Yii::$app->request->get('store_name');
- $cate_id = \Yii::$app->request->get('cate_id');
- $storeowner = \Yii::$app->request->get('storeowner');
- $nickname = \Yii::$app->request->get('nickname');
- $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => $check_status];
- if (!empty($cate_id)) {
- $wheres[] = ['c_id' => $cate_id];
- }
- if (!empty($store_name)) {
- $wheres[] = ['like', 'store_name', $store_name];
- }
- if (!empty($storeowner)) {
- $wheres[] = ['like', 'shop_owner', $storeowner];
- }
- if (!empty($nickname)) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['like', 'nickname', $nickname])
- ->andWhere(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- $user_ids = array_column($users, 'id');
- $wheres[] = ['user_id' => $user_ids];
- }
- $params = [
- 'select' => 'id,mall_id,user_id,shop_owner,shop_mobile,store_name,c_id,province_id,city_id,district_id,address,logo_img,check_status,created_at,license_img',
- 'where' => $wheres,
- 'order' => 'created_at desc',
- 'page' => $page,
- 'limit' => $limit,
- ];
- $mch_list = Mch::listPage($params);
- if (false === $mch_list) {
- return $this->error(Mch::getStaticError());
- }
- if (!empty($mch_list['list'])) {
- if (empty($users)) {
- $user_ids = array_unique(array_column($mch_list['list'], 'user_id'));
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- $cate_ids = array_unique(array_column($mch_list['list'], 'c_id'));
- $categorys = MchCate::find()
- ->select('id,name')
- ->where(['id' => $cate_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- $region_ids = [];
- $province_ids = array_unique(array_column($mch_list['list'], 'province_id'));
- $city_ids = array_unique(array_column($mch_list['list'], 'city_id'));
- $district_ids = array_unique(array_column($mch_list['list'], 'district_id'));
- $region_ids = array_merge($province_ids, $city_ids, $district_ids);
- $regions = Region::find()
- ->select('id,name')
- ->where(['id' => $region_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- foreach ($mch_list['list'] as &$list) {
- $user = $users[$list['user_id']] ?? [];
- $category = $categorys[$list['c_id']] ?? [];
- $province = $regions[$list['province_id']] ?? [];
- $city = $regions[$list['city_id']] ?? [];
- $district = $regions[$list['district_id']] ?? [];
- $list['nickname'] = $user['nickname'] ?? '';
- $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $list['category'] = $category['name'] ?? '';
- $list['store_address'] = ($province['name'] ?? '') . ($city['name'] ?? '') . ($district['name'] ?? '') . $list['address'];
- if ($list['check_status'] == MchEnum::CHECK_WAITING) {
- $list['check_status'] = 1;
- }
- }
- }
- $cate_list = MchCate::find()
- ->select('id,name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- $mch_list['cate_list'] = $cate_list;
- return $this->success('success', $mch_list);
- }
- }
- /**
- * @name:
- * @msg: 门店审核
- * @param {*}
- * @return {*}
- */
- public function actionAudit()
- {
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $post = \Yii::$app->request->post();
- if (!in_array($post['action'], ['adopt', 'reject'])) {
- return $this->error('参数错误');
- }
- $rules = [
- [['id', 'action'], 'required'],
- ['id', 'integer'],
- [['action', 'check_remark'], 'string'],
- ['check_remark', 'safe'],
- ['check_remark', 'string', 'max' => 255],
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- if ('adopt' == $post['action']) {
- $check_status = MchEnum::CHECK_ADOPT;
- } else {
- $check_status = MchEnum::CHECK_FAILED;
- }
- $params = [
- 'mall_id' => $this->mall_id,
- 'id' => $post['id'],
- 'check_status' => $check_status,
- 'check_remark' => $post['check_remark'] ?? '',
- ];
- $res = Mch::setData($params);
- if (false === $res) {
- return $this->error(Mch::getStaticError());
- }
- return $this->success('操作成功');
- }
- }
|