| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace addons\WriteOff\backend\controllers;
- use Yii;
- use common\controllers\AddonsController;
- use addons\WriteOff\common\models\WriteOffAwardLog;
- use addons\WriteOff\common\models\WriteOffCommissionJob;
- use addons\WriteOff\common\models\WriteOffPromoteOrderLog;
- use common\models\user\User;
- use common\enums\StatusEnum;
- use common\models\order\OrderDetail;
- use addons\WriteOff\common\enums\WriteOffEnum;
- use common\helpers\csv\CsvExportHelper;
- use common\enums\DownloadEnum;
- class AchievementController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- if (!empty($get['date_start']) && !empty($get['date_end'])) {
- $where[] = ['between', 'created_at', strtotime($get['date_start']), strtotime($get['date_end'])];
- }
- $maxMoney = $get['max_money'] > $get['min_money'] ? $get['max_money'] : $get['min_money'];
- $minMoney = $get['max_money'] > $get['min_money'] ? $get['min_money'] : $get['max_money'];
- if (!empty($get['max_money']) && !empty($get['min_money'])) {
- $where[] = ['between', 'award_money', $minMoney, $maxMoney];
- } elseif (!empty($this->max_money)) {
- $where[] = ['<=', 'award_money', $get['max_money']];
- } elseif (!empty($this->min_money)) {
- $where[] = ['>=', 'award_money', $get['min_money']];
- }
- $params['order'] = 'id desc';
- $params['where'] = $where;
- $params['limit'] = 10;
- $list = WriteOffAwardLog::listPage($params, false);
- $sum = WriteOffAwardLog::find()->where(['mall_id'=>$this->mall_id])->select('sum(award_money) as money')->asArray()->one();
- $count = WriteOffCommissionJob::find()->where(['mall_id'=>$this->mall_id])->count();
- $returnData['sum'] = [
- 'award_money' => $sum['money'] ?? 0,
- 'grant_num' => $count,
- ];
- if(!empty($list['list'])){
- $user_id_arr = array_column($list['list'],'user_id');
- $user_arr = User::lists([
- 'where'=>[
- ['id'=>$user_id_arr]
- ],
- 'index'=>'id',
- ]);
- foreach($list['list'] as &$item){
- if(isset($user_arr[$item['user_id']])){
- $item['user'] = $user_arr[$item['user_id']];
- }
- }
- }
- $returnData["list"] = $list;
- return $this->success('success', $returnData);
- }
- }
- return $this->render('index', []);
- }
- /**
- * 详情
- *
- * @return string
- */
- public function actionDetail()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $data = \Yii::$app->request->post();
- $filename = '业绩详情'.date('Y-m-d',$data['created_at']).'-' . date('YmdHis');
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ASSETS,WriteOffPromoteOrderLog::class,'exportAssets',$data);
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=','user_id',$get['user_id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- // 获取配置
- $config = Yii::$app->services->setting->addons->get($this->mall_id, WriteOffEnum::ADDONS_NAME, 'basic');
- $compute_period = $config['compute_period'];
- $start_day = 0;
- $end_day = 0;
- switch ($config['compute_period']) {
- case 0:
- if (date('d') != 1) $continue = true;// 非当月1号直接退出
- $start_day = date("Ym01", strtotime("-1 month",$get['created_at']));
- $end_day = date('Ymd', strtotime(date('Y-m', $get['created_at']) . '-01 00:00:00') - 86400);
- break;
- }
- $start_day = strtotime($start_day);
- $end_day = strtotime(date('Y-m-d 23:59:59',strtotime($end_day)));
- $where[] = ['between', 'created_at', $start_day, $end_day];
- if (!empty($get['date_start']) && !empty($get['date_end'])) {
- $where[] = ['between', 'created_at', strtotime($get['date_start']), strtotime($get['date_end'])];
- }
- if(!empty($get['order_no'])){
- $where[] = ['=','order_no',$get['order_no']];
- }
- // 根据搜索手机号查询用户id
- if (!empty($get['keyword'])) {
- $user_ids = User::find()->select("id")
- ->where(['mall_id' => $this->mall_id])
- ->andWhere([
- 'or',
- ['=', 'id', $get['keyword']],
- ['like', 'mobile', $get['keyword'] . '%', false],
- ['like', 'nickname', $get['keyword'] . '%', false]
- ])
- ->asArray()
- ->column();
- $where[] = ['in', 'buy_user_id', $user_ids];
- }
- $params['order'] = 'id desc';
- $params['where'] = $where;
- $params['limit'] = 10;
- $list = WriteOffPromoteOrderLog::listPage($params, false);
- if(!empty($list['list'])){
- $user_id_arr = array_column($list['list'],'buy_user_id');
- $user_arr = User::lists([
- 'where'=>[
- ['id'=>$user_id_arr]
- ],
- 'index'=>'id',
- ]);
- $order_detail_ids = array_column($list['list'],'order_detail_id');
- $order_detail_list = OrderDetail::lists([
- 'where'=>[
- ['id'=>$order_detail_ids]
- ],
- 'index'=>'id',
- ]);
- foreach($list['list'] as &$item){
- if(isset($user_arr[$item['buy_user_id']])){
- $item['user'] = $user_arr[$item['buy_user_id']];
- }
- if(!empty($order_detail_list[$item['order_detail_id']])){
- $item['goods_name'] = $order_detail_list[$item['order_detail_id']]['goods_name'];
- }
- }
- }
- $list['export_list'] = WriteOffPromoteOrderLog::exportFieldsList();
- return $this->success('success', $list);
- }
- }
- return $this->render('detail', []);
- }
- }
|