WithdrawSearch.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace backend\models\searches;
  3. use backend\models\WithdrawApi;
  4. use Yii;
  5. use yii\data\ArrayDataProvider;
  6. use yii\data\Pagination;
  7. class WithdrawSearch extends DataTable
  8. {
  9. public $sTime;
  10. public $eTime;
  11. public $memberId;
  12. public $type;
  13. /**
  14. * @inheritdoc
  15. */
  16. public function rules()
  17. {
  18. $rules = parent::rules();
  19. $rules[] = [['sTime', 'eTime', 'memberId', 'type'], 'safe'];
  20. return $rules;
  21. }
  22. /**
  23. * @param array $params
  24. * @param null|string $from
  25. * @return ArrayDataProvider
  26. */
  27. public function search($params, $from = null)
  28. {
  29. $this->setAttributes($params);
  30. // 初始化DataTable查询参数
  31. $this->initSearchParams();
  32. $pagination = new Pagination();
  33. $pagination->setPageSize($this->pageSize);
  34. $data['pageSize'] = $pagination->getPageSize();
  35. $data['page'] = $this->page;
  36. if ($this->orderBy) {
  37. $data['orderBy'] = $this->orderBy;
  38. }
  39. if (!empty($this->search['value']) && trim($this->search['value']) !== '') {
  40. $data['search'] = trim($this->search['value']);
  41. }
  42. if ($from == 'admin') {
  43. $data['from'] = $from;
  44. if ($this->sTime && ($inTimeStart = strtotime($this->sTime))) {
  45. $data['inTimeStart'] = $inTimeStart * 1000;
  46. }
  47. if ($this->eTime && ($inTimeEnd = strtotime($this->eTime))) {
  48. $data['inTimeEnd'] = $inTimeEnd * 1000;
  49. }
  50. $this->memberId && $data['memberId'] = $this->memberId;
  51. is_numeric($this->type) && $data['type'] = $this->type;
  52. } else {
  53. $data['memberId'] = Yii::$app->getUser()->getId();
  54. }
  55. $api = new WithdrawApi();
  56. $result = $api->getWithdrawList($data);
  57. $models = [];
  58. if ($result['code'] == 1) {
  59. $models = (array)$result['data']['dataList'];
  60. $pagination->totalCount = $result['data']['totalCount'];
  61. }
  62. $dataProvider = new ArrayDataProvider([
  63. 'models' => $models,
  64. 'pagination' => $pagination,
  65. 'totalCount' => $pagination->totalCount,
  66. ]);
  67. return $dataProvider;
  68. }
  69. }