DefaultController.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. <?php
  2. namespace app\modules\admin\controllers;
  3. use app\common\controllers\BController;
  4. use app\modules\admin\models\Attachment;
  5. use app\modules\doc\models\Doc;
  6. use app\modules\doc\models\DocPaylog;
  7. use app\modules\doc\models\DocReal;
  8. use app\modules\shopping\models\ShoppingOrder;
  9. use app\modules\ucenter\models\User;
  10. use app\modules\ucenter\models\UserApplyCert;
  11. use app\modules\ucenter\models\UserDetail;
  12. use app\modules\ucenter\models\UserLoginLog;
  13. use app\modules\ucenter\models\UserMoneyLog;
  14. use app\modules\ucenter\models\UserOpenAuth;
  15. use app\modules\ucenter\models\UserVipOrder;
  16. use app\modules\ucenter\models\UserWithdraw;
  17. use Yii;
  18. use app\modules\admin\models\AdminLoginForm;
  19. use app\modules\admin\models\ChangepwdForm;
  20. use app\modules\admin\models\Admin;
  21. use app\common\helpers\Cookie;
  22. class DefaultController extends BController
  23. {
  24. public $layout = 'main';
  25. //后台首页
  26. public function actionIndex()
  27. {
  28. $userInfo = $this->getIdentityInfo();
  29. $resourceList = $this->getMyResource();
  30. $haveBlock = [];
  31. foreach($resourceList as $resource)
  32. {
  33. $haveBlock[] = $resource['block'];
  34. }
  35. $haveBlock = array_unique($haveBlock);
  36. //设置默认打开页面
  37. $defaultUrl = '';
  38. foreach($resourceList as $resource)
  39. {
  40. if($resource['menu_type']==1&&!empty($resource['action']))
  41. {
  42. $defaultUrl = $this->createRealUrl($resource['module'].'/'.$resource['controller'].'/'.$resource['action']);
  43. $defaultMenuName = Yii::t('resource',$resource['name']);
  44. $defaultHash = $resource['hash'];
  45. break;
  46. }
  47. }
  48. return $this->renderPartial('index',array('resourceList'=>$resourceList,'haveBlock'=>$haveBlock,'userInfo'=>$userInfo,'defaultUrl'=>$defaultUrl,'defaultMenuName'=>$defaultMenuName,'defaultHash'=>$defaultHash));
  49. }
  50. //后台登录
  51. public function actionLogin()
  52. {
  53. if($this->hasLogined())
  54. {
  55. $this->showMessage(array('class'=>'success','message'=>'登录成功','url'=>$this->createRealUrl('admin/default/index'),'time'=>2000),1);
  56. }
  57. $model = new AdminLoginForm();
  58. if($model->load(Yii::$app->request->post())){
  59. if(!$model->validate())
  60. {
  61. $this->showMessage(array('class'=>'error', 'message'=>$model->returnFirstError(),'time'=>2000));
  62. }
  63. else
  64. {
  65. if(!$model->login())
  66. {
  67. $this->showMessage(array('class'=>'error', 'message'=>$model->returnFirstError(),'time'=>2000));
  68. }
  69. else
  70. {
  71. $this->showMessage(array('class'=>'success','message'=>'登录成功','url'=>$this->createRealUrl('admin/default/index'),'time'=>2000));
  72. }
  73. }
  74. }
  75. else
  76. {
  77. return $this->renderPartial('login',array('model'=>$model));
  78. }
  79. }
  80. //个人资料
  81. public function actionMyinfo()
  82. {
  83. $model = Admin::findOne($this->admin_id);
  84. if($model->load(Yii::$app->request->post())){
  85. //is_array($model->avatar) && $model->avatar && $model->avatar = implode(',', $model->avatar);
  86. if(!$model->validate())
  87. {
  88. Yii::$app->session->setFlash('error',$model->returnFirstError());
  89. }
  90. else
  91. {
  92. if($model->save())
  93. {
  94. Attachment::relateAttachmentByTable($model->avatar,'admin','avatar',$this->admin_id);
  95. Yii::$app->session->setFlash('success','操作成功');
  96. }
  97. else
  98. {
  99. Yii::$app->session->setFlash('error',$model->returnFirstError());
  100. }
  101. }
  102. }
  103. return $this->render('myinfo',array('model'=>$model));
  104. }
  105. //修改密码
  106. public function actionChangepwd()
  107. {
  108. $admin = Admin::findOne($this->admin_id);
  109. $model = new ChangepwdForm();
  110. if($model->load(Yii::$app->request->post())){
  111. if(!$model->validate())
  112. {
  113. Yii::$app->session->setFlash('error',$model->returnFirstError());
  114. }
  115. else
  116. {
  117. if(password($model->original_pwd,$admin->encrypt) == $admin->user_pwd)
  118. {
  119. $pwd = password($model->new_pwd);
  120. $admin->user_pwd = $pwd['password'];
  121. $admin->encrypt = $pwd['encrypt'];
  122. if($admin->save())
  123. {
  124. Yii::$app->session->setFlash('success','密码修改成功');
  125. }
  126. else
  127. {
  128. Yii::$app->session->setFlash('error',$admin->returnFirstError());
  129. }
  130. }
  131. else
  132. {
  133. Yii::$app->session->setFlash('error','当前密码不正确');
  134. }
  135. }
  136. }
  137. return $this->render('changepwd',array('model'=>$model));
  138. }
  139. //退出
  140. public function actionLogout()
  141. {
  142. try
  143. {
  144. Cookie::deleteCookie(Yii::$app->params['adminCookieName']);
  145. $this->showMessage(array('class'=>'success','message'=>'您已安全退出','url'=>$this->createRealUrl('admin/default/login'),'time'=>2000));
  146. }
  147. catch(\Exception $e)
  148. {
  149. throw new \Exception($e->getMessage(),500);
  150. }
  151. }
  152. //仪表盘
  153. public function actionDashboard()
  154. {
  155. $timeList = getTimeList(1);
  156. $totalSalesMoney = ShoppingOrder::find()->where('status>0')->sum('total_price');
  157. $docNum = DocReal::find()->where('is_delete=0')->count();
  158. $orderNum = ShoppingOrder::find()->where('status>0')->count();
  159. $userNum = User::find()->count();
  160. //今日注册
  161. $todayRegisterNum = User::find()->where("(register_time>=".$timeList['dayStart']." and register_time<=".$timeList['dayEnd'].")")->count();
  162. //昨日注册
  163. $predayRegisterNum = User::find()->where("(register_time>=".$timeList['predayStart']." and register_time<=".$timeList['predayEnd'].")")->count();
  164. if($todayRegisterNum>$predayRegisterNum&&$predayRegisterNum>0)
  165. {
  166. $todayRegisterPercents = '+ '.number_format(((($todayRegisterNum-$predayRegisterNum)/$predayRegisterNum)*100),2).'%';
  167. }
  168. else if($todayRegisterNum<$predayRegisterNum&&$predayRegisterNum>0)
  169. {
  170. $todayRegisterPercents = '- '.number_format(((($predayRegisterNum-$todayRegisterNum)/$predayRegisterNum)*100),2).'%';
  171. }
  172. else
  173. {
  174. $todayRegisterPercents = '+ 0%';
  175. }
  176. //今日上传
  177. $todayUploadNum = Doc::find()->where("(create_time>=".$timeList['dayStart']." and create_time<=".$timeList['dayEnd'].")")->count();
  178. $predayUploadNum = Doc::find()->where("(create_time>=".$timeList['predayStart']." and create_time<=".$timeList['predayEnd'].")")->count();
  179. if($todayUploadNum>$predayUploadNum&&$predayUploadNum>0)
  180. {
  181. $todayUploadPercents = '+ '.number_format(((($todayUploadNum-$predayUploadNum)/$predayUploadNum)*100),2).'%';
  182. }
  183. else if($todayUploadNum<$predayUploadNum&&$predayUploadNum>0)
  184. {
  185. $todayUploadPercents = '- '.number_format(((($predayUploadNum-$todayUploadNum)/$predayUploadNum)*100),2).'%';
  186. }
  187. else
  188. {
  189. $todayUploadPercents = '+ 0%';
  190. }
  191. //今日下载
  192. $todayPayNum = DocPaylog::find()->where("(create_time>=".$timeList['dayStart']." and create_time<=".$timeList['dayEnd'].")")->count();
  193. $predayPayNum = DocPaylog::find()->where("(create_time>=".$timeList['predayStart']." and create_time<=".$timeList['predayEnd'].")")->count();
  194. if($todayPayNum>$predayPayNum&&$predayPayNum>0)
  195. {
  196. $todaypayPercents = '+ '.number_format(((($todayPayNum-$predayPayNum)/$predayPayNum)*100),2).'%';
  197. }
  198. else if($todayPayNum<$predayPayNum&&$predayPayNum>0)
  199. {
  200. $todaypayPercents = '- '.number_format(((($predayPayNum-$todayPayNum)/$predayPayNum)*100),2).'%';
  201. }
  202. else
  203. {
  204. $todaypayPercents = '+ 0%';
  205. }
  206. //今日销售额
  207. $todaySales = ShoppingOrder::find()->where("(create_time>=".$timeList['dayStart']." and create_time<=".$timeList['dayEnd'].") and status>0")->sum('total_price');
  208. $predaySales = ShoppingOrder::find()->where("(create_time>=".$timeList['predayStart']." and create_time<=".$timeList['predayEnd'].") and status>0")->sum('total_price');
  209. if($todaySales>$predaySales&&$predaySales>0)
  210. {
  211. $todaysalesPercents = '+ '.number_format(((($todaySales-$predaySales)/$predaySales)*100),2).'%';
  212. }
  213. else if($todaySales<$predaySales&&$predaySales>0)
  214. {
  215. $todaysalesPercents = '- '.number_format(((($predaySales-$todaySales)/$predaySales)*100),2).'%';
  216. }
  217. else
  218. {
  219. $todaysalesPercents = '+ 0%';
  220. }
  221. //本月销售额
  222. $monthSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0")->sum('total_price');
  223. $premonthSales = ShoppingOrder::find()->where("(create_time>=".$timeList['premonthStart']." and create_time<=".$timeList['premonthEnd'].") and status>0")->sum('total_price');
  224. if($monthSales>$premonthSales&&$premonthSales>0)
  225. {
  226. $monthsalesPercents = '+ '.number_format(((($monthSales-$premonthSales)/$premonthSales)*100),2).'%';
  227. }
  228. else if($monthSales<$premonthSales&&$premonthSales>0)
  229. {
  230. $monthsalesPercents = '- '.number_format(((($premonthSales-$monthSales)/$premonthSales)*100),2).'%';
  231. }
  232. else
  233. {
  234. $monthsalesPercents = '+ 0%';
  235. }
  236. //本月提现金额
  237. $monthWithdraw = UserWithdraw::find()->where("(process_time>=".$timeList['monthStart']." and process_time<=".$timeList['monthEnd'].") and process_result=1")->sum('real_money');
  238. $premonthWithdraw = UserWithdraw::find()->where("(process_time>=".$timeList['premonthStart']." and process_time<=".$timeList['premonthEnd'].") and process_result=1")->sum('real_money');
  239. if($monthWithdraw>$premonthWithdraw&&$premonthWithdraw>0)
  240. {
  241. $monthwithdrawPercents = '+ '.number_format(((($monthWithdraw-$premonthWithdraw)/$premonthWithdraw)*100),2).'%';
  242. }
  243. else if($monthWithdraw<$premonthWithdraw&&$premonthWithdraw>0)
  244. {
  245. $monthwithdrawPercents = '- '.number_format(((($premonthWithdraw-$monthWithdraw)/$premonthWithdraw)*100),2).'%';
  246. }
  247. else
  248. {
  249. $monthwithdrawPercents = '+ 0%';
  250. }
  251. //获取月份数据
  252. $monthList = getLastAllMonthByNumber(6,get_date(TIMESTAMP,'Y-m'));
  253. //获取当月详细销售数据和用户注册数据
  254. $firstDate = get_date(TIMESTAMP,'Y-m-01');
  255. $days = get_days($firstDate,2);
  256. if(is_array($days))foreach($days as $day)
  257. {
  258. $unitdayStart = str_to_time($day.' 00:00:00');
  259. $unitdayEnd = str_to_time($day.' 23:59:59');
  260. $daySalesNum = ShoppingOrder::find()->where("(create_time>=".$unitdayStart." and create_time<=".$unitdayEnd.") and status>0")->sum('total_price');
  261. $dayRegisterNum = User::find()->where("(register_time>=".$unitdayStart." and register_time<=".$unitdayEnd.")")->count();
  262. $dayLoginNum = UserLoginLog::find()->where("(login_time>=".$unitdayStart." and login_time<=".$unitdayEnd.")")->distinct('user_id')->count();
  263. $dayVipNum = UserVipOrder::find()->where("(create_time>=".$unitdayStart." and create_time<=".$unitdayEnd.") and status=1")->count();
  264. $daysData[] = array('date'=>$day,'salesnum'=>$daySalesNum,'registernum'=>$dayRegisterNum,'loginnum'=>$dayLoginNum,'vipnum'=>$dayVipNum);
  265. }
  266. //月度销售额数据
  267. $monthCoinSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'coinrecharge%'")->sum('total_price');
  268. $monthVipSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'buyvip%'")->sum('total_price');
  269. $monthDocSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'buydoc%'")->sum('total_price');
  270. $monthCouponSales = ShoppingOrder::find()->where("(create_time>=".$timeList['monthStart']." and create_time<=".$timeList['monthEnd'].") and status>0 and pay_credit like 'uservipcoupon%'")->sum('total_price');
  271. $userInfo = $this->getIdentityInfo();
  272. 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));
  273. }
  274. //新旧版之间的数据同步
  275. public function actionSyndata()
  276. {
  277. $do = Yii::$app->request->get('do');
  278. //文档同步
  279. if($do=='doc')
  280. {
  281. $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();
  282. if(empty($doc))
  283. {
  284. exit("导入完成");
  285. }
  286. $cat = Yii::$app->db2->createCommand("select * from wz_category where cat_id=".$doc['cat_id']."")->queryOne();
  287. if(empty($cat))
  288. {
  289. Yii::$app->db2->createCommand("UPDATE wz_doc_real SET is_rotate=1 where id=".$doc['id'])->execute();
  290. echo "<script>";
  291. echo "window.location.reload();";
  292. echo "</script>";
  293. exit;
  294. }
  295. $newCat = \app\modules\cms\models\Category::find()->where("cat_name='".$cat['cat_name']."'")->orderBy(['parent_id'=>SORT_DESC])->one();
  296. if(empty($newCat))
  297. {
  298. Yii::$app->db2->createCommand("UPDATE wz_doc_real SET is_rotate=1 where id=".$doc['id'])->execute();
  299. echo "<script>";
  300. echo "window.location.reload();";
  301. echo "</script>";
  302. exit;
  303. }
  304. $parent_cat_ids = explode(",",$newCat->arr_parent_ids);
  305. $file = sys_auth($doc['file'],'DECODE',$doc['hash']);
  306. $fileUrl = 'https://www.gongwentang.com/upload/'.$file;
  307. $targetFile = UPLOAD_PATH.$file;
  308. dir_create(dirname($targetFile));
  309. file_put_contents($targetFile,https_request($fileUrl));
  310. if(file_exists($targetFile))
  311. {
  312. $params = Yii::$app->params;
  313. //上传设置(判断是否采用全路径)
  314. $attConfigInfo = \app\modules\admin\models\Config::find()->where("name='attachment'")->one();
  315. $attConfig = string2array($attConfigInfo->value);
  316. $ossConfigResult = \app\modules\admin\models\Config::find()->where("name='oss'")->one();
  317. $ossConfig = string2array($ossConfigResult['value']);
  318. $filePath = str_replace(UPLOAD_PATH,'',$targetFile);
  319. $fileUrl = UPLOAD_URL.$filePath;
  320. if($params['oss']['OPEN_OSS']==1)//如果开启了云存储,初始化存储对象
  321. {
  322. $oss = new \app\common\components\Oss();
  323. $initResult = $oss->init($ossConfig['OPEN_INTERNAL']);
  324. if($initResult['error']==0)
  325. {
  326. $result = $oss->Upload($targetFile,$filePath);
  327. if($result['error']==0)
  328. {
  329. $fileUrl = $result['data']['url'];
  330. $filePath = $attConfig['absolute_url']?$result['data']['url']:$result['data']['path'];
  331. //写入附件表
  332. $attachment = new \app\modules\admin\models\Attachment();
  333. $attachment->file_name = $doc['title'];
  334. $attachment->file_path = $filePath;
  335. $attachment->file_size = $doc['size'];
  336. $attachment->file_ext = $doc['ext'];
  337. $attachment->hash = md5($filePath);
  338. $attachment->upload_time = $doc['create_time'];
  339. $attachment->upload_ip = MYIP;
  340. $attachment->md5 = $doc['md5'];
  341. $attachment->status = 1;
  342. $attachment->list_order = 0;
  343. $attachment->folder = Yii::$app->request->post('folder','');
  344. if($attachment->save())
  345. {
  346. $newDoc = new \app\modules\doc\models\Doc();
  347. $mewdocData = new \app\modules\doc\models\DocData();
  348. $newDoc->cat_id = $newCat['cat_id'];
  349. $newDoc->parent_cat_id = intval($parent_cat_ids[1]);
  350. $newDoc->root_cat_id = intval($parent_cat_ids[count($parent_cat_ids)-1]);
  351. if(!empty($newCat->arr_parent_ids))
  352. {
  353. $newDoc->cat_ids = ",".join(",",array_reverse($parent_cat_ids)).",";
  354. }
  355. else
  356. {
  357. $newDoc->cat_ids = ",".$newCat['cat_id'].",";
  358. }
  359. $newDoc->doc_type = 1;
  360. $newDoc->title = $doc['title'];
  361. $newDoc->tags = $doc['tags'];
  362. $newDoc->md5 = $doc['md5'];
  363. $newDoc->ext = $doc['ext'];
  364. $newDoc->filesize = $doc['size'];
  365. $newDoc->vip_free = $doc['vip_free'];
  366. $newDoc->is_vip = $doc['is_vip'];
  367. $newDoc->coin_price = $doc['download_price'];
  368. $newDoc->views = $doc['views'];
  369. $newDoc->downs = $doc['downs'];
  370. $newDoc->status = 0;
  371. $newDoc->stars = 3;
  372. $newDoc->user_id = $doc['user_id'];
  373. $newDoc->user_name = $doc['user_name'];
  374. $newDoc->create_time = $doc['create_time'];
  375. $newDoc->update_time = $doc['update_time'];
  376. $newDoc->list_order = $doc['id'];
  377. $newDoc->ext_type_1 = $doc['ext_type1'];
  378. $newDoc->ext_type_2 = $doc['ext_type2'];
  379. $newDoc->ext_type_3 = $doc['ext_type3'];
  380. $newDoc->ext_type_4 = $doc['ext_type4'];
  381. $newDoc->ext_type_5 = $doc['ext_type5'];
  382. $newDoc->tags = initTags($newDoc);
  383. if($newDoc->save())
  384. {
  385. $mewdocData->id = $newDoc->id;
  386. $mewdocData->file = $filePath;
  387. $mewdocData->content = '';
  388. if($mewdocData->save())
  389. {
  390. if($mewdocData->file) \app\modules\admin\models\Attachment::relateAttachmentByTable($mewdocData->file,$mewdocData->shortTableName(),'file',$newDoc->id);
  391. if($newDoc->tags)refreshTag($newDoc->tags,$newDoc->shortTableName(),$newDoc->id,$newDoc->user_id);
  392. @unlink($targetFile);
  393. Yii::$app->db2->createCommand("UPDATE wz_doc_real SET is_rotate=1 where id=".$doc['id'])->execute();
  394. echo "<script>";
  395. echo "window.location.reload();";
  396. echo "</script>";
  397. exit;
  398. }
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. //自动审核
  407. if($do=='audit')
  408. {
  409. $url = APP_URL.'index.php?r=doc/default/multiaudit';
  410. $docList = Doc::find()->where("trans_status=1 and is_delete=0")->limit(1)->all();
  411. if(empty($docList))
  412. {
  413. exit('审核完毕');
  414. }
  415. else
  416. {
  417. if(is_array($docList))foreach($docList as $doc)
  418. {
  419. $ids[] = $doc->id;
  420. }
  421. $params1 = join(',',$ids);
  422. $result = Yii::$app->runAction('doc/default/multiaudit',['params1'=>$params1]);
  423. if($result['error']==0)
  424. {
  425. //exit('导入成功');
  426. echo "<script>";
  427. echo "window.location.reload();";
  428. echo "</script>";
  429. exit;
  430. }
  431. else
  432. {
  433. exit('出错了');
  434. }
  435. }
  436. }
  437. //用户同步
  438. if($do=='user')
  439. {
  440. $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();
  441. if(empty($userInfo))
  442. {
  443. exit("导入完成");
  444. }
  445. else
  446. {
  447. $userApplyCert = Yii::$app->db2->createCommand("select * from wz_user_apply_cert where user_id=".$userInfo['user_id']." order by id desc limit 1")->queryOne();
  448. $userOpenAuth = Yii::$app->db2->createCommand("select * from wz_user_open_auth where user_id=".$userInfo['user_id']." order by id desc limit 1")->queryOne();
  449. $user = User::findOne($userInfo['user_id']);
  450. if(empty($user))$user = new User();
  451. $userDetail = UserDetail::findOne($userInfo['user_id']);
  452. if(empty($userDetail))$userDetail = new UserDetail();
  453. $user->user_id = $userInfo['user_id'];
  454. $user->user_name = $userInfo['user_name'];
  455. $user->user_pwd = $userInfo['user_pwd'];
  456. $user->content_model_id = 1;
  457. $user->group_id = 1;
  458. $user->user_group_level = 1;
  459. $user->email = $userInfo['email'];
  460. $user->mobile = $userInfo['mobile'];
  461. $user->nick_name = $userInfo['nick_name'];
  462. $user->real_name = $userInfo['real_name'];
  463. $user->sex = $userInfo['sex'];
  464. $user->birthday = $userInfo['birthday'];
  465. $user->signature = $userInfo['signature'];
  466. $user->qq = $userInfo['qq'];
  467. $user->weixin = $userInfo['weixin'];
  468. $user->money = 0;
  469. $user->coin = 0;
  470. $user->coin_income = 0;
  471. $user->amount_coin_income = 0;
  472. $user->avatar = $userInfo['avatar']?$userInfo['avatar']:'';
  473. $user->request_from = 1;
  474. $user->register_time = $userInfo['register_time'];
  475. if($userInfo['cert_2'])$user->open_upload = 1;
  476. if($user->save())
  477. {
  478. $userDetail->user_id = $userInfo['user_id'];
  479. if($userInfo['mobile'])$userDetail->cert_1 = 1;
  480. if($userInfo['email']) $userDetail->cert_2 = 1;
  481. if($userInfo['cert_2'])$userDetail->cert_3 = 1;
  482. $userDetail->doc_num = $userInfo['doc_num'];
  483. if($userDetail->save())
  484. {
  485. if(!empty($userApplyCert))
  486. {
  487. $certModel = UserApplyCert::find()->where("user_id=".$userInfo['user_id']." and process=1")->one();
  488. if(empty($certModel))$certModel = new UserApplyCert();
  489. $certModel->user_id = $userApplyCert['user_id'];
  490. $certModel->cert_type = 3;
  491. $certModel->cert_info = $userApplyCert['cert_info'];
  492. $certModel->process = $userApplyCert['process'];
  493. $certModel->process_result = $userApplyCert['process_result'];
  494. $certModel->process_time = $userApplyCert['process_time'];
  495. $certModel->create_time = $userApplyCert['create_time'];
  496. $certModel->save();
  497. }
  498. if(!empty($userOpenAuth))
  499. {
  500. $authModel = UserOpenAuth::find()->where("user_id=".$userInfo['user_id'])->one();
  501. if(empty($authModel))$authModel = new UserOpenAuth();
  502. $authModel->user_id = $userInfo['user_id'];
  503. $authModel->app = $userOpenAuth['app'];
  504. $authModel->app_uid = $userOpenAuth['app_uid'];
  505. $authModel->user_info = $userOpenAuth['user_info'];
  506. $authModel->hash = $userOpenAuth['hash'];
  507. $authModel->bind_time = $userOpenAuth['bind_time'];
  508. $authModel->app_unionname = $userOpenAuth['app'];
  509. $authModel->save();
  510. }
  511. }
  512. Yii::$app->db2->createCommand("UPDATE wz_user SET have_message=1 where user_id=".$userInfo['user_id'])->execute();
  513. echo "<script>";
  514. echo "window.location.reload();";
  515. echo "</script>";
  516. exit;
  517. }
  518. }
  519. }
  520. //订单同步
  521. if($do=='order')
  522. {
  523. $vipInfo = Yii::$app->db2->createCommand("select * from wz_user_vip_order where status=1 order by order_id asc")->queryOne();
  524. if(empty($vipInfo))
  525. {
  526. exit("导入完成");
  527. }
  528. //VIP类型
  529. if($vipInfo['vip_type']==4)$vipInfo['vip_type']=1;
  530. if($vipInfo['vip_type']==3)$vipInfo['vip_type']=2;
  531. if($vipInfo['vip_type']==2)$vipInfo['vip_type']=3;
  532. if($vipInfo['vip_type']==1)$vipInfo['vip_type']=4;
  533. $userVipType = \app\modules\ucenter\models\UserVipType::findOne($vipInfo['vip_type']);
  534. //创建订单
  535. $order = new ShoppingOrder();
  536. $order->user_id = $vipInfo['user_id'];
  537. $order->order_sn = getUniOrderNo();
  538. $order->pay_credit = 'buyvip_'.$vipInfo['vip_type'];
  539. $order->total_price = $vipInfo['money'];$vipInfo['money'];
  540. $order->discount_price = 0;
  541. $order->remark = '开通VIP-'.$userVipType->title;
  542. $order->order_type = 3;
  543. $order->status = 9;
  544. $order->pay_time = $vipInfo['create_time'];
  545. $order->request_from = REQUEST_FROM;
  546. $order->create_time = $vipInfo['create_time'];
  547. if($order->save())
  548. {
  549. $userVipOrder = new UserVipOrder();
  550. $userVipOrder->order_id = $order->order_id;
  551. $userVipOrder->user_id = $vipInfo['user_id'];
  552. $userVipOrder->vip_type = $vipInfo['vip_type'];
  553. $userVipOrder->money = $vipInfo['money'];
  554. $userVipOrder->days = $userVipType->days;
  555. $userVipOrder->settings = $userVipType->settings;
  556. $userVipOrder->expire_time = $vipInfo['expire_time'];
  557. $userVipOrder->create_time = $vipInfo['create_time'];
  558. $userVipOrder->status = 1;
  559. $userVipOrder->save();
  560. Yii::$app->db2->createCommand("UPDATE wz_user_vip_order SET status=99 where order_id=".$vipInfo['order_id'])->execute();
  561. echo "<script>";
  562. echo "window.location.reload();";
  563. echo "</script>";
  564. exit;
  565. }
  566. }
  567. //重置栏目
  568. if($do=='cat')
  569. {
  570. $doc = DocReal::find()->where("sys_add=0 and doc_type=1")->limit(1)->one();
  571. if(empty($doc))
  572. {
  573. exit("更新完成");
  574. }
  575. $catList = \app\modules\cms\models\Category::find()->where("content_model_id=4 and description!=''")->all();
  576. foreach($catList as $cat)
  577. {
  578. $tags = explode(",",str_replace(array(",",","),array(",",","),$cat->description));
  579. foreach($tags as $tag)
  580. {
  581. if(strpos($doc->title,$tag)!==false)
  582. {
  583. $currentCat = $cat;
  584. $parent_cat_ids = explode(",",$cat->arr_parent_ids);
  585. $doc->parent_cat_id = intval($parent_cat_ids[1]);
  586. $doc->root_cat_id = intval($parent_cat_ids[count($parent_cat_ids)-1]);
  587. $doc->cat_id = $cat->cat_id;
  588. if(!empty($cat->arr_parent_ids))
  589. {
  590. $doc->cat_ids = ",".join(",",array_reverse($parent_cat_ids)).",";
  591. }
  592. else
  593. {
  594. $doc->cat_ids = ",".$doc->cat_id.",";
  595. }
  596. $doc->sys_add = 1;
  597. $doc->save();
  598. echo "<script>";
  599. echo "window.location.reload();";
  600. echo "</script>";
  601. exit;
  602. }
  603. }
  604. }
  605. $doc->sys_add = 2;
  606. $doc->save();
  607. echo "<script>";
  608. echo "window.location.reload();";
  609. echo "</script>";
  610. exit;
  611. }
  612. }
  613. //批量导入文档
  614. public function actionMultiupload()
  615. {
  616. $folder = Yii::$app->request->get('folder','files');//定义源文档存放目录名称
  617. $multiPath = APP_PATH.'multi'.DIRECTORY_SEPARATOR;
  618. $sourcePath = $multiPath.$folder.DIRECTORY_SEPARATOR;
  619. $bakPath = $multiPath.$folder.'_bak'.DIRECTORY_SEPARATOR;
  620. dir_create($bakPath);
  621. $path = $sourcePath;
  622. $dirTree = dir_tree($path);
  623. //如果有子目录,处理子目录
  624. if(!empty($dirTree))
  625. {
  626. $path = $dirTree[1]['dir'];
  627. $tag = $dirTree[1]['name'];
  628. $childPath = $path;
  629. }
  630. $url = get_url();
  631. $fileList = get_filenamesbydir(rtrim($path,DIRECTORY_SEPARATOR));
  632. //过滤文件
  633. if(is_array($fileList))foreach($fileList as $file)
  634. {
  635. $arr = pathinfo($file);
  636. if($arr['extension']=='php')continue;
  637. if(in_array($arr['extension'],['wav','flv','url']))//有些文件要删除
  638. {
  639. @unlink($file);
  640. continue;
  641. }
  642. else
  643. {
  644. $files[] = $file;
  645. }
  646. }
  647. $sourceFile = $files[0];
  648. //没有待处理文档了
  649. if(empty($sourceFile)){
  650. if($dirTree&&$childPath)
  651. {
  652. dir_delete($childPath);
  653. echo "<script>";
  654. echo "window.location.href='".$url."';";
  655. echo "</script>";
  656. }
  657. exit("上传完成");
  658. }
  659. if($this->doMultiUpload($sourceFile,$multiPath,$tag))
  660. {
  661. unlink($sourceFile);
  662. echo "<script>";
  663. echo "window.location.href='".$url."';";
  664. echo "</script>";
  665. }
  666. else
  667. {
  668. $originalFilename = basename($sourceFile);
  669. copy($sourceFile,$bakPath.$originalFilename);
  670. unlink($sourceFile);
  671. echo "<script>";
  672. echo "window.location.href='".$url."';";
  673. echo "</script>";
  674. }
  675. }
  676. //执行批量导入
  677. public function doMultiUpload($sourceFile,$multiPath,$tag)
  678. {
  679. //文件基本信息
  680. $title = basename($sourceFile,'.'.fileext($sourceFile));
  681. $filesize = filesize($sourceFile);
  682. $ext = fileext($sourceFile);
  683. $md5 = md5(file_get_contents($sourceFile));
  684. //配置文件
  685. require_once($multiPath.'config.php');
  686. $parent_cat_ids = explode(",",$arr_parent_ids);
  687. $childPath = date('Y',TIMESTAMP).DIRECTORY_SEPARATOR.date('m',TIMESTAMP).DIRECTORY_SEPARATOR.date('d',TIMESTAMP).DIRECTORY_SEPARATOR;
  688. $targetPath = UPLOAD_PATH.$childPath;
  689. $fileName = get_unique_file_name($targetPath,$ext);//文件重命名
  690. if (!is_dir($targetPath)) {
  691. dir_create($targetPath);
  692. }
  693. $targetFile = $targetPath . $fileName;
  694. if(copy($sourceFile,$targetFile))
  695. {
  696. if(file_exists($targetFile))
  697. {
  698. $md5 = md5(file_get_contents($targetFile));
  699. $exist = DocReal::find()->where("md5='".$md5."'")->exists();
  700. if($exist)
  701. {
  702. @unlink($targetFile);
  703. return true;
  704. }
  705. else
  706. {
  707. $params = Yii::$app->params;
  708. //上传设置(判断是否采用全路径)
  709. $attConfigInfo = \app\modules\admin\models\Config::find()->where("name='attachment'")->one();
  710. $attConfig = string2array($attConfigInfo->value);
  711. $ossConfigResult = \app\modules\admin\models\Config::find()->where("name='oss'")->one();
  712. $ossConfig = string2array($ossConfigResult['value']);
  713. $filePath = str_replace(UPLOAD_PATH,'',$targetFile);
  714. $fileUrl = UPLOAD_URL.$filePath;
  715. if($params['oss']['OPEN_OSS']==1)//如果开启了云存储,初始化存储对象
  716. {
  717. $oss = new \app\common\components\Oss();
  718. $initResult = $oss->init($ossConfig['OPEN_INTERNAL']);
  719. if($initResult['error']==0)
  720. {
  721. $result = $oss->Upload($targetFile,$filePath);
  722. if($result['error']==0)
  723. {
  724. $fileUrl = $result['data']['url'];
  725. $filePath = $attConfig['absolute_url']?$result['data']['url']:$result['data']['path'];
  726. }
  727. }
  728. }
  729. else
  730. {
  731. $filePath = $attConfig['absolute_url']?$fileUrl:$filePath;
  732. }
  733. //写入附件表
  734. $attachment = new \app\modules\admin\models\Attachment();
  735. $attachment->file_name = basename($sourceFile);
  736. $attachment->file_path = $filePath;
  737. $attachment->file_size = $filesize;
  738. $attachment->file_ext = $ext;
  739. $attachment->hash = md5($filePath);
  740. $attachment->upload_time = TIMESTAMP;
  741. $attachment->upload_ip = MYIP;
  742. $attachment->md5 = $md5;
  743. $attachment->status = 1;
  744. $attachment->list_order = 0;
  745. $attachment->folder = '';
  746. if($attachment->save())
  747. {
  748. $newDoc = new \app\modules\doc\models\Doc();
  749. $newdocData = new \app\modules\doc\models\DocData();
  750. $newDoc->cat_id = $cat_id;
  751. $newDoc->parent_cat_id = intval($parent_cat_ids[1]);
  752. $newDoc->root_cat_id = intval($parent_cat_ids[count($parent_cat_ids)-1]);
  753. if(!empty($arr_parent_ids))
  754. {
  755. $newDoc->cat_ids = ",".join(",",array_reverse($parent_cat_ids)).",";
  756. }
  757. else
  758. {
  759. $newDoc->cat_ids = ",".$cat_id.",";
  760. }
  761. $newDoc->doc_type = 1;
  762. $newDoc->title = $title;
  763. $newDoc->tags = $tags;
  764. $newDoc->md5 = $md5;
  765. $newDoc->ext = $ext;
  766. $newDoc->filesize = $filesize;
  767. $newDoc->vip_free = $vip_free;
  768. $newDoc->is_vip = $is_vip;
  769. $newDoc->coin_price = $coin_price;
  770. $newDoc->views = 0;
  771. $newDoc->downs = 0;
  772. $newDoc->status = 0;
  773. $newDoc->stars = $stars;
  774. $newDoc->user_id = $user_id;
  775. $newDoc->user_name = $user_name;
  776. $newDoc->create_time = TIMESTAMP;
  777. $newDoc->update_time = TIMESTAMP;
  778. $newDoc->list_order = 0;
  779. $newDoc->ext_type_1 = $ext_type_1;
  780. $newDoc->ext_type_2 = $ext_type_2;
  781. $newDoc->ext_type_3 = $ext_type_3;
  782. $newDoc->ext_type_4 = $ext_type_4;
  783. $newDoc->ext_type_5 = $ext_type_5;
  784. $newDoc->tags = initTags($newDoc);
  785. if($newDoc->save())
  786. {
  787. $newdocData->id = $newDoc->id;
  788. $newdocData->file = $filePath;
  789. $newdocData->content = '';
  790. if($newdocData->save())
  791. {
  792. if($newdocData->file) \app\modules\admin\models\Attachment::relateAttachmentByTable($newdocData->file,$newdocData->shortTableName(),'file',$newDoc->id);
  793. if($newDoc->tags)refreshTag($newDoc->tags,$newDoc->shortTableName(),$newDoc->id,$newDoc->user_id);
  794. if($params['oss']['OPEN_OSS']==1)@unlink($targetFile);
  795. return true;
  796. }
  797. else
  798. {
  799. echo $newdocData->returnFirstError();
  800. exit;
  801. }
  802. }
  803. else
  804. {
  805. echo $newDoc->returnFirstError();
  806. exit;
  807. }
  808. }
  809. }
  810. }
  811. }
  812. else
  813. {
  814. return false;
  815. }
  816. }
  817. }