SetInteractive.class.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <?php
  2. namespace Cas\Controller\Admin\Activity;
  3. use Cas\Module\Lottery;
  4. use Cas\Dao\PlatformBulletin;
  5. use KIF\Core\Request;
  6. use Cas\Dao\LotteryEvents;
  7. use Cas\Controller\Admin\Controller;
  8. use Cas\Dao\Platform;
  9. use KIF\Core\Config;
  10. use Cas\Dao\LotteryPrize;
  11. use Cas\Dao\LotteryEventsVote;
  12. use Cas\Dao\LotteryEventsCodeData;
  13. use KIF\String\Filter;
  14. use KIF\Page\Page;
  15. use Cas\Module\LotteryDraw;
  16. use KIF\Cache\Memcached;
  17. use KIF\Dao\SqlHelper;
  18. /**
  19. * ["活动相关" - "互动设置" ]
  20. * 页面: 显示&修改 doPageShow
  21. *
  22. * @author lihuanchun 
  23. *
  24. * 表单设置 [模板]
  25. * 事件:
  26. * 1.修改 doReqUpForm
  27. *
  28. * 奖项设置 [模板]
  29. * 事件:
  30. * 1.添加奖项 doReqAddPrize
  31. * 2.修改奖项 doReqUpPrize
  32. * 3.加减奖项数量
  33. * 3.1 增加奖项数量[虚拟,实物] doReqAddPrizeNum
  34. * 3.2 减少奖项数量[实物] doReqMinusPrizeNum
  35. *
  36. * 投票设置 [模板]
  37. * 事件:
  38. * 1.初始化 投票属性 图片类|| 文字类 doReqInitVote
  39. * 2.创建一个投票项 doReqCreateOneVote
  40. * 3.修改一个投票项 doUpOneVote
  41. *
  42. * 获奖数据列表 [模板]
  43. * 页面:PageLotteryDataList&events_id= (prize_id= )
  44. *
  45. * 券设置 [模板]
  46. * 事件:
  47. * 1.修改 券名称||券图片 doReqUpCode
  48. * 2.添加券 doReqEventCode
  49. */
  50. class SetInteractive extends Controller {
  51. private $objLottery; // 活动后端
  52. private $operatorData;
  53. private $showActivityTypeArr; // 当前页面包含的活动
  54. /**
  55. *  初始化
  56. */
  57. public function __construct() {
  58. header ( "Content-Type: text/html; charset=utf-8" );
  59. $this->objLottery = new Lottery ();
  60. $this->operatorData = $this->getUser ();
  61. # 能在当前页面显示的活动
  62. $this->showActivityTypeArr = array(
  63. LotteryEvents::TYPE_EVENTS_TURNTABLE,
  64. LotteryEvents::TYPE_EVENTS_SCRATCH,
  65. LotteryEvents::TYPE_EVENTS_LETTERS,
  66. LotteryEvents::TYPE_EVENTS_TRY,
  67. LotteryEvents::TYPE_EVENTS_VOTE,
  68. LotteryEvents::TYPE_EVENTS_INVITATION,
  69. LotteryEvents::TYPE_EVENTS_CODE,
  70. LotteryEvents::TYPE_EVENTS_OTHER,
  71. LotteryEvents::TYPE_EVENTS_SURVEY,
  72. );
  73. $events_id = isset($_REQUEST['events_id'])?$_REQUEST['events_id'] : null;
  74. if($events_id){
  75. $this->setNowUpPage($events_id, 'Interactive');
  76. }
  77. }
  78. /**
  79. * 默认
  80. */
  81. public function doDefault() {
  82. }
  83. /**
  84. * 页面: 显示&修改
  85. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=PageShow&events_id=nnn
  86. * 参数: events_id 活动ID
  87. */
  88. public function doPageShow() {
  89. $events_id = Request::g ( 'events_id' );
  90. $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  91. // lsm_ep($events_Data);
  92. // 载入修改页面需要用到的配置
  93. $eventsDeliveryType = LotteryEvents::getDeliveryType (); // // [活动] 发货状态
  94. $eventsAuthorize = LotteryEvents::getAuthorize (); // [活动] 授权
  95. $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示
  96. $eventsTwoDimensionalCodeType = LotteryEvents::getTwoDimensionalCodeType (); // [领券活动] 是否是二维码输出 类型
  97. $eventsTypeData = LotteryEvents::getType (); // [活动] 类型
  98. $eventsBigTypeConfig = LotteryEvents::getBigTypeConfig (); // [活动] 大类
  99. $eventsFormRegular = $this->formRegular (); // [活动] 表单
  100. $prizeDisplay = LotteryPrize::getDisplay (); // [奖项] 显示状态
  101. $prizeExpress = LotteryPrize::getExpress (); // [奖项] 是否需要快递
  102. $prizeType = LotteryPrize::getType (); // [奖项] 类型
  103. $voteType = LotteryEvents::getVoteType();
  104. // 投票
  105. $voteData = null;
  106. if ($events_Data ['events'] ['type'] == \Cas\Dao\LotteryEvents::TYPE_EVENTS_VOTE) {
  107. $objDLotteryEventsVote = new LotteryEventsVote ();
  108. $voteData = $objDLotteryEventsVote->getThisEventData ( $events_id );
  109. }
  110. // 领码
  111. if ($events_Data ['events'] ['type'] == \Cas\Dao\LotteryEvents::TYPE_EVENTS_CODE) {
  112. $voteData = null;
  113. $objEventsCodeData = new LotteryEventsCodeData ();
  114. $useCodeDataNum = $objEventsCodeData->getEventsUseCodeDataNum ( $events_id );
  115. $codeDataNum = $objEventsCodeData->getEventsCodeDataNum ( $events_id );
  116. $this->setOutput ( 'codeDataNum', $codeDataNum );
  117. $this->setOutput ( 'useCodeDataNum', $useCodeDataNum );
  118. }
  119. $objMemcached = new Memcached();
  120. $objMLotteryDraw = new LotteryDraw(null,$events_id);
  121. foreach($events_Data['prize'] as $key=> $prize){
  122. $lottery_prize_draw_next_time_key = $objMLotteryDraw->getCacheKeyOfNextWinTime($key);
  123. $events_Data['prize'][$key]['nextTime'] = $objMemcached->get($lottery_prize_draw_next_time_key);
  124. }
  125. if ($events_Data['events']['forms']) {
  126. foreach ($events_Data['events']['forms'] as $tmpkey => $tmpval) {
  127. if ($tmpval['type'] == 'select') {
  128. $events_Data['events']['forms'][$tmpkey]['options'] = implode("\n", $tmpval['options']);
  129. }
  130. }
  131. }
  132. $this->setOutput ( 'eventsDeliveryType', $eventsDeliveryType );
  133. $this->setOutput ( 'eventsAuthorize', $eventsAuthorize );
  134. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  135. $this->setOutput ( 'eventsTwoDimensionalCodeType', $eventsTwoDimensionalCodeType );
  136. $this->setOutput ( 'eventsTypeData', $eventsTypeData );
  137. $this->setOutput('typeData', $eventsTypeData);
  138. $this->setOutput ( 'eventsBigTypeConfig', $eventsBigTypeConfig );
  139. $this->setOutput ( 'eventsFormRegular', $eventsFormRegular );
  140. $this->setOutput ( 'prizeDisplay', $prizeDisplay );
  141. $this->setOutput ( 'prizeExpress', $prizeExpress );
  142. $this->setOutput ( 'prizeType', $prizeType );
  143. $this->setOutput('events_Data', $events_Data);
  144. $this->setOutput('eventData', $events_Data['events']);
  145. $this->setOutput('voteType', $voteType);
  146. $this->setOutput('voteData', $voteData);
  147. $this->setOutput('vote_id', Request::g('vote_id'));
  148. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  149. // 注:互动区根据配置 调用不同模板
  150. switch ($events_Data['events']['type']) {
  151. case LotteryEvents::TYPE_EVENTS_TURNTABLE: //大转盘
  152. if (Request::g('edit')) {
  153. $this->tpl = 'admin/activity/interactive_prize_edit';
  154. $prize_id = Request::g('prize_id');
  155. $prize = $events_Data['prize'][$prize_id];
  156. $prize['white_list'] = implode("\n", $prize['white_list']);
  157. $prize['hundred_percent_list'] = implode("\n", $prize['hundred_percent_list']);
  158. $prize['black_list'] = implode("\n", $prize['black_list']);
  159. $this->setOutput('prize_id', $prize_id);
  160. $this->setOutput('prize', $prize);
  161. } else if (Request::g('incr')) {
  162. $this->tpl = 'admin/activity/interactive_prize_incr';
  163. } else if (Request::g('decr')) {
  164. $this->tpl = 'admin/activity/interactive_prize_decr';
  165. } else {
  166. $this->tpl = 'admin/activity/interactive_prize';
  167. }
  168. break;
  169. case LotteryEvents::TYPE_EVENTS_SCRATCH: //刮刮卡
  170. if (Request::g('edit')) {
  171. $this->tpl = 'admin/activity/interactive_prize_edit';
  172. $prize_id = Request::g('prize_id');
  173. $prize = $events_Data['prize'][$prize_id];
  174. $prize['white_list'] = implode("\n", $prize['white_list']);
  175. $prize['hundred_percent_list'] = implode("\n", $prize['hundred_percent_list']);
  176. $prize['black_list'] = implode("\n", $prize['black_list']);
  177. $this->setOutput('prize_id', $prize_id);
  178. $this->setOutput('prize', $prize);
  179. } else if (Request::g('incr')) {
  180. $this->tpl = 'admin/activity/interactive_prize_incr';
  181. } else if (Request::g('decr')) {
  182. $this->tpl = 'admin/activity/interactive_prize_decr';
  183. } else {
  184. $this->tpl = 'admin/activity/interactive_prize';
  185. }
  186. break;
  187. case LotteryEvents::TYPE_EVENTS_TRY: //试用
  188. $this->tpl = 'admin/activity/interactive_input';
  189. break;
  190. case LotteryEvents::TYPE_EVENTS_SURVEY: //问卷调查
  191. $typ = Request::g('typ');
  192. $this->setOutput('typ', $typ);
  193. if($typ == 'input'){
  194. $this->tpl = 'admin/activity/interactive_input';
  195. break;
  196. }
  197. if($typ == 'prize'){
  198. $this->tpl = 'admin/activity/interactive_add_survey_prize';
  199. break;
  200. }
  201. if($typ == 'question'){
  202. $nextSort = 0;
  203. if(isset($events_Data['events']['survery_question'])){
  204. foreach ($events_Data['events']['survery_question'] as $key => $data){
  205. $nextSort = $key;
  206. }
  207. }
  208. $nextSort ++;
  209. $this->setOutput('nextSort', $nextSort);
  210. $this->tpl = 'admin/activity/interactive_question';
  211. break;
  212. }
  213. $this->tpl = 'admin/activity/interactive_survey_input_question';
  214. break;
  215. case LotteryEvents::TYPE_EVENTS_VOTE: //投票
  216. if (!$events_Data['events']['vote_type']) { //创建投票类型
  217. $this->tpl = 'admin/activity/interactive_vote_type';
  218. } else {
  219. $this->tpl = 'admin/activity/interactive_vote';
  220. if (Request::g('add_one_vote')) { //添加投票项
  221. $this->tpl = 'admin/activity/interactive_add_one_vote';
  222. }
  223. if (Request::g('update_one_vote')) { //修改投票项
  224. $this->tpl = 'admin/activity/interactive_update_one_vote';
  225. }
  226. }
  227. break;
  228. case LotteryEvents::TYPE_EVENTS_INVITATION: //邀请函
  229. $this->tpl = 'admin/activity/interactive_input';
  230. break;
  231. case LotteryEvents::TYPE_EVENTS_CODE: //领券
  232. $this->tpl = 'admin/activity/interactive_code';
  233. break;
  234. case LotteryEvents::TYPE_EVENTS_CUT_SCREEN: //切屏专题
  235. $this->tpl = 'admin/activity/interactive_input';
  236. break;
  237. }
  238. $navConfig = $this->getUpPageNav($events_id, 'Interactive');
  239. $title = '互动设置';
  240. $this->setOutput('title', $title);
  241. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  242. $this->addNavMenu('活动列表');
  243. $this->addNavMenu($title);
  244. $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置
  245. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  246. }
  247. /**
  248. * 删除一个调查问卷的奖品
  249. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqDelSurveyQuestion
  250. */
  251. public function doReqDelSurveyQuestion(){
  252. $events_id = Request::p('events_id');
  253. $survery_question_id = Request::p('survery_question_id');
  254. $eventsData = $this->objLottery->getOneLotteryEvents($events_id);
  255. foreach($eventsData['survery_question'] as $key=>$data){
  256. if($key == $survery_question_id){
  257. unset($eventsData['survery_question'][$key]);
  258. }
  259. }
  260. $info['survery_question'] = $eventsData['survery_question'];
  261. $this->objLottery->upLotteryEvents ( $info, array (
  262. 'id' => $events_id
  263. ) );
  264. $this->ajax_success_exit('删除成功');
  265. }
  266. /**
  267. * 添加一个调查问卷的问题
  268. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqAddSurveyQuestion
  269. */
  270. public function doReqAddSurveyQuestion(){
  271. $data = $_POST;
  272. $events_id = $data['events_id'];
  273. $sort = $data['f_sort_h'];
  274. $type = $data['f_type_h'];
  275. $choice = $data['f_choice_h'];
  276. $eventsData = $this->objLottery->getOneLotteryEvents($events_id);
  277. if(empty($eventsData['survery_question'])){
  278. $eventsData['survery_question'] = array();
  279. }
  280. if(isset($eventsData['survery_question'][$sort] )){
  281. $this->ajax_fail_exit('当前排序已有数据');
  282. }
  283. $info['survery_question'] = $eventsData['survery_question'];
  284. $info['survery_question'][$sort] = array();
  285. $info['survery_question'][$sort]['question'] = $data['f_question_h'];
  286. $info['survery_question'][$sort]['type'] = $type;
  287. $info['survery_question'][$sort]['choice'] = $choice;
  288. if($type == 'img'){
  289. for($i=1 ; $i<= $data['f_num_h']; $i++){
  290. $info['survery_question'][$sort]['answer'][$i] = array(
  291. 'img_url' => $data['img_url_'.$i],
  292. 'answer' => $data['img_url_answer_'.$i],
  293. );
  294. }
  295. }
  296. if($type == 'txt'){
  297. for($i=1 ; $i<= $data['f_num_h']; $i++){
  298. $info['survery_question'][$sort]['answer'][$i] = array(
  299. 'answer' => $data['txt_'.$i],
  300. );
  301. }
  302. }
  303. $this->objLottery->upLotteryEvents ( $info, array (
  304. 'id' => $events_id
  305. ) );
  306. $this->ajax_success_exit('添加成功');
  307. }
  308. /**
  309. * 添加一个调查问卷的奖品
  310. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqAddSurveyPrize
  311. */
  312. public function doReqAddSurveyPrize(){
  313. $events_id = Request::p('events_id');
  314. $survery_prize_name = Request::p('survery_prize_name');
  315. $survery_prize_img_url = Request::p('img_url');
  316. $survery_prize_num = Request::p('survery_prize_num');
  317. $survery_prize_unit_name = Request::p('survery_prize_unit_name');
  318. $eventsData = $this->objLottery->getOneLotteryEvents($events_id);
  319. if(empty($eventsData['survery_prize'])){
  320. $eventsData['survery_prize'] = array();
  321. }
  322. $info['survery_prize'] = $eventsData['survery_prize'];
  323. $thisData = array(
  324. 'name' => $survery_prize_name,
  325. 'img_url' => $survery_prize_img_url,
  326. 'num' => $survery_prize_num,
  327. 'unit_name' => $survery_prize_unit_name,
  328. );
  329. array_push($info['survery_prize'] , $thisData);
  330. $this->objLottery->upLotteryEvents ( $info, array (
  331. 'id' => $events_id
  332. ) );
  333. $this->ajax_success_exit('添加成功');
  334. }
  335. /**
  336. * 删除一个调查问卷的奖品
  337. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqDelSurveyPrize
  338. */
  339. public function doReqDelSurveyPrize(){
  340. $events_id = Request::p('events_id');
  341. $survery_prize_id = Request::p('survery_prize_id');
  342. $eventsData = $this->objLottery->getOneLotteryEvents($events_id);
  343. foreach($eventsData['survery_prize'] as $key=>$data){
  344. if($key == $survery_prize_id){
  345. unset($eventsData['survery_prize'][$key]);
  346. }
  347. }
  348. $info['survery_prize'] = $eventsData['survery_prize'];
  349. $this->objLottery->upLotteryEvents ( $info, array (
  350. 'id' => $events_id
  351. ) );
  352. $this->ajax_success_exit('删除成功');
  353. }
  354. /**
  355. * 事件:修改表单设置
  356. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqUpForm
  357. * 参数:内方法内
  358. */
  359. public function doReqUpForm() {
  360. $events_id = Request::p ( 'events_id' );
  361. $formRegular = $this->formRegular ();
  362. if (isset ( $_POST ['f'] )) {
  363. $forms = Filter::arrayfilter ( $_POST ['f'] );
  364. foreach ( $forms as $tmpKey => $tmpForm ) {
  365. if (! $tmpForm ['name']) {
  366. unset ( $forms [$tmpKey] );
  367. }
  368. $regularid = $tmpForm ['rule'] ['regularid'];
  369. if (! empty ( $regularid ) && in_array ( $regularid, array_keys ( $formRegular ) )) {
  370. $forms [$tmpKey] ['rule'] ['regular'] = $formRegular [$regularid] ['regular'];
  371. } else {
  372. unset ( $forms [$tmpKey] ['rule'] ['regular'] );
  373. }
  374. if ($tmpForm ['options']) {
  375. $forms [$tmpKey] ['options'] = Filter::arrayfilter ( explode ( "\n", $tmpForm ['options'] ) );
  376. }
  377. }
  378. $info ['forms'] = $forms;
  379. $this->objLottery->upLotteryEvents ( $info, array (
  380. 'id' => $events_id
  381. ) );
  382. }
  383. // TODO 跳转页面自定义 返回 信息自定义
  384. $this->ajax_success_exit();
  385. }
  386. /**
  387. * 事件: 添加奖项
  388. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqAddPrize
  389. * 参数:内方法内
  390. */
  391. public function doReqAddPrize() {
  392. $events_id = Request::p ( 'events_id' );
  393. $prize_name = Request::p ( 'prize_name' );
  394. $begin_hour = Request::p ( 'begin_hour' );
  395. $end_hour = Request::p ( 'end_hour' );
  396. $type = Request::p ( 'prize_type' );
  397. $prize_num = Request::p ( 'prize_num' );
  398. $virtual_data_str = Request::p ( 'virtual_data' );
  399. $white_list_str = Request::p ( 'white_list' );
  400. $hundred_percent_list_str = Request::p ( 'hundred_percent_list' );
  401. $black_list_str = Request::p ( 'black_list' );
  402. $express = Request::p ( 'express' );
  403. $img_url = Request::p('prize_image_url');
  404. $virtual_data = array ();
  405. $tmp_virtual_data = explode ( "\n", $virtual_data_str );
  406. foreach ( $tmp_virtual_data as $data ) {
  407. if (! empty ( $data )) {
  408. $virtual_data [$data] = $data;
  409. }
  410. }
  411. if ($type == LotteryPrize::TYPE_ENTITY) {
  412. $prize_num = count ( $virtual_data );
  413. }
  414. $white_list = array ();
  415. $tmp_white_list = explode ( "\n", $white_list_str );
  416. foreach ( $tmp_white_list as $data ) {
  417. if (! empty ( $data )) {
  418. $white_list [$data] = $data;
  419. }
  420. }
  421. $hundred_percent_list = array ();
  422. $tmp_hundred_percent_list = explode ( "\n", $hundred_percent_list_str );
  423. foreach ( $tmp_hundred_percent_list as $data ) {
  424. if (! empty ( $data )) {
  425. $hundred_percent_list [$data] = $data;
  426. }
  427. }
  428. $black_list = array ();
  429. $tmp_black_list = explode ( "\n", $black_list_str );
  430. foreach ( $tmp_black_list as $data ) {
  431. if (! empty ( $data )) {
  432. $black_list [$data] = $data;
  433. }
  434. }
  435. $info = array (
  436. 'events_id' => $events_id,
  437. 'prize_name' => $prize_name,
  438. 'prize_num' => $prize_num,
  439. 'type' => $type,
  440. 'white_list' => $white_list,
  441. 'hundred_percent_list' => $hundred_percent_list,
  442. 'black_list' => $black_list,
  443. 'begin_hour' => $begin_hour,
  444. 'end_hour' => $end_hour,
  445. 'img_url' => $img_url,
  446. 'virtual_data' => $virtual_data,
  447. 'express' => $express
  448. );
  449. $prize_id = $this->objLottery->addLotteryPrize ( $info );
  450. // TODO 跳转页面自定义 返回 信息自定义
  451. $this->ajax_success_exit($prize_id);
  452. }
  453. /**
  454. * 页面:获奖数据列表页
  455. * 地址: http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=PageLotteryDataList
  456. */
  457. public function doPageLotteryDataList() {
  458. $events_id = Request::g ( 'events_id' );
  459. $scratch_receive = Request::g ( 'scratch_receive' );
  460. $eventsAndPrizeData = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  461. if ($eventsAndPrizeData ['events'] ['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH) {
  462. }
  463. // 取数据
  464. $page = Request::varGetInt ( 'page', 1 );
  465. $size = 20;
  466. $offset = ($page - 1) * $size;
  467. $limit = "{$offset},{$size}";
  468. $condition = array (
  469. 'events_id' => $events_id
  470. );
  471. // 刮刮卡 跳将特殊处理
  472. $pieze_notreceive_num = array ();
  473. if ($eventsAndPrizeData ['events'] ['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH) {
  474. $condition ['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_TRUE;
  475. foreach ( $eventsAndPrizeData ['prize'] as $prize ) {
  476. $for_condition = array (
  477. 'events_id' => $events_id,
  478. 'prize_id' => $prize ['id'],
  479. 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_FALSE
  480. );
  481. $pieze_notreceive_num [$prize ['id']] = $this->objLottery->getLotteryDataListNum ( $for_condition );
  482. }
  483. }
  484. // 筛选条件
  485. $prize_id = Request::g ( 'prize_id' );
  486. if ($prize_id) {
  487. $condition ['prize_id'] = $prize_id;
  488. }
  489. if ($scratch_receive == 'false') {
  490. $condition ['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_FALSE;
  491. }
  492. $total_num = $this->objLottery->getLotteryDataListNum ( $condition );
  493. $url_tpl = Request::schemeDomain () . "?c=admin_Lottery&a=LotteryDataListPage&events_id={$events_id}";
  494. if ($prize_id) {
  495. $url_tpl .= "&prize_id={$prize_id}";
  496. }
  497. $url_tpl .= "&page={page}";
  498. // 分页
  499. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  500. $page_html = $objPage->html ();
  501. $order = 'id desc';
  502. $lotteryData = $this->objLottery->getLotteryDataList ( $condition, $limit, $order );
  503. $objDLotteryPrize = new LotteryPrize ();
  504. $prizeType = $objDLotteryPrize->getType ();
  505. $prizeDisplayStatus = $objDLotteryPrize->getDisplay ();
  506. $this->setOutput ( 'page_html', $page_html );
  507. $this->setOutput ( 'eventsAndPrizeData', $eventsAndPrizeData );
  508. $this->setOutput ( 'pieze_notreceive_num', $pieze_notreceive_num );
  509. $this->setOutput ( 'prizeType', $prizeType );
  510. $this->setOutput ( 'lotteryData', $lotteryData );
  511. }
  512. /**
  513. * 事件: 修改奖项
  514. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqUpPrize
  515. * 参数:见方法内
  516. */
  517. public function doReqUpPrize() {
  518. $prize_id = Request::p ( 'prize_id' );
  519. $events_id = Request::p ( 'events_id' );
  520. $prize_name = Request::p ( 'prize_name' );
  521. $begin_hour = Request::p ( 'begin_hour' );
  522. $end_hour = Request::p ( 'end_hour' );
  523. $white_list_str = Request::p ( 'white_list' );
  524. $hundred_percent_list_str = Request::p ( 'hundred_percent_list' );
  525. $black_list_str = Request::p ( 'black_list' );
  526. $display = Request::p ( 'display' );
  527. $express = Request::p ( 'express' );
  528. $img_url = Request::p ( 'prize_image_url' );
  529. $white_list = array ();
  530. $tmp_white_list = explode ( "\n", $white_list_str );
  531. foreach ( $tmp_white_list as $data ) {
  532. if (! empty ( $data )) {
  533. $white_list [$data] = $data;
  534. }
  535. }
  536. $hundred_percent_list = array ();
  537. $tmp_hundred_percent_list = explode ( "\n", $hundred_percent_list_str );
  538. foreach ( $tmp_hundred_percent_list as $data ) {
  539. if (! empty ( $data )) {
  540. $hundred_percent_list [$data] = $data;
  541. }
  542. }
  543. $black_list = array ();
  544. $tmp_black_list = explode ( "\n", $black_list_str );
  545. foreach ( $tmp_black_list as $data ) {
  546. if (! empty ( $data )) {
  547. $black_list [$data] = $data;
  548. }
  549. }
  550. $info = array (
  551. 'events_id' => $events_id,
  552. 'prize_name' => $prize_name,
  553. 'white_list' => $white_list,
  554. 'hundred_percent_list' => $hundred_percent_list,
  555. 'black_list' => $black_list,
  556. 'begin_hour' => $begin_hour,
  557. 'end_hour' => $end_hour,
  558. 'img_url' => $img_url,
  559. 'display' => $display,
  560. 'express' => $express
  561. );
  562. $this->objLottery->UpLotteryPrize ( $info, array (
  563. 'id' => $prize_id
  564. ) );
  565. // TODO 跳转页面自定义 返回 信息自定义
  566. $redirect_url = Request::schemeDomain() . '/?c=Admin_Activity_SetInteractive&a=PageShow&events_id='.$events_id;
  567. $this->ajax_success_exit($redirect_url);
  568. }
  569. /**
  570. * 事件:增加奖项数量[虚拟,实物]
  571. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqAddPrizeNum
  572. */
  573. public function doReqAddPrizeNum() {
  574. $virtual_data_str = Request::p ( 'virtual_data' );
  575. $prize_id = Request::p ( 'prize_id' );
  576. $num = Request::p ( 'prize_num' );
  577. $events_id = Request::p ( 'events_id' );
  578. $virtual_data = array ();
  579. $tmp_virtual_data = explode ( "\n", $virtual_data_str );
  580. foreach ( $tmp_virtual_data as $data ) {
  581. if (! empty ( $data )) {
  582. $virtual_data [$data] = $data;
  583. }
  584. }
  585. $this->objLottery->addLotteryPrizeNum ( $prize_id, $num, $virtual_data );
  586. // TODO 跳转页面自定义 返回 信息自定义
  587. if (Request::g('noajax')) {
  588. $this->redirect(Request::referer());
  589. } else {
  590. $this->ajax_success_exit();
  591. }
  592. }
  593. /**
  594. * 事件: 减少奖项数量[实物]
  595. * 地址: http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqMinusPrizeNum
  596. */
  597. public function doReqMinusPrizeNum() {
  598. $prize_id = Request::p ( 'prize_id' );
  599. $num = Request::p ( 'num' );
  600. $this->objLottery->addLotteryPrizeNum ( $prize_id, - $num );
  601. // TODO 跳转页面自定义 返回 信息自定义
  602. $this->ajax_success_exit();
  603. }
  604. /**
  605. * 事件:初始化 投票属性 图片类|| 文字类
  606. * 地址: http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqInitVote
  607. * 参数:见方法
  608. */
  609. public function doReqInitVote(){
  610. $events_id = Request::p ( 'events_id' );
  611. $vote_num = Request::p ( 'vote_num' );
  612. $vote_type = Request::p ( 'vote_type' );
  613. $vote_title = Request::p ( 'vote_title' );
  614. $objDLotteryEvents = new LotteryEvents ();
  615. $info = array (
  616. 'vote_type' => $vote_type,
  617. 'vote_title' => $vote_title
  618. );
  619. $objDLotteryEvents->modify ( $info, array (
  620. 'id' => $events_id
  621. ) );
  622. $objDLotteryEventsVote = new LotteryEventsVote ();
  623. for($i = 1; $i <= $vote_num; $i ++) {
  624. $info = array (
  625. 'events_id' => $events_id,
  626. 'title' => 'null',
  627. 'img_url' => 'null'
  628. );
  629. $objDLotteryEventsVote->add ( $info );
  630. }
  631. // TODO 跳转页面自定义 返回 信息自定义
  632. $this->ajax_success_exit();
  633. }
  634. /**
  635. * 事件:创建一个投票项
  636. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqCreateOneVote
  637. */
  638. public function doReqCreateOneVote(){
  639. $title = Request::p ( 'title' );
  640. $events_id = Request::p ( 'events_id' );
  641. $img_url = Request::p('img_url');
  642. // $tmpImgData = $this->loadImg ();
  643. // if (is_array ( $tmpImgData )) {
  644. // $img_url = $tmpImgData ['url'] [0];
  645. // }
  646. $add_num = Request::p ( 'add_num' );
  647. $info = array (
  648. 'title' => $title,
  649. 'img_url' => $img_url,
  650. 'add_num' => $add_num,
  651. 'events_id' => $events_id
  652. );
  653. $objDLotteryEventsVote = new LotteryEventsVote ();
  654. $id = $objDLotteryEventsVote->add ( $info );
  655. if (!$id) {
  656. $this->ajax_fail_exit('创建投票项失败');
  657. }
  658. $redirect_url = Request::schemeDomain() . '/?c=Admin_Activity_SetInteractive&a=PageShow&events_id='.$events_id;
  659. $this->ajax_success_exit($redirect_url);
  660. }
  661. /**
  662. * 事件:修改一个投票项
  663. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=UpOneVote
  664. */
  665. public function doUpOneVote(){
  666. $vote_id = Request::p ( 'vote_id' );
  667. $add_num = Request::p ( 'add_num' );
  668. $title = Request::p ( 'title' );
  669. $img_url = Request::p ( 'img_url' );
  670. $events_id = Request::p ( 'events_id' );
  671. $objDLotteryEventsVote = new LotteryEventsVote ();
  672. // $tmpImgData = $this->loadImg ();
  673. // if (is_array ( $tmpImgData )) {
  674. // $img_url = $tmpImgData ['url'] [0];
  675. // }
  676. $info = array (
  677. 'add_num' => $add_num,
  678. 'title' => $title,
  679. 'img_url' => $img_url
  680. );
  681. $tmpResult = $objDLotteryEventsVote->modify ( $info, array (
  682. 'id' => $vote_id
  683. ) );
  684. if (!$tmpResult->isSuccess()) {
  685. $this->ajax_fail_exit('修改投票项失败');
  686. }
  687. $redirect_url = Request::schemeDomain() . '/?c=Admin_Activity_SetInteractive&a=PageShow&events_id='.$events_id;
  688. $this->ajax_success_exit($redirect_url);
  689. }
  690. /**
  691. * 事件:修改 券名称||券图片
  692. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqUpCode
  693. */
  694. public function doReqUpCode(){
  695. $info =array();
  696. $events_id = Request::p ( 'events_id' );
  697. # 券信息
  698. $info ['two_dimensional_code'] = LotteryEvents::TWO_DIMENSIONAL_CODE_FALSE;
  699. $info ['code_name'] = Request::p ( 'code_name' );
  700. $info ['code_img_url'] = Request::p ( 'code_img_url' );
  701. # 添加自定义表单
  702. $formRegular = $this->formRegular ();
  703. if (isset ( $_POST ['f'] )) {
  704. $forms = Filter::arrayfilter ( $_POST ['f'] );
  705. foreach ( $forms as $tmpKey => $tmpForm ) {
  706. if (! $tmpForm ['name']) {
  707. unset ( $forms [$tmpKey] );
  708. }
  709. $regularid = $tmpForm ['rule'] ['regularid'];
  710. if (! empty ( $regularid ) && in_array ( $regularid, array_keys ( $formRegular ) )) {
  711. $forms [$tmpKey] ['rule'] ['regular'] = $formRegular [$regularid] ['regular'];
  712. } else {
  713. unset ( $forms [$tmpKey] ['rule'] ['regular'] );
  714. }
  715. if ($tmpForm ['options']) {
  716. $forms [$tmpKey] ['options'] = Filter::arrayfilter ( explode ( "\n", $tmpForm ['options'] ) );
  717. }
  718. }
  719. $info ['forms'] = $forms;
  720. }
  721. $tmpReuslt = $this->objLottery->upLotteryEvents ( $info, array (
  722. 'id' => $events_id
  723. ) );
  724. if (!$tmpReuslt) {
  725. $this->ajax_fail_exit('服务器操作失败');
  726. }
  727. # 添加券
  728. $code_data = Request::p ( 'code_data' );
  729. $code_data = explode ( "\n", $code_data );
  730. $code_data = Filter::arrayfilter($code_data);
  731. if (count ( $code_data ) > 200) {
  732. $this->ajax_fail_exit ( '一次上传不允许超过200张券' );
  733. }
  734. $objDLotteryEventsCodeData = new LotteryEventsCodeData ();
  735. foreach ( $code_data as $key => $data ) {
  736. $info = array (
  737. 'events_id' => $events_id,
  738. 'data' => $data
  739. );
  740. $objDLotteryEventsCodeData->add ( $info );
  741. }
  742. $this->ajax_success_exit();
  743. }
  744. /**
  745. * 事件:添加券
  746. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqAddEventCode
  747. */
  748. public function doReqAddEventCode() {
  749. $events_id = Request::p ( 'events_id' );
  750. $code_data = Request::p ( 'code_data' );
  751. $code_data = explode ( "\n", $code_data );
  752. foreach ( $code_data as $key => $data ) {
  753. if ($data) {
  754. $code_data [$data] = $data;
  755. }
  756. }
  757. if (count ( $code_data ) > 200) {
  758. $this->ajax_fail_exit ( '一次上传不允许超过200条记录' );
  759. }
  760. $objDLotteryEventsCodeData = new LotteryEventsCodeData ();
  761. foreach ( $code_data as $key => $data ) {
  762. $info = array (
  763. 'events_id' => $events_id,
  764. 'data' => $data
  765. );
  766. $objDLotteryEventsCodeData->add ( $info );
  767. }
  768. // TODO 跳转页面自定义 返回 信息自定义
  769. return;
  770. }
  771. /**
  772. * 查看券码页面
  773. */
  774. public function doReqShowEventCode() {
  775. $events_id = Request::g('events_id');
  776. $page = Request::varGetInt('page', 1);
  777. $size = 20;
  778. $offset = ($page - 1) * $size;
  779. $limit = "{$offset},{$size}";
  780. $condition = array (
  781. 'events_id' => $events_id
  782. );
  783. $objDLotteryEventsCodeData = new LotteryEventsCodeData ();
  784. $codeIds = $objDLotteryEventsCodeData->findIdsBy ( $condition, $limit, 'id desc' );
  785. $codeData = $objDLotteryEventsCodeData->gets ( $codeIds );
  786. $total_num = $objDLotteryEventsCodeData->totals ( $condition );
  787. # 分页
  788. $url_tpl = Request::schemeDomain () . "/?c=Admin_Activity_SetInteractive&a=ReqShowEventCode&events_id={$events_id}";
  789. $url_tpl .= "&page={page}";
  790. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  791. $page_html = $objPage->html ();
  792. $events_id = Request::g ( 'events_id' );
  793. $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  794. $eventsTypeData = LotteryEvents::getType ();
  795. $navConfig = $this->getUpPageNav($events_id, 'Interactive');
  796. $this->tpl = 'admin/activity/interactive_code_show';
  797. $title = '互动设置';
  798. $this->setOutput('title', $title);
  799. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  800. $this->addNavMenu('活动列表');
  801. $this->addNavMenu($title);
  802. $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置
  803. $this->setOutput('title', $title);
  804. $this->setOutput('events_Data', $events_Data);
  805. $this->setOutput('eventData', $events_Data['events']);
  806. $this->setOutput ( 'eventsTypeData', $eventsTypeData );
  807. $this->setOutput('typeData', $eventsTypeData);
  808. $this->setOutput('codeData', $codeData);
  809. $this->setOutput('page', $page-1);
  810. $this->setOutput('size', $size);
  811. $this->setOutput('page_html', $page_html);
  812. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  813. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  814. }
  815. /**
  816. * 页面:虚拟数据列表页
  817. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=PageVirtualDataList&prize_id=
  818. * 参数:
  819. * 奖项id: prize_id
  820. * 使用 & 未使用 ottery_data_id true| false
  821. * 分页:page
  822. */
  823. public function doPageVirtualDataList() {
  824. $prize_id = Request::g ( 'prize_id' );
  825. $lottery_data_id = Request::g ( 'lottery_data_id' );
  826. $prizeData = $this->objLottery -> getOneLotteryPrize($prize_id);
  827. $events_id = $prizeData['events_id'];
  828. // 取数据
  829. $page = Request::varGetInt ( 'page', 1 );
  830. $size = 20;
  831. $offset = ($page - 1) * $size;
  832. $limit = "{$offset},{$size}";
  833. $condition = array (
  834. 'prize_id' => $prize_id
  835. );
  836. if($lottery_data_id=='true'){
  837. $condition['lottery_data_id'] = SqlHelper::addCompareOperator('!=', 0);
  838. }
  839. if($lottery_data_id=='false'){
  840. $condition['lottery_data_id'] = 0;
  841. }
  842. $order = 'id desc';
  843. $prizeVirtualData = $this->objLottery-> getLotteryPrizeVirtualDataList ( $condition, $limit, $order );
  844. $page_html = '';
  845. $total_num = $this->objLottery->getLotteryPrizeVirtualDataListNum($condition);
  846. $url_tpl = Request::schemeDomain () . "?c=Admin_Activity_SetInteractive&a=PageVirtualDataList&prize_id={$prize_id}";
  847. if($lottery_data_id){
  848. $url_tpl .= "&lottery_data_id={$lottery_data_id}";
  849. }
  850. $url_tpl .= "&page={page}";
  851. // 分页
  852. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  853. $page_html = $objPage->html ();
  854. //通过data_id 获取用户中奖信息
  855. $dataIds = array();
  856. foreach($prizeVirtualData as $key => $data){
  857. if($data['lottery_data_id']){
  858. $dataIds[$data['lottery_data_id']] = $data['lottery_data_id'];
  859. }
  860. }
  861. $lotteryData = $this->objLottery->getLotteryDatas($dataIds);
  862. $navConfig = $this->getUpPageNav($events_id, 'Interactive');
  863. $title = '虚拟数据列表';
  864. $this->setOutput('title', $title);
  865. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  866. $this->addNavMenu('互动设置');
  867. $this->addNavMenu($title);
  868. $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置
  869. $this->setOutput ( 'prizeVirtualData', $prizeVirtualData );
  870. $this->setOutput ( 'page_html', $page_html );
  871. $this->setOutput ( 'prizeData', $prizeData );
  872. $this->setOutput ( 'lotteryData', $lotteryData );
  873. $this->tpl = 'admin/activity/virtual_goods_list';
  874. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  875. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  876. }
  877. /**
  878. * 事件:删除一个虚拟奖品
  879. * 地址 : http://cas.lishuy.com/?c=Admin_Activity_SetInteractive&a=ReqDelPrizeVirtual
  880. * 参数:
  881. * prize_id 奖项ID
  882. * prize_virtua_id 当前虚拟奖品ID
  883. */
  884. public function doReqDelPrizeVirtual(){
  885. $prize_id = Request::p ( 'prize_id' );
  886. $prize_virtua_id = Request::p ( 'prize_virtua_id' );
  887. $prizeData = $this->objLottery -> delLotteryPrizeVirtual($prize_virtua_id);
  888. $this->ajax_success_exit('删除成功');
  889. }
  890. /**
  891. * 方法:图片上传
  892. */
  893. public function loadImg($image_name = 'image') {
  894. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  895. // 定义允许上传的文件扩展名
  896. $ext_arr = array (
  897. 'image' => array (
  898. 'gif',
  899. 'jpg',
  900. 'jpeg',
  901. 'png',
  902. 'bmp'
  903. )
  904. );
  905. if (! is_array ( $_FILES [$image_name] ['name'] )) {
  906. foreach ( $_FILES [$image_name] as $key => $data ) {
  907. unset ( $_FILES [$image_name] [$key] );
  908. $_FILES [$image_name] [$key] [] = $data;
  909. }
  910. }
  911. $file_url = array ();
  912. foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
  913. // 文件保存目录路径
  914. $save_path = $uploadConfig ['path'] . '/';
  915. $save_path = realpath ( $save_path ) . '/';
  916. // PHP上传失败
  917. if ($_FILES [$image_name] ['error'] [$key] != 0) {
  918. switch ($_FILES [$image_name] ['error'] [$key]) {
  919. case '1' :
  920. $error = '超过php.ini允许的大小。';
  921. break;
  922. case '2' :
  923. $error = '超过表单允许的大小。';
  924. break;
  925. case '3' :
  926. $error = '图片只有部分被上传。';
  927. break;
  928. case '4' :
  929. $error = '请选择图片。';
  930. break;
  931. case '6' :
  932. $error = '找不到临时目录。';
  933. break;
  934. case '7' :
  935. $error = '写文件到硬盘出错。';
  936. break;
  937. case '8' :
  938. $error = 'File upload stopped by extension。';
  939. break;
  940. case '999' :
  941. default :
  942. $error = '未知错误。';
  943. }
  944. return $error;
  945. }
  946. // 有上传文件时
  947. if (empty ( $_FILES ) === false) {
  948. // 原文件名
  949. $file_name = $_FILES [$image_name] ['name'] [$key];
  950. // 服务器上临时文件名
  951. $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
  952. // 文件大小
  953. $file_size = $_FILES [$image_name] ['size'] [$key];
  954. // 检查文件名
  955. if (! $file_name) {
  956. return "请选择文件。";
  957. }
  958. // 检查目录
  959. if (@is_dir ( $save_path ) === false) {
  960. return "上传目录不存在。";
  961. }
  962. // 检查目录写权限
  963. if (@is_writable ( $save_path ) === false) {
  964. return "上传目录没有写权限。";
  965. }
  966. // 检查是否已上传
  967. if (@is_uploaded_file ( $tmp_name ) === false) {
  968. return "上传失败。";
  969. }
  970. // 检查目录名
  971. $dir_name = 'image';
  972. if (empty ( $ext_arr [$dir_name] )) {
  973. return "目录名不正确。";
  974. }
  975. // 获得文件扩展名
  976. $temp_arr = explode ( ".", $file_name );
  977. $file_ext = array_pop ( $temp_arr );
  978. $file_ext = trim ( $file_ext );
  979. $file_ext = strtolower ( $file_ext );
  980. // 检查扩展名
  981. if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
  982. return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
  983. }
  984. // 创建文件夹
  985. $ymd = date ( "Ymd" );
  986. $ymd = date ( "Y" ) . '/' . date ( 'md' );
  987. // 文件保存目录URL
  988. $save_url = $uploadConfig ['url'] . '/';
  989. $new_file_name = '';
  990. $save_path .= $dir_name . "/" . $ymd . "/";
  991. $save_url .= $dir_name . "/" . $ymd . "/";
  992. if (! file_exists ( $save_path )) {
  993. if (! mkdir ( $save_path, 0775, true )) {
  994. return "创建目录失败:{$save_path}";
  995. }
  996. }
  997. // 新文件名
  998. $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
  999. // 移动文件
  1000. $file_path = $save_path . $new_file_name;
  1001. // 原图上传
  1002. if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
  1003. return "上传文件失败。";
  1004. }
  1005. error_reporting ( E_ALL );
  1006. // 压缩65质量原图
  1007. $this_basename = basename ( $file_path );
  1008. $this_dirname = dirname ( $file_path );
  1009. $z_file_path = $this_dirname . '/' . 'z.' . $this_basename;
  1010. \KIF\Image::transformFormat ( $file_path, $z_file_path, 'JPG' );
  1011. @chmod ( $file_path, 0777 );
  1012. $file_url [$key] = $save_url . 'z.' . $new_file_name;
  1013. }
  1014. }
  1015. return array (
  1016. 'error' => 0,
  1017. 'url' => $file_url
  1018. );
  1019. }
  1020. /**
  1021. * 表单验证规则
  1022. *
  1023. * @return multitype:multitype:string
  1024. */
  1025. public function formRegular() {
  1026. return array (
  1027. 1 => array (
  1028. 'desc' => '手机验证',
  1029. 'regular' => '/^(1[0-9][0-9]|15[0-9]|18[02-9]|14[57])[0-9]{8}$/'
  1030. ),
  1031. 2 => array (
  1032. 'desc' => '邮箱验证',
  1033. 'regular' => '/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/'
  1034. )
  1035. );
  1036. }
  1037. public function display() {
  1038. return $this->render ();
  1039. }
  1040. }