request; if ($retuest->isAjax) { if ($retuest->isPost) { $params = Yii::$app->request->post(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($params,[ [['name'], 'string'], [['create_time'],'safe'] ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = []; $time = time(); if(!empty($params['name'])){ $user_ids = IssueCouponsRule::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'name', $params['name'] . '%', false])->asArray()->column(); if (empty($user_ids)) $this->success('查无此用户'); $where[] = ['in', 'rule_id', $user_ids]; }; if($params['create_time']) $where[] = ['between', 'created_at', strtotime($params['create_time'][0]),strtotime($params['create_time'][1])]; $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $order = 'id desc'; $params = array('where' => $where, 'with'=>['rule'], 'order'=>$order, 'limit' => $params['limit']); $list = IssueCouponsStatistics::listPage($params, false, true); if($list['list']){ foreach ($list['list'] as $k => $v){ if($v['rule']['coupon']){ $coupon = json_decode($v['rule']['coupon'],true); if($coupon){ $coupon_array = array_sum(array_column($coupon,'num')); $list['list'][$k]['rule']['coupon_num'] = $coupon_array; } } if($v['rule']['e_coupon']){ $e_coupon = json_decode($v['rule']['e_coupon'],true); if($e_coupon){ $e_coupon_array = array_sum(array_column($e_coupon,'num')); $list['list'][$k]['rule']['e_coupon_num'] = $e_coupon_array; } } } } $list['now_time'] = time(); $this->success('获取成功', $list); } } else { return $this->render($this->action->id); } } }