ShareProfitListForm.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\Share;
  9. use app\models\SharingReceiver;
  10. use app\models\User;
  11. use yii\base\Model;
  12. class ShareProfitListForm extends Model
  13. {
  14. public $store_id;
  15. public $search_type;
  16. public $status;
  17. public $dateStart;
  18. public $dateEnd;
  19. public $keyword;
  20. public $from;
  21. public $type;
  22. // 平台调用
  23. const CALL_TYPE_PLATFORM = 1;
  24. // 店铺调用
  25. const CALL_TYPE_STORE = 2;
  26. public function rules()
  27. {
  28. return [
  29. [['store_id', 'search_type', 'status', 'from'], 'integer'],
  30. [['keyword', 'dateStart', 'dateEnd'], 'string', 'max' => 255],
  31. [['keyword'], 'trim'],
  32. [['type'], 'required']
  33. ];
  34. }
  35. public function search() {
  36. if (!$this->validate()) {
  37. return [
  38. 'code' => 1,
  39. 'msg' => $this->getErrorSummary(false)[0]
  40. ];
  41. }
  42. $query = SharingReceiver::find()->where(['is_delete' => 0]);
  43. if ($this->type == self::CALL_TYPE_STORE) {
  44. $query->andWhere(['store_id' => $this->store_id]);
  45. }
  46. if (!empty($this->keyword)) {
  47. // 订单号
  48. if ($this->search_type == 1) {
  49. $query->andWhere(['like', 'order_no', $this->keyword]);
  50. }
  51. // 名称
  52. if ($this->search_type == 2) {
  53. $query->andWhere(['like', 'name', $this->keyword]);
  54. }
  55. }
  56. if (!empty($this->dateStart)) {
  57. $query->andWhere(['>=', 'created_at', strtotime($this->dateStart)]);
  58. }
  59. if (!empty($this->dateEnd)) {
  60. $query->andWhere(['<=', 'created_at', strtotime($this->dateEnd)]);
  61. }
  62. if (($this->status && in_array($this->status, [0, 1, 2])) || $this->status == 0) {
  63. $query->andWhere(['is_pay' => $this->status]);
  64. }
  65. // 0: 店铺分销, 1:平台分销, 2:平台推荐, 3:服务商分账, 4:商城间分销, 5:消费返利
  66. // if (($this->from && in_array($this->from, [0, 1, 2, 3, 4])) || $this->from == 0) {
  67. // $query->andWhere(['from' => $this->from]);
  68. // }
  69. if ((isset($this->from)) && intval($this->from) !== -1) {
  70. $query->andWhere(['from' => $this->from]);
  71. } else {
  72. $query->andWhere(['from' => SharingReceiver::FROM_ARR]);
  73. }
  74. if ($this->from == 5) {
  75. $query->andWhere(['from' => 1]);
  76. $query->andWhere(['like', 'remark', '自购返利']);
  77. }
  78. $query->orderBy('id DESC')
  79. ->select('*');
  80. $list = pagination_make($query);
  81. foreach ($list['list'] as &$val) {
  82. $val['rate'] = $val['rate'] . "%";
  83. $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
  84. $val['updated_at'] = date('Y-m-d H:i:s', $val['updated_at']);
  85. }
  86. return [
  87. 'code' => 0,
  88. 'msg' => 'success',
  89. 'data' => [
  90. 'data' => $list['list'],
  91. 'pageNo' => $list['pageNo'],
  92. 'totalCount' => $list['totalCount'],
  93. ]
  94. ];
  95. }
  96. }