| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace addons\Dianqian\backend\controllers;
- use addons\Dianqian\common\models\DianqianApply;
- use common\enums\DownloadEnum;
- use common\enums\StatusEnum;
- use common\helpers\csv\CsvExportHelper;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Dianqian\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 申请列表
- * @Author: lun
- * @DateTime: 2023/5/11 0011 19:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id','sign_status','mobile'], 'integer'],
- [['start_at','end_at'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = $list = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
- !empty($get['mobile']) && $where[] = ['=', 'mobile', $get['mobile']];
- !empty($get['sign_status']) && $where[] = ['=', 'sign_status', $get['sign_status']];
- if (!empty($get['start_at']) && !empty($get['end_at'])) {
- $where[] = ['between', 'created_at', strtotime($get['start_at']), strtotime($get['end_at'])];
- }
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $with = ['user'];
- $order = 'created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit']);
- $list = DianqianApply::listPage($params, false, true);
- $list['export_list'] = DianqianApply::fieldsList();
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 状态修改
- * @Author: lun
- * @DateTime: 2023/5/11 0011 19:05
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionHandle()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'required'],
- [['id','sign_status','status'], 'integer'],
- [['reason','remark'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params = DianqianApply::exceptNullVal($params);
- $params['mall_id'] = $this->mall_id;
- $res = DianqianApply::setData($params);
- if (!$res) return $this->error('修改失败:msg=' . DianqianApply::getStaticError());
- return $this->success('修改成功');
- }
- }
- }
- /**
- * 导出
- * @Author: lun
- * @DateTime: 2023/5/13 0013 14:11
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionApplyExport()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isPost && $retuest->post('flag') == 'EXPORT') {
- $post = Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = '电子签约列表-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename,DownloadEnum::TYPE_STATISTICS,DianqianApply::class,'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- }
|