ClaimController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace addons\Certificate\backend\controllers;
  3. use addons\Certificate\common\models\CertificateClaim;
  4. use common\enums\StatusEnum;
  5. use common\models\user\User;
  6. use Yii;
  7. use yii\db\Exception;
  8. /**
  9. * 默认控制器
  10. *
  11. * Class DefaultController
  12. * @package addons\Car\backend\controllers
  13. */
  14. class ClaimController extends BaseController
  15. {
  16. public $enableCsrfValidation = false;
  17. /**
  18. * 首页
  19. *
  20. * @return string
  21. */
  22. public function actionIndex()
  23. {
  24. $retuest = Yii::$app->request;
  25. if ($retuest->isAjax) {
  26. if ($retuest->isGet) {
  27. $params = Yii::$app->request->get();
  28. // 检查提交的参数
  29. $res = Yii::$app->services->validate->validate($params,[
  30. [['id','user_id','user_keyword','create_time'], 'safe'],
  31. [['limit'],'default','value' => '15'],
  32. ]);
  33. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  34. $where = [];
  35. if (!empty($params['user_keyword'])) {
  36. $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $params['user_keyword'] . '%', false])->asArray()->column();
  37. $user_name = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $params['user_keyword'] . '%', false])->asArray()->column();
  38. $user_ids = $user_ids + $user_name;
  39. if (empty($user_ids)) $this->success('查无此用户');
  40. $where[] = ['in', 'user_id', $user_ids];
  41. }
  42. if($params['create_time']) $where[] = ['between', 'created_at', strtotime($params['create_time'][0]),strtotime($params['create_time'][1])];
  43. if(!empty($params['user_id'])) $where[] = ['=', 'user_id', $params['user_id']];
  44. $with = ['user','certificate'];
  45. $where[] = ['=', 'mall_id', $this->mall_id];
  46. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  47. $order = 'id desc';
  48. $params = array('where' => $where, 'order'=>$order, 'with'=>$with, 'limit' => $params['limit']);
  49. $list = CertificateClaim::listPage($params, false, true);
  50. $this->success('获取成功', $list);
  51. }
  52. } else {
  53. return $this->render($this->action->id);
  54. }
  55. }
  56. }