request->isAjax && Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['page', 'user_id', 'business_user_id', 'store_type'], 'integer'], [['nickname', 'business_nickname', 'store_name'], 'string'], [['created_at', 'region_option'], 'safe'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [ ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED], ['=', 'store_type', $params['store_type']], ]; if ($params['store_name'] && $params['store_type'] == BusinessBonusEnums::STORE_TYPE_STORE) { $store_ids = Store::find() ->orWhere(['like', 'store_name', "%" . $params['store_name'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'store_id', $store_ids]; } if ($params['store_name'] && $params['store_type'] == BusinessBonusEnums::STORE_TYPE_MCH) { $store_ids = Mch::find() ->orWhere(['like', 'store_name', "%" . $params['store_name'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'store_id', $store_ids]; } if ($params['region_option'] && $params['store_type'] == BusinessBonusEnums::STORE_TYPE_STORE ) { list ($province_id, $city_id, $district_id) = $params['region_option']; $store_ids = Store::find() ->andWhere(['=', 'province_id', $province_id]) ->andWhere(['=', 'city_id', $city_id]) ->andWhere(['=', 'district_id', $district_id]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'store_id', $store_ids]; } if ($params['region_option'] && $params['store_type'] == BusinessBonusEnums::STORE_TYPE_MCH ) { list ($province_id, $city_id, $district_id) = $params['region_option']; $store_ids = Mch::find() ->andWhere(['=', 'province_id', $province_id]) ->andWhere(['=', 'city_id', $city_id]) ->andWhere(['=', 'district_id', $district_id]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'store_id', $store_ids]; } // 店主昵称 if ($params['nickname']) { $user_ids = User::find() ->orWhere(['like', 'nickname', "%" . $params['nickname'] . "%", false]) ->orWhere(['like', 'mobile', "%" . $params['nickname'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'store_user_id', $user_ids]; } // 招商员昵称 if ($params['business_nickname']) { $user_ids = User::find() ->orWhere(['like', 'nickname', "%" . $params['business_nickname'] . "%", false]) ->orWhere(['like', 'mobile', "%" . $params['business_nickname'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'business_user_id', $user_ids]; } // 店主 if ($params['user_id']) { $where[] = ['=', 'store_user_id', (int)$params['user_id']]; } // 招商员 if ($params['business_user_id']) { $where[] = ['=', 'business_user_id', (int)$params['business_user_id']]; } // 店铺创建时间 $start_time = strtotime($params['created_at'][0] ?? 0); $end_time = strtotime($params['created_at'][1] ?? 0); if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) { $where[] = ['>=', 'store_created_at', $start_time]; $where[] = ['<=', 'store_created_at', $end_time]; } $condition = ['where' => $where, 'with' => ['storeUser', 'businessUser'], 'order' => 'id desc']; if (Yii::$app->request->post('flag') == 'EXPORT') { $title = $params['store_type'] == BusinessBonusEnums::FROM_TYPE_STORE ? '招商分红门店列表' : '招商分红商户列表'; $filename = $title . '-' . date('YmdHis').'_'.rand(10000,99999); $post = Yii::$app->request->post(); $post['condition'] = $condition; $post['mall_id'] = $this->mall_id; $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_CASHIER, BusinessBonusStore::class,'exportHandle', $post); if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } $page_data = BusinessBonusStore::listPage($condition, false, true); $page_data['list'] = is_array($page_data['list']) ? $page_data['list'] : []; $page_data['list'] = BusinessBonusStore::dealStoreList($page_data['list'], $this->mall_id); $page_data['export_list'] = BusinessBonusStore::fieldsList(null, $params['store_type']); $this->success('获取成功', compact('page_data')); } else { return $this->render('index'); } } }