| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\models\UserCard;
- use app\modules\client\models\ApiModel;
- use yii\data\Pagination;
- class CardListForm extends ApiModel
- {
- public $store_id;
- public $user_id;
- public $page;
- public $limit;
- public $status;
- public $user_card_id;
- public function rules()
- {
- return [
- [['user_card_id'], 'integer'],
- [['page'], 'default','value' => 1],
- [['limit'], 'default','value' => 10],
- [['status'], 'default','value' => 1]
- ];
- }
- /**
- * @return array
- */
- public function detail()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $list = UserCard::findOne([
- 'store_id' => $this->store_id,
- 'user_id' => $this->user_id,
- 'id' => $this->user_card_id,
- 'is_delete' => 0,
- ]);
- return [
- 'code'=>0,
- 'msg'=> '',
- 'data'=> [
- 'list' => $list,
- ]
- ];
- }
- /**
- * @return array
- */
- public function search()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $query = UserCard::find()->where([
- 'store_id' => $this->store_id, 'user_id' => $this->user_id, 'is_delete' => 0]);
- if ($this->status == 1) {
- $query->andWhere(['is_use' => 0]);
- }
- if ($this->status == 2) {
- $query->andWhere(['is_use' => 1]);
- }
- $count = $query->count();
- $p = new Pagination(['totalCount' => $count,'pageSize' => $this->limit]);
- $list = $query->limit($p->limit)->offset($p->offset)->orderBy(['created_at' => SORT_DESC])->asArray()->all();
- foreach ($list as $k => $v) {
- $list[$k]['clerk_time'] = date('Y-m-d H:i:s', $v['clerk_time']);
- }
- return [
- 'code'=>0,
- 'msg'=>'',
- 'data'=>[
- 'list' => $list,
- 'page_count' => $p->pageCount,
- 'row_count' => $count
- ]
- ];
- }
- }
|