| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace addons\Mch\api\modules\v1\controllers;
- use addons\Mch\common\models\Mch;
- use addons\Mch\common\models\MchCate;
- use common\enums\StatusEnum;
- use common\models\goods\GoodsCate;
- use common\models\order\OrderComments;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Store\api\modules\v1\controllers
- */
- class MchController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $params = Yii::$app->request->get();
- $mch_id = $params['mch_id'];
- if (empty($mch_id)) return $this->error('参数错误');
- $mall_id = $this->mall_id;
- $mch = Mch::getOne([['id' => $mch_id], ['mall_id' => $mall_id]]);
- if (empty($mch)) return $this->error('商户不存在');
- $time = time();
- $data['store_status'] = '';
- if(empty($mch['shop_status'])) $data['store_status'] = '休息中';
- if(!empty($data['expire_time'])&&$time>=$data['expire_time'])$data['store_status'] = '休息中';
- $data['mch_id'] = $mch['id'];
- $data['logo_img'] = $mch['logo_img'];
- $data['store_name'] = $mch['store_name'];
- $data['store_background'] = $mch['store_background']??'';
- $data['praise'] = $mch['praise'];//好评
- $data['sales_volume'] = $mch['sales_volume'];
- $comment_where = [['mch_id' => $mch_id], ['mall_id' => $mall_id], ['status' => StatusEnum::ENABLED]];
- $order_comment_count = OrderComments::listCount(['where' => $comment_where,]);
- $data['order_comment_count'] = $order_comment_count ?? 0;//评论条数
- $mch_goods_cate_list = GoodsCate::lists([
- 'where' => [
- // ['mch_id' => $mch_id],
- ['mall_id' => $mall_id],
- ['status' => StatusEnum::ENABLED],
- ['is_show' => 1],
- ['parent_id' => 0],
- ],
- 'select' => 'id,name',
- 'order' => 'sort asc',
- ]);
- $data['mch_goods_cate_list'] = $mch_goods_cate_list;
- return $this->success('成功', $data);
- }
- //商户列表
- public function actionMchList()
- {
- $params = Yii::$app->request->get();
- $sort = $params['sort'] ?? '';
- $mall_id = $this->mall_id;
- $status = StatusEnum::ENABLED;
- $shop_status = 1;
- $check_status = 1;
- $where[] = ['mall_id' => $mall_id];
- $where[] = ['status' => $status];
- $where[] = ['shop_status' => $shop_status];
- $where[] = ['check_status' => $check_status];
- $where[] = ['or', ['>', 'expire_time', time()], ['expire_time' => 0]];
- if(!empty($params['mch_id'])) $where[] = ['id' => explode(',',$params['mch_id'])];
- if (!empty($params['keyword'])) $where[] = ['like', 'store_name', trim($params['keyword']) . '%', false];
- if (!empty($params['cate_id'])) $where[] = ['c_id' => $params['cate_id']];
- if (in_array($sort, ['sales_volume', 'praise'])) $params['order'] = "{$sort} desc";
- $params['where'] = $where;
- $list_page = Mch::listPage($params);
- return $this->success('成功', $list_page);
- }
- public function actionMchCate()
- {
- $list = MchCate::lists(['where' => ['mall_id' => $this->mall_id, 'is_show' => 1, 'status' => StatusEnum::ENABLED], 'select' => 'id,parent_id,name']);
- $list = MchCate::getTreeMenu($list, 0);
- return $this->success('ok', compact('list'));
- }
- public function actionCate()
- {
- $params = \Yii::$app->request->get();
- $cate_id = empty($params['cate_id']) ? 0 : $params['cate_id'];
- $params['where'] = [['mall_id' => $this->mall_id, 'parent_id' => $cate_id, 'is_show' => 1, 'status' => StatusEnum::ENABLED]];
- $params['select'] = 'id,name,pic,advert_pic,advert_url';
- $params['order'] = 'sort desc';
- $cate_list = MchCate::listPage($params);
- if (false === $cate_list) {
- return $this->error(MchCate::getStaticError());
- }
- if (!empty($cate_list['list'])) {
- foreach ($cate_list['list'] as &$lv) {
- if (!empty($lv['advert_pic'])) {
- $lv['advert_pic'] = json_decode($lv['advert_pic'], true);
- }
- if (!empty($lv['advert_url'])) {
- $lv['advert_url'] = json_decode($lv['advert_url'], true);
- }
- }
- }
- $cate = MchCate::find()
- ->select('id,name,pic,advert_pic,advert_url')
- ->where(['mall_id' => $this->mall_id, 'id' => $cate_id, 'is_show' => 1, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->one();
- if (!empty($cate['advert_pic'])) {
- $cate['advert_pic'] = json_decode($cate['advert_pic'], true);
- }
- if (!empty($cate['advert_url'])) {
- $cate['pic_url'] = json_decode($cate['advert_url'], true);
- }
- $cate_list['cate_info'] = $cate;
- return $this->success('操作成功', $cate_list);
- }
- }
|