CashListForm.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1;
  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 $status;
  16. public $page;
  17. public $limit;
  18. public $cash_type = -1;
  19. public function rules()
  20. {
  21. return [
  22. [['page', 'limit', 'status',], 'integer'],
  23. [['page',], 'default', 'value' => 1],
  24. [['limit',], 'default', 'value' => 10],
  25. [['cash_type'], 'safe'],
  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. 'store_id'=>$this->store_id,
  39. 'user_id'=>$this->user_id
  40. ]);
  41. if ($this->cash_type > -1) {
  42. $query->andWhere([
  43. 'cash_type' => $this->cash_type
  44. ]);
  45. }
  46. if ($this->status == 0 && $this->status != null) { //待审核
  47. $query->andWhere(['status'=>0]);
  48. }
  49. if ($this->status == 1) {//待打款
  50. $query->andWhere(['status'=>1]);
  51. }
  52. if ($this->status == 2) {//已打款
  53. $query->andWhere(['in','status',[2,4,5]]);
  54. }
  55. if ($this->status == 3) {//无效
  56. $query->andWhere(['status'=>3]);
  57. }
  58. $count = $query->count();
  59. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  60. $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('status ASC,created_at DESC')->all();
  61. $new_list = [];
  62. /* @var Cash[] $list */
  63. foreach ($list as $index => $value) {
  64. $new_list[] = (object)[
  65. 'type_name' => Cash::getTypeName($value),
  66. 'price' => number_format(($value->price - ($value->price * ($value->service_charge / 100))), 2),
  67. 'addtime' => date('Y-m-d H:i:s', $value->created_at),
  68. 'wx_cash_status'=> $value->wx_cash_status,
  69. 'wx_cash_error'=> $value->wx_cash_error,
  70. 'status_no'=> $value->status,
  71. 'status'=> Cash::$status[$value->status],
  72. 'id' => $value->id
  73. ];
  74. }
  75. $data = [
  76. 'row_count' => $count,//总数
  77. 'page_count' => $pagination->pageCount,//总页数
  78. 'list' => $new_list,
  79. ];
  80. return ['code' => 0, 'msg' => 'success', 'data' => $data];
  81. }
  82. }