| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace addons\ElectronCoupon\backend\controllers;
- use addons\ElectronCoupon\common\models\ElectronCoupon;
- use addons\ElectronCoupon\common\models\ElectronCouponApprovalIncomeLog;
- use Yii;
- use common\controllers\AddonsController;
- use common\enums\StatusEnum;
- use common\models\user\User;
- class IncomeLogController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 收益明细
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['page', 'user_id'], 'integer'],
- [['profit_time'], 'safe'],
- [['user_name'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [
- ['=', 'mall_id', $this->mall_id],
- ['>=', 'status', StatusEnum::DISABLED],
- ];
- if ($params['user_id']) {
- $where[] = ['=', 'user_id', (int)$params['user_id']];
- }
- // 昵称、手机号
- if ($params['user_name']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $params['user_name'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $params['user_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 收益时间
- $start_time = strtotime($params['profit_time'][0] ?? 0);
- $end_time = strtotime($params['profit_time'][1] ?? 0);
- if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) {
- $where[] = ['>=', 'created_at', $start_time];
- $where[] = ['<=', 'created_at', $end_time];
- }
- $condition = ['where' => $where, 'with' => ['user'], 'order' => 'id desc'];
- $page_data = ElectronCouponApprovalIncomeLog::listPage($condition, false, true);
- $page_data['list'] = is_array($page_data['list']) ? $page_data['list'] : [];
- // 关联电子券
- $coupon_id_array = array_unique(array_filter(array_column($page_data['list'], 'e_coupon_id')));
- $e_coupon = ElectronCoupon::find()
- ->select('id,name,is_proper')
- ->where(['>=', 'status', StatusEnum::DISABLED])
- ->where(['mall_id' => $this->mall_id])
- ->where(['in', 'id', $coupon_id_array])
- ->asArray()
- ->all();
- $coupon_name_data = array_column($e_coupon, null, 'id');
- foreach ($page_data['list'] as $index => $item) {
- // 电子券名称
- $item['coupon'] = $coupon_name_data[$item['e_coupon_id']] ?? '';
- $page_data['list'][$index] = $item;
- }
- $this->success('获取成功', compact('page_data'));
- } else {
- return $this->render('index');
- }
- }
- }
|