0], ['type', 'in', 'range' => [Favorite::FAVORITE_GOODS, Favorite::FAVORITE_SHOP, Favorite::FAVORITE_WORKER]], [['page', 'limit',], 'integer',], [['page'], 'default', 'value' => 1], [['limit'], 'default', 'value' => 20], ]; } 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(['store_id' => $this->store_id, 'type' => Favorite::FAVORITE_SHOP, '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 $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(); if (!$mch) { continue; } $new_list[] = (object)[ 'id' => $shop['id'], 'created_at' => $shop['created_at'], 'name' => $mch['name'], 'logo' => $mch['logo'], '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, ], ]; } if ($this->type == Favorite::FAVORITE_WORKER) { $query = Favorite::find()->where(['store_id' => $this->store_id, 'type' => Favorite::FAVORITE_WORKER, '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 $key => $item) { $worker = Worker::findOne(['id' => $item['worker_id'], 'store_id' => $this->store_id, 'status' => 1]); if (!$worker) { continue; } $worker_cat_id = WorkerCatExt::find()->where(['worker_id' => $worker->id, 'is_delete' => 0])->select('cat_id')->column(); $worker_cat = []; if ($worker_cat_id) { $worker_cat = WorkerCat::find()->where(['id' => $worker_cat_id])->select('name')->column(); } $new_list[] = (object)[ 'id' => $item['worker_id'], 'created_at' => $item['created_at'], 'name' => $worker->name, 'logo' => $worker->logo, 'worker_cat' => $worker_cat ]; } return [ 'code' => 0, 'data' => (object)[ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $new_list, ], ]; } } }