CashListForm.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\models;
  8. use app\models\Cash;
  9. use yii\base\Model;
  10. use yii\data\Pagination;
  11. class CashListForm extends Model
  12. {
  13. public $store_id;
  14. public $user_id;
  15. public $saas_id;
  16. public $status;
  17. public $page;
  18. public $limit;
  19. public $cash_type = -1;
  20. public function rules()
  21. {
  22. return [
  23. [['page', 'limit', 'status',], 'integer'],
  24. [['page',], 'default', 'value' => 1],
  25. [['limit',], 'default', 'value' => 10],
  26. ];
  27. }
  28. public function getList()
  29. {
  30. if (!$this->validate()) {
  31. return [
  32. 'code' => 1,
  33. 'msg' => $this->getErrorSummary(false)[0],
  34. ];
  35. }
  36. $query = Cash::find()->where([
  37. 'is_delete'=>0,
  38. 'saas_id'=>$this->saas_id
  39. ]);
  40. if ($this->cash_type > -1) {
  41. $query->andWhere([
  42. 'cash_type' => $this->cash_type
  43. ]);
  44. }
  45. if ($this->status == 0 && $this->status != null) { //待审核
  46. $query->andWhere(['status'=>0]);
  47. }
  48. if ($this->status == 1) {//待打款
  49. $query->andWhere(['status'=>1]);
  50. }
  51. if ($this->status == 2) {//已打款
  52. $query->andWhere(['in','status',[2,5]]);
  53. }
  54. if ($this->status == 3) {//无效
  55. $query->andWhere(['status'=>3]);
  56. }
  57. $count = $query->count();
  58. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  59. $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('status ASC,created_at DESC')->all();
  60. $new_list = [];
  61. /* @var Cash[] $list */
  62. foreach ($list as $index => $value) {
  63. $new_list[] = (object)[
  64. 'price' => $value->price,
  65. 'addtime' => date('Y-m-d H:i:s', $value->created_at),
  66. 'status'=> Cash::$status[$value->status],
  67. 'type'=> $value->type
  68. ];
  69. }
  70. $data = [
  71. 'row_count' => $count,//总数
  72. 'page_count' => $pagination->pageCount,//总页数
  73. 'list' => $new_list,
  74. ];
  75. return ['code' => 0, 'msg' => 'success', 'data' => $data];
  76. }
  77. }