| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\Share;
- use app\models\SharingReceiver;
- use app\models\User;
- use yii\base\Model;
- class ShareProfitListForm extends Model
- {
- public $store_id;
- public $search_type;
- public $status;
- public $dateStart;
- public $dateEnd;
- public $keyword;
- public $from;
- public $type;
- // 平台调用
- const CALL_TYPE_PLATFORM = 1;
- // 店铺调用
- const CALL_TYPE_STORE = 2;
- public function rules()
- {
- return [
- [['store_id', 'search_type', 'status', 'from'], 'integer'],
- [['keyword', 'dateStart', 'dateEnd'], 'string', 'max' => 255],
- [['keyword'], 'trim'],
- [['type'], 'required']
- ];
- }
- public function search() {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0]
- ];
- }
- $query = SharingReceiver::find()->where(['is_delete' => 0]);
- if ($this->type == self::CALL_TYPE_STORE) {
- $query->andWhere(['store_id' => $this->store_id]);
- }
- if (!empty($this->keyword)) {
- // 订单号
- if ($this->search_type == 1) {
- $query->andWhere(['like', 'order_no', $this->keyword]);
- }
- // 名称
- if ($this->search_type == 2) {
- $query->andWhere(['like', 'name', $this->keyword]);
- }
- }
- if (!empty($this->dateStart)) {
- $query->andWhere(['>=', 'created_at', strtotime($this->dateStart)]);
- }
- if (!empty($this->dateEnd)) {
- $query->andWhere(['<=', 'created_at', strtotime($this->dateEnd)]);
- }
- if (($this->status && in_array($this->status, [0, 1, 2])) || $this->status == 0) {
- $query->andWhere(['is_pay' => $this->status]);
- }
- // 0: 店铺分销, 1:平台分销, 2:平台推荐, 3:服务商分账, 4:商城间分销, 5:消费返利
- // if (($this->from && in_array($this->from, [0, 1, 2, 3, 4])) || $this->from == 0) {
- // $query->andWhere(['from' => $this->from]);
- // }
- if ((isset($this->from)) && intval($this->from) !== -1) {
- $query->andWhere(['from' => $this->from]);
- } else {
- $query->andWhere(['from' => SharingReceiver::FROM_ARR]);
- }
-
- if ($this->from == 5) {
- $query->andWhere(['from' => 1]);
- $query->andWhere(['like', 'remark', '自购返利']);
- }
- $query->orderBy('id DESC')
- ->select('*');
- $list = pagination_make($query);
- foreach ($list['list'] as &$val) {
- $val['rate'] = $val['rate'] . "%";
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- $val['updated_at'] = date('Y-m-d H:i:s', $val['updated_at']);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ];
- }
- }
|