123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887 |
- <?php
- namespace app\modules\admin\controllers;
- use app\common\controllers\BController;
- use app\modules\admin\models\Attachment;
- use app\modules\doc\models\Doc;
- use app\modules\doc\models\DocPaylog;
- use app\modules\doc\models\DocReal;
- use app\modules\shopping\models\ShoppingOrder;
- use app\modules\ucenter\models\User;
- use app\modules\ucenter\models\UserApplyCert;
- use app\modules\ucenter\models\UserDetail;
- use app\modules\ucenter\models\UserLoginLog;
- use app\modules\ucenter\models\UserMoneyLog;
- use app\modules\ucenter\models\UserOpenAuth;
- use app\modules\ucenter\models\UserVipOrder;
- use app\modules\ucenter\models\UserWithdraw;
- use Yii;
- use app\modules\admin\models\AdminLoginForm;
- use app\modules\admin\models\ChangepwdForm;
- use app\modules\admin\models\Admin;
- use app\common\helpers\Cookie;
- class DefaultController extends BController
- {
- public $layout = 'main';
- //后台首页
- public function actionIndex()
- {
- $userInfo = $this->getIdentityInfo();
- $resourceList = $this->getMyResource();
- $haveBlock = [];
- foreach($resourceList as $resource)
- {
- $haveBlock[] = $resource['block'];
- }
- $haveBlock = array_unique($haveBlock);
- //设置默认打开页面
- $defaultUrl = '';
- foreach($resourceList as $resource)
- {
- if($resource['menu_type']==1&&!empty($resource['action']))
- {
- $defaultUrl = $this->createRealUrl($resource['module'].'/'.$resource['controller'].'/'.$resource['action']);
- $defaultMenuName = Yii::t('resource',$resource['name']);
- $defaultHash = $resource['hash'];
- break;
- }
- }
- return $this->renderPartial('index',array('resourceList'=>$resourceList,'haveBlock'=>$haveBlock,'userInfo'=>$userInfo,'defaultUrl'=>$defaultUrl,'defaultMenuName'=>$defaultMenuName,'defaultHash'=>$defaultHash));
- }
- //后台登录
- public function actionLogin()
- {
- if($this->hasLogined())
- {
- $this->showMessage(array('class'=>'success','message'=>'登录成功','url'=>$this->createRealUrl('admin/default/index'),'time'=>2000),1);
- }
- $model = new AdminLoginForm();
- if($model->load(Yii::$app->request->post())){
- if(!$model->validate())
- {
- $this->showMessage(array('class'=>'error', 'message'=>$model->returnFirstError(),'time'=>2000));
- }
- else
- {
- if(!$model->login())
- {
- $this->showMessage(array('class'=>'error', 'message'=>$model->returnFirstError(),'time'=>2000));
- }
- else
- {
- $this->showMessage(array('class'=>'success','message'=>'登录成功','url'=>$this->createRealUrl('admin/default/index'),'time'=>2000));
- }
- }
- }
- else
- {
- return $this->renderPartial('login',array('model'=>$model));
- }
- }
- //个人资料
- public function actionMyinfo()
- {
- $model = Admin::findOne($this->admin_id);
- if($model->load(Yii::$app->request->post())){
- //is_array($model->avatar) && $model->avatar && $model->avatar = implode(',', $model->avatar);
- if(!$model->validate())
- {
- Yii::$app->session->setFlash('error',$model->returnFirstError());
- }
- else
- {
- if($model->save())
- {
- Attachment::relateAttachmentByTable($model->avatar,'admin','avatar',$this->admin_id);
- Yii::$app->session->setFlash('success','操作成功');
- }
- else
- {
- Yii::$app->session->setFlash('error',$model->returnFirstError());
- }
- }
- }
- return $this->render('myinfo',array('model'=>$model));
- }
- //修改密码
- public function actionChangepwd()
- {
- $admin = Admin::findOne($this->admin_id);
- $model = new ChangepwdForm();
- if($model->load(Yii::$app->request->post())){
- if(!$model->validate())
- {
- Yii::$app->session->setFlash('error',$model->returnFirstError());
- }
- else
- {
- if(password($model->original_pwd,$admin->encrypt) == $admin->user_pwd)
- {
- $pwd = password($model->new_pwd);
- $admin->user_pwd = $pwd['password'];
- $admin->encrypt = $pwd['encrypt'];
- if($admin->save())
- {
- Yii::$app->session->setFlash('success','密码修改成功');
- }
- else
- {
- Yii::$app->session->setFlash('error',$admin->returnFirstError());
- }
- }
- else
- {
- Yii::$app->session->setFlash('error','当前密码不正确');
- }
- }
- }
- return $this->render('changepwd',array('model'=>$model));
- }
- //退出
- public function actionLogout()
- {
- try
- {
- Cookie::deleteCookie(Yii::$app->params['adminCookieName']);
- $this->showMessage(array('class'=>'success','message'=>'您已安全退出','url'=>$this->createRealUrl('admin/default/login'),'time'=>2000));
- }
- catch(\Exception $e)
- {
- throw new \Exception($e->getMessage(),500);
- }
- }
- //仪表盘
- public function actionDashboard()
- {
- $timeList = getTimeList(1);
- $totalSalesMoney = ShoppingOrder::find()->where('status>0')->sum('total_price');
- $docNum = DocReal::find()->where('is_delete=0')->count();
- $orderNum = ShoppingOrder::find()->where('status>0')->count();
- $userNum = User::find()->count();
- //今日注册
- $todayRegisterNum = User::find()->where("(register_time>=".$timeList['dayStart']." and register_time<=".$timeList['dayEnd'].")")->count();
- //昨日注册
- $predayRegisterNum = User::find()->where("(register_time>=".$timeList['predayStart']." and register_time<=".$timeList['predayEnd'].")")->count();
- if($todayRegisterNum>$predayRegisterNum&&$predayRegisterNum>0)
- {
- $todayRegisterPercents = '+ '.number_format(((($todayRegisterNum-$predayRegisterNum)/$predayRegisterNum)*100),2).'%';
- }
- else if($todayRegisterNum<$predayRegisterNum&&$predayRegisterNum>0)
- {
- $todayRegisterPercents = '- '.number_format(((($predayRegisterNum-$todayRegisterNum)/$predayRegisterNum)*100),2).'%';
- }
- else
- {
- $todayRegisterPercents = '+ 0%';
- }
- //今日上传
- $todayUploadNum = Doc::find()->where("(create_time>=".$timeList['dayStart']." and create_time<=".$timeList['dayEnd'].")")->count();
- $predayUploadNum = Doc::find()->where("(create_time>=".$timeList['predayStart']." and create_time<=".$timeList['predayEnd'].")")->count();
- if($todayUploadNum>$predayUploadNum&&$predayUploadNum>0)
- {
- $todayUploadPercents = '+ '.number_format(((($todayUploadNum-$predayUploadNum)/$predayUploadNum)*100),2).'%';
- }
- else if($todayUploadNum<$predayUploadNum&&$predayUploadNum>0)
- {
- $todayUploadPercents = '- '.number_format(((($predayUploadNum-$todayUploadNum)/$predayUploadNum)*100),2).'%';
- }
- else
- {
- $todayUploadPercents = '+ 0%';
- }
- //今日下载
- $todayPayNum = DocPaylog::find()->where("(create_time>=".$timeList['dayStart']." and create_time<=".$timeList['dayEnd'].")")->count();
- $predayPayNum = DocPaylog::find()->where("(create_time>=".$timeList['predayStart']." and create_time<=".$timeList['predayEnd'].")")->count();
- if($todayPayNum>$predayPayNum&&$predayPayNum>0)
- {
- $todaypayPercents = '+ '.number_format(((($todayPayNum-$predayPayNum)/$predayPayNum)*100),2).'%';
- }
- else if($todayPayNum<$predayPayNum&&$predayPayNum>0)
- {
- $todaypayPercents = '- '.number_format(((($predayPayNum-$todayPayNum)/$predayPayNum)*100),2).'%';
- }
- else
- {
- $todaypayPercents = '+ 0%';
- }
- //今日销售额
- $todaySales = ShoppingOrder::find()->where("(create_time>=".$timeList['dayStart']." and create_time<=".$timeList['dayEnd'].") and status>0")->sum('total_price');
- $predaySales = ShoppingOrder::find()->where("(create_time>=".$timeList['predayStart']." and create_time<=".$timeList['predayEnd'].") and status>0")->sum('total_price');
- if($todaySales>$predaySales&&$predaySales>0)
- {
- $todaysalesPercents = '+ '.number_format(((($todaySales-$predaySales)/$predaySales)*100),2).'%';
- }
- else if($todaySales<$predaySales&&$predaySales>0)
- {
- $todaysalesPercents = '- '.number_format(((($predaySales-$todaySales)/$predaySales)*100),2).'%';
- }
- else
- {
- $todaysalesPercents = '+ 0%';
- }
- //本月销售额
- $monthSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0")->sum('total_price');
- $premonthSales = ShoppingOrder::find()->where("(create_time>=".$timeList['premonthStart']." and create_time<=".$timeList['premonthEnd'].") and status>0")->sum('total_price');
- if($monthSales>$premonthSales&&$premonthSales>0)
- {
- $monthsalesPercents = '+ '.number_format(((($monthSales-$premonthSales)/$premonthSales)*100),2).'%';
- }
- else if($monthSales<$premonthSales&&$premonthSales>0)
- {
- $monthsalesPercents = '- '.number_format(((($premonthSales-$monthSales)/$premonthSales)*100),2).'%';
- }
- else
- {
- $monthsalesPercents = '+ 0%';
- }
- //本月提现金额
- $monthWithdraw = UserWithdraw::find()->where("(process_time>=".$timeList['monthStart']." and process_time<=".$timeList['monthEnd'].") and process_result=1")->sum('real_money');
- $premonthWithdraw = UserWithdraw::find()->where("(process_time>=".$timeList['premonthStart']." and process_time<=".$timeList['premonthEnd'].") and process_result=1")->sum('real_money');
- if($monthWithdraw>$premonthWithdraw&&$premonthWithdraw>0)
- {
- $monthwithdrawPercents = '+ '.number_format(((($monthWithdraw-$premonthWithdraw)/$premonthWithdraw)*100),2).'%';
- }
- else if($monthWithdraw<$premonthWithdraw&&$premonthWithdraw>0)
- {
- $monthwithdrawPercents = '- '.number_format(((($premonthWithdraw-$monthWithdraw)/$premonthWithdraw)*100),2).'%';
- }
- else
- {
- $monthwithdrawPercents = '+ 0%';
- }
- //获取月份数据
- $monthList = getLastAllMonthByNumber(6,get_date(TIMESTAMP,'Y-m'));
- //获取当月详细销售数据和用户注册数据
- $firstDate = get_date(TIMESTAMP,'Y-m-01');
- $days = get_days($firstDate,2);
- if(is_array($days))foreach($days as $day)
- {
- $unitdayStart = str_to_time($day.' 00:00:00');
- $unitdayEnd = str_to_time($day.' 23:59:59');
- $daySalesNum = ShoppingOrder::find()->where("(create_time>=".$unitdayStart." and create_time<=".$unitdayEnd.") and status>0")->sum('total_price');
- $dayRegisterNum = User::find()->where("(register_time>=".$unitdayStart." and register_time<=".$unitdayEnd.")")->count();
- $dayLoginNum = UserLoginLog::find()->where("(login_time>=".$unitdayStart." and login_time<=".$unitdayEnd.")")->distinct('user_id')->count();
- $dayVipNum = UserVipOrder::find()->where("(create_time>=".$unitdayStart." and create_time<=".$unitdayEnd.") and status=1")->count();
- $daysData[] = array('date'=>$day,'salesnum'=>$daySalesNum,'registernum'=>$dayRegisterNum,'loginnum'=>$dayLoginNum,'vipnum'=>$dayVipNum);
- }
- //月度销售额数据
- $monthCoinSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'coinrecharge%'")->sum('total_price');
- $monthVipSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'buyvip%'")->sum('total_price');
- $monthDocSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'buydoc%'")->sum('total_price');
- $monthCouponSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'uservipcoupon%'")->sum('total_price');
- $userInfo = $this->getIdentityInfo();
- return $this->render('dashboard',array('userInfo'=>$userInfo,'docNum'=>$docNum,'orderNum'=>$orderNum,'userNum'=>$userNum,'totalSalesMoney'=>$totalSalesMoney,'todayRegisterNum'=>$todayRegisterNum,'todayRegisterPercents'=>$todayRegisterPercents,'todayUploadNum'=>$todayUploadNum,'todayUploadPercents'=>$todayUploadPercents,'todayPayNum'=>$todayPayNum,'todaypayPercents'=>$todaypayPercents,'todaySales'=>$todaySales,'todaysalesPercents'=>$todaysalesPercents,'monthSales'=>$monthSales,'premonthSales'=>$premonthSales,'monthsalesPercents'=>$monthsalesPercents,'monthList'=>$monthList,'daysData'=>$daysData,'monthCoinSales'=>floatval($monthCoinSales),'monthVipSales'=>floatval($monthVipSales),'monthDocSales'=>floatval($monthDocSales),'monthCouponSales'=>floatval($monthCouponSales),'monthWithdraw'=>$monthWithdraw,'monthwithdrawPercents'=>$monthwithdrawPercents));
- }
- //新旧版之间的数据同步
- public function actionSyndata()
- {
- $do = Yii::$app->request->get('do');
- //文档同步
- if($do=='doc')
- {
- $doc = Yii::$app->db2->createCommand("select * from wz_doc_real where is_rotate=0 and doc_type=1 order by id asc limit 1")->queryOne();
- if(empty($doc))
- {
- exit("导入完成");
- }
- $cat = Yii::$app->db2->createCommand("select * from wz_category where cat_id=".$doc['cat_id']."")->queryOne();
- if(empty($cat))
- {
- Yii::$app->db2->createCommand("UPDATE wz_doc_real SET is_rotate=1 where id=".$doc['id'])->execute();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- $newCat = \app\modules\cms\models\Category::find()->where("cat_name='".$cat['cat_name']."'")->orderBy(['parent_id'=>SORT_DESC])->one();
- if(empty($newCat))
- {
- Yii::$app->db2->createCommand("UPDATE wz_doc_real SET is_rotate=1 where id=".$doc['id'])->execute();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- $parent_cat_ids = explode(",",$newCat->arr_parent_ids);
- $file = sys_auth($doc['file'],'DECODE',$doc['hash']);
- $fileUrl = 'https://www.gongwentang.com/upload/'.$file;
- $targetFile = UPLOAD_PATH.$file;
- dir_create(dirname($targetFile));
- file_put_contents($targetFile,https_request($fileUrl));
- if(file_exists($targetFile))
- {
- $params = Yii::$app->params;
- //上传设置(判断是否采用全路径)
- $attConfigInfo = \app\modules\admin\models\Config::find()->where("name='attachment'")->one();
- $attConfig = string2array($attConfigInfo->value);
- $ossConfigResult = \app\modules\admin\models\Config::find()->where("name='oss'")->one();
- $ossConfig = string2array($ossConfigResult['value']);
- $filePath = str_replace(UPLOAD_PATH,'',$targetFile);
- $fileUrl = UPLOAD_URL.$filePath;
- if($params['oss']['OPEN_OSS']==1)//如果开启了云存储,初始化存储对象
- {
- $oss = new \app\common\components\Oss();
- $initResult = $oss->init($ossConfig['OPEN_INTERNAL']);
- if($initResult['error']==0)
- {
- $result = $oss->Upload($targetFile,$filePath);
- if($result['error']==0)
- {
- $fileUrl = $result['data']['url'];
- $filePath = $attConfig['absolute_url']?$result['data']['url']:$result['data']['path'];
- //写入附件表
- $attachment = new \app\modules\admin\models\Attachment();
- $attachment->file_name = $doc['title'];
- $attachment->file_path = $filePath;
- $attachment->file_size = $doc['size'];
- $attachment->file_ext = $doc['ext'];
- $attachment->hash = md5($filePath);
- $attachment->upload_time = $doc['create_time'];
- $attachment->upload_ip = MYIP;
- $attachment->md5 = $doc['md5'];
- $attachment->status = 1;
- $attachment->list_order = 0;
- $attachment->folder = Yii::$app->request->post('folder','');
- if($attachment->save())
- {
- $newDoc = new \app\modules\doc\models\Doc();
- $mewdocData = new \app\modules\doc\models\DocData();
- $newDoc->cat_id = $newCat['cat_id'];
- $newDoc->parent_cat_id = intval($parent_cat_ids[1]);
- $newDoc->root_cat_id = intval($parent_cat_ids[count($parent_cat_ids)-1]);
- if(!empty($newCat->arr_parent_ids))
- {
- $newDoc->cat_ids = ",".join(",",array_reverse($parent_cat_ids)).",";
- }
- else
- {
- $newDoc->cat_ids = ",".$newCat['cat_id'].",";
- }
- $newDoc->doc_type = 1;
- $newDoc->title = $doc['title'];
- $newDoc->tags = $doc['tags'];
- $newDoc->md5 = $doc['md5'];
- $newDoc->ext = $doc['ext'];
- $newDoc->filesize = $doc['size'];
- $newDoc->vip_free = $doc['vip_free'];
- $newDoc->is_vip = $doc['is_vip'];
- $newDoc->coin_price = $doc['download_price'];
- $newDoc->views = $doc['views'];
- $newDoc->downs = $doc['downs'];
- $newDoc->status = 0;
- $newDoc->stars = 3;
- $newDoc->user_id = $doc['user_id'];
- $newDoc->user_name = $doc['user_name'];
- $newDoc->create_time = $doc['create_time'];
- $newDoc->update_time = $doc['update_time'];
- $newDoc->list_order = $doc['id'];
- $newDoc->ext_type_1 = $doc['ext_type1'];
- $newDoc->ext_type_2 = $doc['ext_type2'];
- $newDoc->ext_type_3 = $doc['ext_type3'];
- $newDoc->ext_type_4 = $doc['ext_type4'];
- $newDoc->ext_type_5 = $doc['ext_type5'];
- $newDoc->tags = initTags($newDoc);
- if($newDoc->save())
- {
- $mewdocData->id = $newDoc->id;
- $mewdocData->file = $filePath;
- $mewdocData->content = '';
- if($mewdocData->save())
- {
- if($mewdocData->file) \app\modules\admin\models\Attachment::relateAttachmentByTable($mewdocData->file,$mewdocData->shortTableName(),'file',$newDoc->id);
- if($newDoc->tags)refreshTag($newDoc->tags,$newDoc->shortTableName(),$newDoc->id,$newDoc->user_id);
- @unlink($targetFile);
- Yii::$app->db2->createCommand("UPDATE wz_doc_real SET is_rotate=1 where id=".$doc['id'])->execute();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- }
- }
- }
- }
- }
- }
- }
- //自动审核
- if($do=='audit')
- {
- $url = APP_URL.'index.php?r=doc/default/multiaudit';
- $docList = Doc::find()->where("trans_status=1 and is_delete=0")->limit(1)->all();
- if(empty($docList))
- {
- exit('审核完毕');
- }
- else
- {
- if(is_array($docList))foreach($docList as $doc)
- {
- $ids[] = $doc->id;
- }
- $params1 = join(',',$ids);
- $result = Yii::$app->runAction('doc/default/multiaudit',['params1'=>$params1]);
- if($result['error']==0)
- {
- //exit('导入成功');
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- else
- {
- exit('出错了');
- }
- }
- }
- //用户同步
- if($do=='user')
- {
- $userInfo = Yii::$app->db2->createCommand("select * from wz_user as a left join wz_user_detail as b on a.user_id=b.user_id where a.have_message=0 order by a.user_id asc limit 1")->queryOne();
- if(empty($userInfo))
- {
- exit("导入完成");
- }
- else
- {
- $userApplyCert = Yii::$app->db2->createCommand("select * from wz_user_apply_cert where user_id=".$userInfo['user_id']." order by id desc limit 1")->queryOne();
- $userOpenAuth = Yii::$app->db2->createCommand("select * from wz_user_open_auth where user_id=".$userInfo['user_id']." order by id desc limit 1")->queryOne();
- $user = User::findOne($userInfo['user_id']);
- if(empty($user))$user = new User();
- $userDetail = UserDetail::findOne($userInfo['user_id']);
- if(empty($userDetail))$userDetail = new UserDetail();
- $user->user_id = $userInfo['user_id'];
- $user->user_name = $userInfo['user_name'];
- $user->user_pwd = $userInfo['user_pwd'];
- $user->content_model_id = 1;
- $user->group_id = 1;
- $user->user_group_level = 1;
- $user->email = $userInfo['email'];
- $user->mobile = $userInfo['mobile'];
- $user->nick_name = $userInfo['nick_name'];
- $user->real_name = $userInfo['real_name'];
- $user->sex = $userInfo['sex'];
- $user->birthday = $userInfo['birthday'];
- $user->signature = $userInfo['signature'];
- $user->qq = $userInfo['qq'];
- $user->weixin = $userInfo['weixin'];
- $user->money = 0;
- $user->coin = 0;
- $user->coin_income = 0;
- $user->amount_coin_income = 0;
- $user->avatar = $userInfo['avatar']?$userInfo['avatar']:'';
- $user->request_from = 1;
- $user->register_time = $userInfo['register_time'];
- if($userInfo['cert_2'])$user->open_upload = 1;
- if($user->save())
- {
- $userDetail->user_id = $userInfo['user_id'];
- if($userInfo['mobile'])$userDetail->cert_1 = 1;
- if($userInfo['email']) $userDetail->cert_2 = 1;
- if($userInfo['cert_2'])$userDetail->cert_3 = 1;
- $userDetail->doc_num = $userInfo['doc_num'];
- if($userDetail->save())
- {
- if(!empty($userApplyCert))
- {
- $certModel = UserApplyCert::find()->where("user_id=".$userInfo['user_id']." and process=1")->one();
- if(empty($certModel))$certModel = new UserApplyCert();
- $certModel->user_id = $userApplyCert['user_id'];
- $certModel->cert_type = 3;
- $certModel->cert_info = $userApplyCert['cert_info'];
- $certModel->process = $userApplyCert['process'];
- $certModel->process_result = $userApplyCert['process_result'];
- $certModel->process_time = $userApplyCert['process_time'];
- $certModel->create_time = $userApplyCert['create_time'];
- $certModel->save();
- }
- if(!empty($userOpenAuth))
- {
- $authModel = UserOpenAuth::find()->where("user_id=".$userInfo['user_id'])->one();
- if(empty($authModel))$authModel = new UserOpenAuth();
- $authModel->user_id = $userInfo['user_id'];
- $authModel->app = $userOpenAuth['app'];
- $authModel->app_uid = $userOpenAuth['app_uid'];
- $authModel->user_info = $userOpenAuth['user_info'];
- $authModel->hash = $userOpenAuth['hash'];
- $authModel->bind_time = $userOpenAuth['bind_time'];
- $authModel->app_unionname = $userOpenAuth['app'];
- $authModel->save();
- }
- }
- Yii::$app->db2->createCommand("UPDATE wz_user SET have_message=1 where user_id=".$userInfo['user_id'])->execute();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- }
- }
- //订单同步
- if($do=='order')
- {
- $vipInfo = Yii::$app->db2->createCommand("select * from wz_user_vip_order where status=1 order by order_id asc")->queryOne();
- if(empty($vipInfo))
- {
- exit("导入完成");
- }
- //VIP类型
- if($vipInfo['vip_type']==4)$vipInfo['vip_type']=1;
- if($vipInfo['vip_type']==3)$vipInfo['vip_type']=2;
- if($vipInfo['vip_type']==2)$vipInfo['vip_type']=3;
- if($vipInfo['vip_type']==1)$vipInfo['vip_type']=4;
- $userVipType = \app\modules\ucenter\models\UserVipType::findOne($vipInfo['vip_type']);
- //创建订单
- $order = new ShoppingOrder();
- $order->user_id = $vipInfo['user_id'];
- $order->order_sn = getUniOrderNo();
- $order->pay_credit = 'buyvip_'.$vipInfo['vip_type'];
- $order->total_price = $vipInfo['money'];$vipInfo['money'];
- $order->discount_price = 0;
- $order->remark = '开通VIP-'.$userVipType->title;
- $order->order_type = 3;
- $order->status = 9;
- $order->pay_time = $vipInfo['create_time'];
- $order->request_from = REQUEST_FROM;
- $order->create_time = $vipInfo['create_time'];
- if($order->save())
- {
- $userVipOrder = new UserVipOrder();
- $userVipOrder->order_id = $order->order_id;
- $userVipOrder->user_id = $vipInfo['user_id'];
- $userVipOrder->vip_type = $vipInfo['vip_type'];
- $userVipOrder->money = $vipInfo['money'];
- $userVipOrder->days = $userVipType->days;
- $userVipOrder->settings = $userVipType->settings;
- $userVipOrder->expire_time = $vipInfo['expire_time'];
- $userVipOrder->create_time = $vipInfo['create_time'];
- $userVipOrder->status = 1;
- $userVipOrder->save();
- Yii::$app->db2->createCommand("UPDATE wz_user_vip_order SET status=99 where order_id=".$vipInfo['order_id'])->execute();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- }
- //重置栏目
- if($do=='cat')
- {
- $doc = DocReal::find()->where("sys_add=0 and doc_type=1")->limit(1)->one();
- if(empty($doc))
- {
- exit("更新完成");
- }
- $catList = \app\modules\cms\models\Category::find()->where("content_model_id=4 and description!=''")->all();
- foreach($catList as $cat)
- {
- $tags = explode(",",str_replace(array(",",","),array(",",","),$cat->description));
- foreach($tags as $tag)
- {
- if(strpos($doc->title,$tag)!==false)
- {
- $currentCat = $cat;
- $parent_cat_ids = explode(",",$cat->arr_parent_ids);
- $doc->parent_cat_id = intval($parent_cat_ids[1]);
- $doc->root_cat_id = intval($parent_cat_ids[count($parent_cat_ids)-1]);
- $doc->cat_id = $cat->cat_id;
- if(!empty($cat->arr_parent_ids))
- {
- $doc->cat_ids = ",".join(",",array_reverse($parent_cat_ids)).",";
- }
- else
- {
- $doc->cat_ids = ",".$doc->cat_id.",";
- }
- $doc->sys_add = 1;
- $doc->save();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- }
- }
- $doc->sys_add = 2;
- $doc->save();
- echo "<script>";
- echo "window.location.reload();";
- echo "</script>";
- exit;
- }
- }
- //批量导入文档
- public function actionMultiupload()
- {
- $folder = Yii::$app->request->get('folder','files');//定义源文档存放目录名称
- $multiPath = APP_PATH.'multi'.DIRECTORY_SEPARATOR;
- $sourcePath = $multiPath.$folder.DIRECTORY_SEPARATOR;
- $bakPath = $multiPath.$folder.'_bak'.DIRECTORY_SEPARATOR;
- dir_create($bakPath);
- $path = $sourcePath;
- $dirTree = dir_tree($path);
- //如果有子目录,处理子目录
- if(!empty($dirTree))
- {
- $path = $dirTree[1]['dir'];
- $tag = $dirTree[1]['name'];
- $childPath = $path;
- }
- $url = get_url();
- $fileList = get_filenamesbydir(rtrim($path,DIRECTORY_SEPARATOR));
- //过滤文件
- if(is_array($fileList))foreach($fileList as $file)
- {
- $arr = pathinfo($file);
- if($arr['extension']=='php')continue;
- if(in_array($arr['extension'],['wav','flv','url']))//有些文件要删除
- {
- @unlink($file);
- continue;
- }
- else
- {
- $files[] = $file;
- }
- }
- $sourceFile = $files[0];
- //没有待处理文档了
- if(empty($sourceFile)){
- if($dirTree&&$childPath)
- {
- dir_delete($childPath);
- echo "<script>";
- echo "window.location.href='".$url."';";
- echo "</script>";
- }
- exit("上传完成");
- }
- if($this->doMultiUpload($sourceFile,$multiPath,$tag))
- {
- unlink($sourceFile);
- echo "<script>";
- echo "window.location.href='".$url."';";
- echo "</script>";
- }
- else
- {
- $originalFilename = basename($sourceFile);
- copy($sourceFile,$bakPath.$originalFilename);
- unlink($sourceFile);
- echo "<script>";
- echo "window.location.href='".$url."';";
- echo "</script>";
- }
- }
- //执行批量导入
- public function doMultiUpload($sourceFile,$multiPath,$tag)
- {
- //文件基本信息
- $title = basename($sourceFile,'.'.fileext($sourceFile));
- $filesize = filesize($sourceFile);
- $ext = fileext($sourceFile);
- $md5 = md5(file_get_contents($sourceFile));
- //配置文件
- require_once($multiPath.'config.php');
- $parent_cat_ids = explode(",",$arr_parent_ids);
- $childPath = date('Y',TIMESTAMP).DIRECTORY_SEPARATOR.date('m',TIMESTAMP).DIRECTORY_SEPARATOR.date('d',TIMESTAMP).DIRECTORY_SEPARATOR;
- $targetPath = UPLOAD_PATH.$childPath;
- $fileName = get_unique_file_name($targetPath,$ext);//文件重命名
- if (!is_dir($targetPath)) {
- dir_create($targetPath);
- }
- $targetFile = $targetPath . $fileName;
- if(copy($sourceFile,$targetFile))
- {
- if(file_exists($targetFile))
- {
- $md5 = md5(file_get_contents($targetFile));
- $exist = DocReal::find()->where("md5='".$md5."'")->exists();
- if($exist)
- {
- @unlink($targetFile);
- return true;
- }
- else
- {
- $params = Yii::$app->params;
- //上传设置(判断是否采用全路径)
- $attConfigInfo = \app\modules\admin\models\Config::find()->where("name='attachment'")->one();
- $attConfig = string2array($attConfigInfo->value);
- $ossConfigResult = \app\modules\admin\models\Config::find()->where("name='oss'")->one();
- $ossConfig = string2array($ossConfigResult['value']);
- $filePath = str_replace(UPLOAD_PATH,'',$targetFile);
- $fileUrl = UPLOAD_URL.$filePath;
- if($params['oss']['OPEN_OSS']==1)//如果开启了云存储,初始化存储对象
- {
- $oss = new \app\common\components\Oss();
- $initResult = $oss->init($ossConfig['OPEN_INTERNAL']);
- if($initResult['error']==0)
- {
- $result = $oss->Upload($targetFile,$filePath);
- if($result['error']==0)
- {
- $fileUrl = $result['data']['url'];
- $filePath = $attConfig['absolute_url']?$result['data']['url']:$result['data']['path'];
- }
- }
- }
- else
- {
- $filePath = $attConfig['absolute_url']?$fileUrl:$filePath;
- }
- //写入附件表
- $attachment = new \app\modules\admin\models\Attachment();
- $attachment->file_name = basename($sourceFile);
- $attachment->file_path = $filePath;
- $attachment->file_size = $filesize;
- $attachment->file_ext = $ext;
- $attachment->hash = md5($filePath);
- $attachment->upload_time = TIMESTAMP;
- $attachment->upload_ip = MYIP;
- $attachment->md5 = $md5;
- $attachment->status = 1;
- $attachment->list_order = 0;
- $attachment->folder = '';
- if($attachment->save())
- {
- $newDoc = new \app\modules\doc\models\Doc();
- $newdocData = new \app\modules\doc\models\DocData();
- $newDoc->cat_id = $cat_id;
- $newDoc->parent_cat_id = intval($parent_cat_ids[1]);
- $newDoc->root_cat_id = intval($parent_cat_ids[count($parent_cat_ids)-1]);
- if(!empty($arr_parent_ids))
- {
- $newDoc->cat_ids = ",".join(",",array_reverse($parent_cat_ids)).",";
- }
- else
- {
- $newDoc->cat_ids = ",".$cat_id.",";
- }
- $newDoc->doc_type = 1;
- $newDoc->title = $title;
- $newDoc->tags = $tags;
- $newDoc->md5 = $md5;
- $newDoc->ext = $ext;
- $newDoc->filesize = $filesize;
- $newDoc->vip_free = $vip_free;
- $newDoc->is_vip = $is_vip;
- $newDoc->coin_price = $coin_price;
- $newDoc->views = 0;
- $newDoc->downs = 0;
- $newDoc->status = 0;
- $newDoc->stars = $stars;
- $newDoc->user_id = $user_id;
- $newDoc->user_name = $user_name;
- $newDoc->create_time = TIMESTAMP;
- $newDoc->update_time = TIMESTAMP;
- $newDoc->list_order = 0;
- $newDoc->ext_type_1 = $ext_type_1;
- $newDoc->ext_type_2 = $ext_type_2;
- $newDoc->ext_type_3 = $ext_type_3;
- $newDoc->ext_type_4 = $ext_type_4;
- $newDoc->ext_type_5 = $ext_type_5;
- $newDoc->tags = initTags($newDoc);
- if($newDoc->save())
- {
- $newdocData->id = $newDoc->id;
- $newdocData->file = $filePath;
- $newdocData->content = '';
- if($newdocData->save())
- {
- if($newdocData->file) \app\modules\admin\models\Attachment::relateAttachmentByTable($newdocData->file,$newdocData->shortTableName(),'file',$newDoc->id);
- if($newDoc->tags)refreshTag($newDoc->tags,$newDoc->shortTableName(),$newDoc->id,$newDoc->user_id);
- if($params['oss']['OPEN_OSS']==1)@unlink($targetFile);
- return true;
- }
- else
- {
- echo $newdocData->returnFirstError();
- exit;
- }
- }
- else
- {
- echo $newDoc->returnFirstError();
- exit;
- }
- }
- }
- }
- }
- else
- {
- return false;
- }
- }
- }
|