DefaultController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace addons\Dianqian\backend\controllers;
  3. use addons\Dianqian\common\models\DianqianApply;
  4. use common\enums\DownloadEnum;
  5. use common\enums\StatusEnum;
  6. use common\helpers\csv\CsvExportHelper;
  7. use Yii;
  8. /**
  9. * 默认控制器
  10. *
  11. * Class DefaultController
  12. * @package addons\Dianqian\backend\controllers
  13. */
  14. class DefaultController extends BaseController
  15. {
  16. public $enableCsrfValidation = false;
  17. /**
  18. * 申请列表
  19. * @Author: lun
  20. * @DateTime: 2023/5/11 0011 19:07
  21. * @Copyright: copyright (c) 2021 广东七件事集团
  22. * @return mixed|string|void
  23. */
  24. public function actionIndex()
  25. {
  26. $retuest = Yii::$app->request;
  27. if ($retuest->isAjax) {
  28. if ($retuest->isGet) {
  29. $get = Yii::$app->request->get();
  30. // 检查提交的参数
  31. $res = Yii::$app->services->validate->validate($get,[
  32. [['user_id','sign_status','mobile'], 'integer'],
  33. [['start_at','end_at'], 'safe'],
  34. ]);
  35. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  36. $where = $list = [];
  37. $where[] = ['=', 'mall_id', $this->mall_id];
  38. !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
  39. !empty($get['mobile']) && $where[] = ['=', 'mobile', $get['mobile']];
  40. !empty($get['sign_status']) && $where[] = ['=', 'sign_status', $get['sign_status']];
  41. if (!empty($get['start_at']) && !empty($get['end_at'])) {
  42. $where[] = ['between', 'created_at', strtotime($get['start_at']), strtotime($get['end_at'])];
  43. }
  44. $where[] = ['=', 'status', StatusEnum::ENABLED];
  45. $with = ['user'];
  46. $order = 'created_at desc';
  47. $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit']);
  48. $list = DianqianApply::listPage($params, false, true);
  49. $list['export_list'] = DianqianApply::fieldsList();
  50. $this->success('获取成功', $list);
  51. }
  52. } else {
  53. return $this->render($this->action->id);
  54. }
  55. }
  56. /**
  57. * 状态修改
  58. * @Author: lun
  59. * @DateTime: 2023/5/11 0011 19:05
  60. * @Copyright: copyright (c) 2021 广东七件事集团
  61. * @return mixed|void
  62. */
  63. public function actionHandle()
  64. {
  65. $request = Yii::$app->request;
  66. if ($request->isAjax) {
  67. if ($request->isGet) {
  68. $params = Yii::$app->request->get();
  69. // 检查提交的参数
  70. $res = Yii::$app->services->validate->validate($params,[
  71. [['id'], 'required'],
  72. [['id','sign_status','status'], 'integer'],
  73. [['reason','remark'], 'string'],
  74. ]);
  75. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  76. $params = DianqianApply::exceptNullVal($params);
  77. $params['mall_id'] = $this->mall_id;
  78. $res = DianqianApply::setData($params);
  79. if (!$res) return $this->error('修改失败:msg=' . DianqianApply::getStaticError());
  80. return $this->success('修改成功');
  81. }
  82. }
  83. }
  84. /**
  85. * 导出
  86. * @Author: lun
  87. * @DateTime: 2023/5/13 0013 14:11
  88. * @Copyright: copyright (c) 2021 广东七件事集团
  89. * @return mixed|void
  90. */
  91. public function actionApplyExport()
  92. {
  93. $retuest = Yii::$app->request;
  94. if ($retuest->isPost && $retuest->post('flag') == 'EXPORT') {
  95. $post = Yii::$app->request->post();
  96. $post['mall_id'] = $this->mall_id;
  97. $filename = '电子签约列表-' . date('YmdHis').'_'.rand(10000,99999);
  98. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename,DownloadEnum::TYPE_STATISTICS,DianqianApply::class,'exportHandle', $post);
  99. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  100. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  101. }
  102. }
  103. }