| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models;
- use app\models\Admin;
- use app\models\Favorite;
- use app\models\Goods;
- use app\models\Mch;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\Cat;
- use app\models\WechatConfig;
- use yii\base\Model;
- use yii\data\Pagination;
- use yii\helpers\VarDumper;
- use app\modules\client\models\ApiModel;
- class FavoriteListForm extends ApiModel
- {
- public $store_id;
- public $user_id;
- public $saas_id;
- public $page;
- public $limit;
- public $type;
- public function rules()
- {
- return [
- [['type'], 'default', 'value' => 0],
- ['type', 'in', 'range' => [Favorite::FAVORITE_GOODS, Favorite::FAVORITE_SHOP]],
- [['page', 'limit',], 'integer',],
- [['page'], 'default', 'value' => 1],
- [['limit'], 'default', 'value' => 20],
- ];
- }
- public function league_search($saas_user_id)
- {
- $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']);
- $store = Store::findOne($admin->type_id);
- if($store){
- return [
- 'code' => 0,
- 'data' => $store->league_price,
- 'msg' => '查找成功'
- ];
- }else{
- return [
- 'code' => 1,
- 'msg' => '该账户不是商城管理员'
- ];
- }
- }
- public function search()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0]
- ];
- }
- // 暂无商品收藏列表
- // if ($this->type == Favorite::FAVORITE_GOODS) {
- // $query = Favorite::find()->where(['store_id' => $this->store_id, 'type' => Favorite::FAVORITE_GOODS, 'is_delete' => 0, 'user_id' => $this->user_id]);
- // $count = $query->count();
- // $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- // $list = $query->select('*')->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
- // $new_list = [];
- // foreach ($list as $i => $favorite) {
- // $goods = Goods::findOne(['store_id' => $this->store_id, 'is_delete' => 0, 'status' => Goods::STATUS_NORMAL, 'id' => $favorite['goods_id']]);
- // if (!$goods) {
- // continue;
- // }
- // if ($goods->is_negotiable) {
- // $goods->price = Goods::GOODS_NEGOTIABLE;
- // }
- // $new_list[] = (object)[
- // 'id' => $favorite['id'],
- // 'goods_id' => $goods->id,
- // 'name' => $goods->name,
- // 'price' => $goods->price,
- // 'goods_pic' => $goods->getGoodsPic(0)->pic_url,
- // 'is_negotiable' => $goods->is_negotiable,
- // ];
- // }
- // return [
- // 'code' => 0,
- // 'data' => (object)[
- // 'row_count' => $count,
- // 'page_count' => $pagination->pageCount,
- // 'list' => $new_list,
- // ],
- // ];
- // }
- if ($this->type == Favorite::FAVORITE_SHOP) {
- $query = Favorite::find()->where(['type' => Favorite::FAVORITE_SHOP, 'is_delete' => 0, 'saas_id' => $this->saas_id]);
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- $list = $query->select('*')->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
- $new_list = [];
- foreach ($list as $key => $shop) {
- //$mch = Mch::find()->where(['id' => $shop['goods_id'], 'store_id' => $this->store_id, 'is_delete' => 0, 'is_open' => 1, 'is_lock' => 0])->one();
- //$store = Store::find()->where(['id' =>$shop['store_id'], 'is_delete' => 0])->one();
- $storeInfo = Store::find()->alias('s')->where(['s.id'=>$shop['store_id'],'s.is_delete'=>0])->select('s.id,s.name,s.logo,s.address,s.category_id,s.sales,s.rank,s.per_spend,s.coordinate,s.business_model')->asArray()->one();
- if (!$storeInfo) {
- continue;
- }
- if($storeInfo['category_id']>0){
- $categoryInfo = Cat::find()->where(['id'=>$storeInfo['category_id'],'is_delete'=>0])->asArray()->one();
- if($categoryInfo){
- $storeInfo['category_name'] = $categoryInfo['name'];
- }else{
- $storeInfo['category_name'] = '';
- }
- }
- $new_list[] = (object)[
- 'id' => $shop['id'],
- 'created_at' => $shop['created_at'],
- 'store_info' => $storeInfo
- //'goods_list' => Goods::find()->where(['store_id' => $this->store_id, 'status' => Goods::STATUS_NORMAL, 'is_delete' => 0, 'mch_id' => $shop['goods_id']])->select('id, price, cover_pic, mch_id')->limit(4)->orderBy('created_at DESC')->asArray()->all()
- ];
- }
- return [
- 'code' => 0,
- 'data' => (object)[
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $new_list,
- ],
- ];
- }
- }
- }
|