ProductsetController.php 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918
  1. <?php
  2. /**
  3. * 产品设置.
  4. * User: chenye
  5. * Date: 2017/11/22
  6. * Time: 11:05
  7. */
  8. class ProductsetController extends Product {
  9. public $layout = false;
  10. /**
  11. * 首页
  12. */
  13. public function actionIndex(){
  14. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  15. //////新跳转规则////////
  16. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  17. // Header("Location: " . Yii::app()->params['product_set'] . '#/ProductSet/VersionSelect?subjectId=3');
  18. Header("Location: ".Yii::app()->params['product_setting_url']."index.html#/ProductSet/VersionSelect?subjectId=3");
  19. exit;
  20. }else if($subjectId == 12){
  21. Header("Location: ".Yii::app()->params['product_setting_url']."index.html#/ProductSet/Customized?subjectId=12");
  22. // Header("Location: " . Yii::app()->params['product_set'] . '#/ProductSet/Customized?subjectId=12');
  23. exit;
  24. }else{
  25. $this->redirect(array('oldSet'));exit;
  26. }
  27. ///////////////
  28. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  29. //读取版本选择
  30. $data=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow();
  31. if(!$data){
  32. $data['switch']=2;
  33. }
  34. $this->render('versionOptions',$data);
  35. }else{
  36. $this->redirect(array('oldSet'));
  37. }
  38. }
  39. //2.0产品设置
  40. public function actionOldSet(){
  41. // phpinfo();exit;
  42. $data = array();
  43. $classList = array();
  44. $productList = array();
  45. $classRelationIds = array();
  46. $classRList = array();
  47. //获取设置详情,没有则获取第一个默认设置
  48. if(isset($_GET['psId'])){
  49. $psId = Req::get('psId');
  50. }else{
  51. $psId = 0;
  52. }
  53. if(isset($_GET['subjectId'])){
  54. Yii::app()->session['session_duoxueke_subject_id'] = $_GET['subjectId'];
  55. Yii::app()->session['session_subject_id'] = $_GET['subjectId'];
  56. }
  57. $subjectId=Yii::app()->session['session_duoxueke_subject_id']?Yii::app()->session['session_duoxueke_subject_id']:3;
  58. //当前学期
  59. $currSemester = $this->schoolManager->getCurrSemester();
  60. $currClass = $this->schoolManager->getSemesterClasses($currSemester['semester_id']);
  61. //获取指定产品设置
  62. $setInfoObj = SProductSetting::model()->getSetInfo($psId,$subjectId);
  63. if($setInfoObj){
  64. $setInfo = $setInfoObj->getAttributes();
  65. $subjectId=$setInfo['subject_id'];
  66. //获取产品列表
  67. $productListR = SProductSetting::model()->getProductList($subjectId);
  68. }else{
  69. if($subjectId==8){
  70. SProductSetting::model()->initProductSetting($subjectId,true,$this->schoolInfo['province_id']);
  71. }else{
  72. SProductSetting::model()->initProductSetting($subjectId);
  73. }
  74. $productListR = SProductSetting::model()->getProductList($subjectId);
  75. $setInfoObj = SProductSetting::model()->getSetInfo($psId,$subjectId);
  76. $setInfo = $setInfoObj->getAttributes();
  77. }
  78. foreach ($productListR as $k=>$v){
  79. $productList[$v['product_type']][] = $v;
  80. }
  81. //11 江苏 12浙江
  82. //读取自定义模块
  83. if($subjectId==8 ){
  84. //没有自定义模板,新增
  85. if(!isset($productList[6])){
  86. SProductSetting::model()->initProductSetting($subjectId,true,$this->schoolInfo['province_id']);
  87. }elseif(!isset($productList[7])){
  88. SProductSetting::model()->initEnglishCdch();
  89. }elseif(!isset($productList[8])){
  90. SProductSetting::model()->initEnglishMagicWord();
  91. }elseif(!isset($productList[9])){
  92. SProductSetting::model()->initEnglishWriting();
  93. }
  94. $productListR = SProductSetting::model()->getProductList($subjectId);
  95. $productList=array();
  96. foreach ($productListR as $k=>$v){
  97. $productList[$v['product_type']][] = $v;
  98. }
  99. }
  100. //获取当前学期班级产品关联
  101. $classRelation = SProductClassRelation::model()->getClassRelation($setInfo['ps_id'],$currSemester['semester_id']);
  102. if(!empty($classRelation)){
  103. foreach ($classRelation as $k=>$v){
  104. $classRelationIds[] = $v['class_id'];
  105. $classRList[$v['grade']][] = $v;
  106. }
  107. }
  108. //获取班级(屏蔽已经关联的班级)
  109. foreach ($currClass as $k=>$v){
  110. if(!in_array($v['class_id'],$classRelationIds,true)){
  111. $classList[$v['grade']][] = $v;
  112. }
  113. }
  114. //debug($productList);exit;
  115. $customConfig=array();
  116. if($subjectId==8){
  117. foreach ($productList as $val){
  118. foreach ($val as $value){
  119. if($value['custom_config']){
  120. $config=json_decode($value['custom_config'],true);
  121. if($config){
  122. $config['name']=$value['name'];
  123. $config['is_default']=$value['is_default'];
  124. $config['ps_id']=$value['ps_id'];
  125. $config['product_type']=$value['product_type'];
  126. $customConfig[$config['moduleType']][]=$config;
  127. }
  128. }
  129. }
  130. }
  131. }
  132. $data = array(
  133. 'class_list' => $classList,
  134. 'product_list' => $productList,
  135. 'set_info' =>$setInfo,
  136. 'classR_list' => $classRList,
  137. 'curr_ps' => $setInfo['ps_id'],
  138. 'subject_id'=>$subjectId,
  139. 'customConfig'=>$customConfig,
  140. 'province_id'=>$this->schoolInfo['province_id'],
  141. 'is_whole' => $this->isWholeMagic(), //词汇宝是否是完整版
  142. );
  143. //获取全学科
  144. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  145. $data['subjects']=Yii::app()->params['subjectId'];
  146. unset($data['subjects'][6]);
  147. unset($data['subjects'][51]);
  148. if(isset($data['subjects'][20])) unset($data['subjects'][20]);
  149. }
  150. $data['subject_name']=$data['subjects'][$subjectId];
  151. //debug($data);
  152. if($subjectId==8 && $setInfo['product_type']>3){
  153. $data['custom']=json_decode($setInfo['custom_config'],true);
  154. //debug($data['custom']);
  155. $this->render('english',$data);
  156. }else{
  157. $this->render('index',$data);
  158. }
  159. }
  160. /**
  161. * 添加班级
  162. * 删除其他类型的关联关系
  163. */
  164. public function actionAddClass(){
  165. //当前学期
  166. $currSemester = $this->schoolManager->getCurrSemester();
  167. $psId = Req::post('ps_id2');
  168. $classId = Req::post('class_id'); //array()
  169. $setType = Req::post('setType');
  170. $subjectId = Req::post('subject_id');
  171. if($subjectId==3){
  172. $productListR = SProductSetting::model()->getProductList($subjectId);
  173. $psIds=array();
  174. foreach ($productListR as $item){
  175. if($item['ps_id']!=$psId) $psIds[]=$item['ps_id'];
  176. }
  177. $repeat=SProductClassRelation::model()->getPsClass($psIds,$classId);
  178. if($repeat){
  179. $data['status'] = 0;
  180. $data['info'] = "添加失败,该学科已有相同班级";
  181. exit(json_encode($data));
  182. }
  183. }elseif($subjectId==8){
  184. $psIds=array();
  185. $productListR=$this->sConn->createCommand("select ps_id from product_setting where subject_id='{$subjectId}' and product_type='{$setType}'")->queryAll();
  186. foreach ($productListR as $item){
  187. if($item['ps_id']!=$psId) $psIds[]=$item['ps_id'];
  188. }
  189. if($psIds){
  190. $repeat=$this->sConn->createCommand("select ps_id from product_class_relation where class_id in(".implode(',',$classId).") and ps_id in(".implode(',',$psIds).") ")->queryRow();
  191. if($repeat){
  192. $data['status'] = 0;
  193. $data['info'] = "添加失败,该学科产品类别已有相同班级";
  194. exit(json_encode($data));
  195. }
  196. }
  197. }
  198. $bool = SProductClassRelation::model()->insertClassRelation($psId,$classId,$currSemester['semester_id'],$setType);
  199. if($bool){
  200. $data['status'] = 1;
  201. $data['info'] = "添加成功";
  202. }else{
  203. $data['status'] = 0;
  204. $data['info'] = "添加失败";
  205. }
  206. //操作记录
  207. if(Yii::app()->params['handle_log_on_off']){
  208. writeFileLog(jsonEncode(array(
  209. 'product_id' => $psId,
  210. 'account' => Yii::app()->session['coachInfo']['coach_name'],
  211. 'operate_url' => 'productset/addClass',
  212. 'operate_param' => json_encode(array('post'=>$_POST)),
  213. 'school_id' => $this->schoolId,
  214. 'operate_time' => time(),
  215. 'title' => '添加关联的班级',
  216. 'status' => json_encode($data),
  217. "date"=>date('Y-m-d H:i:s')
  218. )));
  219. }
  220. exit(json_encode($data));
  221. }
  222. /**
  223. * 删除班级-产品关联
  224. */
  225. public function actionDelClass(){
  226. $classId = Req::post('classId');
  227. $psId = Req::post('psId');
  228. $currSemester = $this->schoolManager->getCurrSemester();
  229. $bool = SProductClassRelation::model()->deleteAll("ps_id=:ps_id AND class_id=:class_id AND semester_id=:semester_id",array(':ps_id'=>$psId,':class_id'=>$classId,':semester_id'=>$currSemester['semester_id']));
  230. if($bool!==false){
  231. $data['status'] = 1;
  232. $data['info'] = "删除成功";
  233. }else{
  234. $data['status'] = 0;
  235. $data['info'] = "删除失败";
  236. }
  237. //操作记录
  238. if(Yii::app()->params['handle_log_on_off']){
  239. writeFileLog(jsonEncode(array(
  240. 'product_id' => $psId,
  241. 'account' => Yii::app()->session['coachInfo']['coach_name'],
  242. 'operate_url' => 'productset/delClass',
  243. 'operate_param' => json_encode(array('post'=>$_POST)),
  244. 'school_id' => $this->schoolId,
  245. 'operate_time' => time(),
  246. 'title' => '删除关联的班级',
  247. 'status' => json_encode($data),
  248. "date"=>date('Y-m-d H:i:s')
  249. )));
  250. }
  251. exit(json_encode($data));
  252. }
  253. /**
  254. * 编辑产品设置
  255. */
  256. public function actionEdit(){
  257. $editdata = array();
  258. // debug($_POST);
  259. $subjectId=$_POST['subject_id'];
  260. if(isset($_POST['show_map'])){
  261. $editdata['show_map'] = Req::post('show_map');
  262. }
  263. if(isset($_POST['show_kp'])){
  264. $editdata['show_kp'] = Req::post('show_kp');
  265. }
  266. if(isset($_POST['show_guide'])){
  267. $editdata['show_guide'] = Req::post('show_guide');
  268. }
  269. if(isset($_POST['show_wrg_origin'])){
  270. $editdata['show_wrg_origin'] = Req::post('show_wrg_origin');
  271. }
  272. if(isset($_POST['show_wrg_analyze'])){
  273. $editdata['show_wrg_analyze'] = Req::post('show_wrg_analyze');
  274. }
  275. if(isset($_POST['show_classmate_optimization'])){
  276. $editdata['show_classmate_optimization'] = Req::post('show_classmate_optimization');
  277. }
  278. if(isset($_POST['show_isp_wrong_answer'])){
  279. $editdata['show_isp_wrong_answer'] = Req::post('show_isp_wrong_answer');
  280. }
  281. if(isset($_POST['level_rule'])){
  282. $editdata['level_rule'] = Req::post('level_rule');
  283. }
  284. if(isset($_POST['show_level'])){
  285. $editdata['show_level'] = Req::post('show_level');
  286. }
  287. if(isset($editdata['show_level']) && $editdata['show_level'] == 2 && isset($_POST['show_top'])){
  288. $editdata['show_top'] = implode('|',Req::post('show_top'));
  289. }
  290. if(isset($_POST['show_wrg_answer'])){
  291. $editdata['show_wrg_answer'] = Req::post('show_wrg_answer');
  292. }
  293. if(isset($_POST['st_tuozhan'])){
  294. $editdata['st_tuozhan'] = implode('|',Req::post('st_tuozhan'));
  295. }else{
  296. $editdata['st_tuozhan'] = '';
  297. }
  298. if($subjectId==3){
  299. if(isset($_POST['st_wrong'])){
  300. $editdata['st_wrong'] = implode('|',Req::post('st_wrong'));
  301. }else{
  302. $editdata['st_wrong'] = '';
  303. }
  304. }else{
  305. if(isset($_POST['st_wrong']) && $_POST['st_wrong']==1){
  306. $editdata['st_wrong'] = '1|1|1|1|1';
  307. }else{
  308. $editdata['st_wrong'] = '0|0|0|0|0';
  309. }
  310. }
  311. if(isset($_POST['st_reduce'])){
  312. $editdata['st_reduce'] = implode('|',Req::post('st_reduce'));
  313. }else{
  314. $editdata['st_reduce'] = '';
  315. }
  316. if(isset($_POST['push_question_upgrade'])){
  317. $editdata['push_question_upgrade'] = Req::post('push_question_upgrade');
  318. }
  319. if(isset($_POST['old_top_kps']) && isset($editdata['show_top'])){
  320. $old_top_kps = explode('|',Req::post('old_top_kps'));
  321. foreach (array(1,2,3,4) as $key => $level){
  322. $_key = 'top_kps_'.$level;
  323. if(isset($_POST[$_key]) && in_array($_POST[$_key],array(3,4,5))){
  324. $editdata['top_kps'][$key] = (int)Req::post($_key);
  325. }else{
  326. if(isset($old_top_kps[$key - 1])){
  327. $editdata['top_kps'][$key] = $old_top_kps[$key - 1];
  328. }else{
  329. $editdata['top_kps'][$key] = 5;
  330. }
  331. }
  332. }
  333. $editdata['top_kps'] = implode('|',$editdata['top_kps']);
  334. }
  335. if(isset($_POST['custom'])){
  336. if(isset($_POST['product_name']))
  337. $_POST['custom']['setting']['productName'] = Req::post('product_name');
  338. }
  339. $editdata['custom_config']=isset($_POST['custom'])?json_encode($_POST['custom']):'';
  340. $psId = Req::post('ps_id');
  341. if(empty($editdata)){
  342. $data['status'] = 0;
  343. $data['info'] = "无数据更新";
  344. }else{
  345. //个性化学习宝 产品名称不为空且长度不超过15
  346. if(isset($_POST['custom']) && $_POST['custom']['moduleType'] == 'english_3'){
  347. $setting = $_POST['custom'];
  348. if(isset($setting['setting']['productName']) && !$setting['setting']['productName']){
  349. $data['status'] = 0;
  350. $data['info'] = "产品名称不为空";
  351. exit(json_encode($data));
  352. }elseif(isset($setting['setting']['productName']) && $setting['setting']['productName']){
  353. if(mb_strlen($setting['setting']['productName'], 'utf-8') > 15){
  354. $data['status'] = 0;
  355. $data['info'] = "产品名称最多不超过15个字符";
  356. exit(json_encode($data));
  357. }
  358. }
  359. }
  360. $result = SProductSetting::model()->updateByPk($psId,$editdata);
  361. if($result>=0){
  362. $data['status'] = 1;
  363. $data['info'] = "保存成功";
  364. }else{
  365. $data['status'] = 0;
  366. $data['info'] = "保存失败";
  367. }
  368. }
  369. //操作记录
  370. if(Yii::app()->params['handle_log_on_off']){
  371. writeFileLog(jsonEncode(array(
  372. 'product_id' => $psId,
  373. 'account' => Yii::app()->session['coachInfo']['coach_name'],
  374. 'operate_url' => 'productset/edit',
  375. 'operate_param' => json_encode(array('post'=>$_POST)),
  376. 'school_id' => $this->schoolId,
  377. 'operate_time' => time(),
  378. 'title' => '编辑产品设置',
  379. 'status' => json_encode($data),
  380. "date"=>date('Y-m-d H:i:s')
  381. )));
  382. }
  383. exit(json_encode($data));
  384. }
  385. /*
  386. * 新增(和同类型默认配置一样)
  387. */
  388. public function actionAdd(){
  389. $type_id = Req::post('psType');
  390. $name = Req::post('name');
  391. $subjectId=Req::post('subject');
  392. $result = SProductSetting::model()->addNew($type_id,$name,$subjectId);
  393. if($result['status']=='1'){
  394. $data['status'] = 1;
  395. $data['info'] = $result['msg'];
  396. }elseif($result['status']=='2'){
  397. $data['status'] = 2;
  398. $data['info'] = "名称已存在";
  399. }else{
  400. $data['status'] = 0;
  401. $data['info'] = "新增失败";
  402. }
  403. //操作记录
  404. if(Yii::app()->params['handle_log_on_off']){
  405. writeFileLog(jsonEncode(array(
  406. 'product_id' => $result['msg'],
  407. 'title' => '新增产品',
  408. 'operate_url' => 'productset/add',
  409. 'account' => Yii::app()->session['coachInfo']['coach_name'],
  410. 'operate_param' => json_encode(array('post'=>$_POST)),
  411. 'school_id' => $this->schoolId,
  412. 'operate_time' => time(),
  413. 'status' => json_encode($data),
  414. "date"=>date('Y-m-d H:i:s')
  415. )));
  416. }
  417. exit(json_encode($data));
  418. }
  419. /*
  420. * 重命名产品
  421. */
  422. public function actionRename(){
  423. $psType = Req::post('psType');
  424. $name = Req::post('name');
  425. $psTypeArr = explode('_',$psType);
  426. $result = SProductSetting::model()->rename($psType,$name);
  427. if($result=='1'){
  428. $data['status'] = 1;
  429. $data['info'] = "更新成功";
  430. }elseif($result=='2'){
  431. $data['status'] = 2;
  432. $data['info'] = "名称已存在";
  433. }else{
  434. $data['status'] = 0;
  435. $data['info'] = "更新失败";
  436. }
  437. //操作记录
  438. if(Yii::app()->params['handle_log_on_off']){
  439. writeFileLog(jsonEncode(array(
  440. 'product_id' => $psTypeArr[1],
  441. 'title' => '重命名产品',
  442. 'operate_url' => 'productset/rename',
  443. 'account' => Yii::app()->session['coachInfo']['coach_name'],
  444. 'operate_param' => json_encode(array('post'=>$_POST)),
  445. 'school_id' => $this->schoolId,
  446. 'operate_time' => time(),
  447. 'status' => json_encode($data),
  448. "date"=>date('Y-m-d H:i:s')
  449. )));
  450. }
  451. exit(json_encode($data));
  452. }
  453. /*
  454. * 删除产品
  455. */
  456. public function actionDel(){
  457. //当前学期
  458. $currSemester = $this->schoolManager->getCurrSemester();
  459. $semId = $currSemester['semester_id'];
  460. $psType = explode('_',Req::post('psType'));
  461. $classR = SProductClassRelation::model()->find("ps_id={$psType[1]} AND semester_id={$semId}");
  462. if($classR){
  463. $data['status'] = 2;
  464. $data['info'] = "有关联的学校,无法删除";
  465. }else{
  466. //其他关联了次产品的班级设置为默认
  467. $otherClassR = SProductClassRelation::model()->find("ps_id={$psType[1]} AND semester_id!={$semId}");
  468. $defaultId = SProductSetting::model()->find("product_type={$psType[0]} AND is_default=1");
  469. if($otherClassR){
  470. //获取默认产品
  471. $criteria = new CDbCriteria();
  472. $criteria->addCondition("ps_id={$psType[1]}");
  473. SProductClassRelation::model()->updateAll(array('ps_id'=>$defaultId->ps_id),$criteria);
  474. }
  475. $result = SProductSetting::model()->deleteByPk($psType[1]);
  476. if($result){
  477. $data['status'] = 1;
  478. $data['info'] = "删除成功";
  479. $data['data']=$defaultId->ps_id;
  480. }else{
  481. $data['status'] = 0;
  482. $data['info'] = "删除失败";
  483. }
  484. }
  485. //操作记录
  486. if(Yii::app()->params['handle_log_on_off']){
  487. writeFileLog(jsonEncode(array(
  488. 'product_id' => $psType[1],
  489. 'title' => '删除产品',
  490. 'operate_url' => 'productset/del',
  491. 'account' => Yii::app()->session['coachInfo']['coach_name'],
  492. 'operate_param' => json_encode(array('post'=>$_POST)),
  493. 'school_id' => $this->schoolId,
  494. 'operate_time' => time(),
  495. 'status' => json_encode($data),
  496. "date"=>date('Y-m-d H:i:s')
  497. )));
  498. }
  499. exit(json_encode($data));
  500. }
  501. //新版产品设置3.0入口
  502. public function actionNav(){
  503. $this->render('productionSetFor3');
  504. }
  505. //获取产品版本
  506. public function actionGetProductEdition()
  507. {
  508. echo json_encode(array('status'=>1,'data'=>$this->getProductEdition(), 'isPrecise'=>$this->isPreciseIsp()));exit;
  509. }
  510. /**
  511. * 是否是精准学习宝
  512. * @return int
  513. */
  514. public function isPreciseIsp()
  515. {
  516. $http = http('customer/precision-learning-school/check/'.$this->schoolId, 'GET', $this->authUsername);
  517. $response = formatResponse($http);
  518. return isset($response['data']) ? $response['data'] : 0;
  519. }
  520. public function getProductEdition()
  521. {
  522. $switch = 2;
  523. $data=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow();
  524. if($data){
  525. $switch = $data['switch'];
  526. }
  527. return $switch;
  528. }
  529. //模板中心
  530. public function actionTemplate(){
  531. //读取所有模板
  532. $data=array();
  533. $this->initTemplate3();
  534. //判断版本
  535. $_num= '';
  536. $use_version = '';
  537. if(isset(Yii::app()->session['coachInfo']->use_version))
  538. {
  539. $use_version = Yii::app()->session['coachInfo']->use_version;
  540. }else
  541. {
  542. $use_version = Yii::app()->session['coachInfo']['use_version'];
  543. }
  544. if(!$use_version)
  545. {
  546. $use_version = 100;
  547. }
  548. $version_number = implode('',explode('.',$use_version));
  549. if(strlen($version_number)<7)
  550. {
  551. for($i=0;$i<7-strlen($version_number);$i++)
  552. {
  553. $_num.='0';
  554. }
  555. }
  556. $version_number=(int)$version_number.$_num;
  557. $isShowCustomCard=1;
  558. $data['isShowCustomCard']=$isShowCustomCard;
  559. $this->render('customMadeCenter',$data);
  560. }
  561. //模板列表接口
  562. public function actionAjaxGetTemplate(){
  563. $data=array();
  564. $subject_id = isset(Yii::app()->session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3;
  565. $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,is_default from product_template where subject_id='{$subject_id}'")->queryAll();
  566. if($productTemplate){
  567. foreach ($productTemplate as $val){
  568. $data['list'][$val['product_type']]=$val;
  569. }
  570. }else{
  571. $this->initTemplate3();
  572. $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,is_default from product_template where subject_id='{$subject_id}'")->queryAll();
  573. foreach ($productTemplate as $val){
  574. $data['list'][$val['product_type']]=$val;
  575. }
  576. }
  577. $result['status'] = 1;
  578. $result['data']=$data['list'];
  579. exit(json_encode($result));
  580. }
  581. //新版产品设置 错题本班级设置
  582. public function actionErrorPushSettingForClass(){
  583. $this->render('errorPushSettingForClass');
  584. }
  585. //复用错题本模板设置
  586. public function actionCopyTemplate(){
  587. $id = intval(Req::post('id'));
  588. $result['status'] = 0;
  589. if(!$id){
  590. $result['msg']='模板ID不能为空';
  591. exit(json_encode($result));
  592. }
  593. $productTemplate=$this->sConn->createCommand("select template_name,product_type,target_type,config_text,subject_id from product_template where template_id='{$id}'")->queryRow();
  594. if(!$productTemplate){
  595. $result['msg']='请选择复用的模板';
  596. exit(json_encode($result));
  597. }
  598. //查询模板名称
  599. $templateName=$productTemplate['template_name'].'副本';
  600. $repeat=$this->sConn->createCommand("select template_name from product_template where template_name like '".$templateName."%' and product_type='".$productTemplate['product_type']."' and target_type='".$productTemplate['target_type']."' and subject_id='".$productTemplate['subject_id']."'")->queryAll();
  601. if($repeat){
  602. $preg='/\(\d+\)/is';
  603. $cloneCount=0;
  604. foreach ($repeat as $value){
  605. $str=str_replace($templateName,'',$value['template_name']);
  606. preg_match_all($preg,$str,$match);
  607. if(isset($match[0]) && count($match[0])==1){
  608. $cloneCount++;
  609. }
  610. }
  611. $templateName.='('.($cloneCount+1).')';
  612. }else{
  613. $templateName.='(1)';
  614. }
  615. $isBeta = $this->isBeta($productTemplate['subject_id']);
  616. $ps = new SProductTemplate();
  617. $ps->template_name = $templateName;
  618. $ps->product_type = $productTemplate['product_type'];
  619. $ps->target_type = $productTemplate['target_type'];
  620. $ps->config_text = $productTemplate['config_text'];
  621. $ps->subject_id = $productTemplate['subject_id'];
  622. $ps->is_default = 0;
  623. $ps->is_beta = $isBeta;
  624. $ps->create_time = time();
  625. if($bool = $ps->save()){
  626. $result['status'] = 1;
  627. $result['msg']='操作成功';
  628. $result['data']=array(
  629. 'id'=>$ps->template_id,
  630. 'name'=>$templateName
  631. );
  632. }else{
  633. $result['msg']='操作失败';
  634. }
  635. exit(json_encode($result));
  636. }
  637. //编辑
  638. public function actionGetTemplate(){
  639. $product_type = intval(Req::get('product_type'));
  640. $target_type = intval(Req::get('target_type'));
  641. $id = intval(Req::get('id'));
  642. $subject_id = 3;
  643. if($id){
  644. $sql = "select subject_id from product_template where template_id = '{$id}'";
  645. $template_data = $this->sConn->createCommand($sql)->queryRow();
  646. if($template_data){
  647. $subject_id = $template_data["subject_id"];
  648. }
  649. }
  650. if(!$product_type || !$target_type){
  651. Yii::app()->jump->error('模板类型不正确');
  652. }
  653. if($subject_id != 3){
  654. if($product_type==1){
  655. if($target_type==1){
  656. $this->render('errorPushSettingForClass_'.$subject_id);
  657. }if($target_type==2){
  658. $this->render('errorPushSettingForStudent_'.$subject_id);
  659. }
  660. }elseif($product_type==2){
  661. if($target_type==1){
  662. $this->render('addPointStep2ForClass_'.$subject_id);
  663. }if($target_type==2){
  664. $this->render('addPointStep2ForStudent_'.$subject_id);
  665. }
  666. }elseif($product_type==3){
  667. if($target_type==1){
  668. $this->render('addPointStep3ForClass_'.$subject_id);
  669. }if($target_type==2){
  670. $this->render('addPointStep3ForStudent_'.$subject_id);
  671. }
  672. }
  673. }else{
  674. if($product_type==1){
  675. if($target_type==1){
  676. $this->render('errorPushSettingForClass');
  677. }if($target_type==2){
  678. $this->render('errorPushSettingForStudent');
  679. }
  680. }elseif($product_type==2){
  681. if($target_type==1){
  682. $this->render('addPointStep2ForClass');
  683. }if($target_type==2){
  684. $this->render('addPointStep2ForStudent');
  685. }
  686. }elseif($product_type==3){
  687. if($target_type==1){
  688. $this->render('addPointStep3ForClass');
  689. }if($target_type==2){
  690. $this->render('addPointStep3ForStudent');
  691. }
  692. }
  693. }
  694. }
  695. public function actionAjaxGetTemplateById(){
  696. $id = intval(Req::post('id'));
  697. $result['status'] = 0;
  698. if(!$id){
  699. $result['msg']='模板ID不正确';
  700. exit(json_encode($result));
  701. }
  702. $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,config_text,subject_id,is_default,create_time from product_template where template_id='{$id}'")->queryRow();
  703. if(!$productTemplate){
  704. $result['msg']='模板id不正确';
  705. exit(json_encode($result));
  706. }else{
  707. $result['status'] = 1;
  708. $result['data'] = $productTemplate;
  709. exit(json_encode($result));
  710. }
  711. }
  712. //保存
  713. public function actionSaveTemplate(){
  714. $id = intval(Req::post('id'));
  715. $config=Req::post('config');
  716. $result['status'] = 0;
  717. $subject_id = 3;
  718. if(!$id || !$config){
  719. $result['msg']='模板参数不正确';
  720. exit(json_encode($result));
  721. }
  722. //
  723. $config=str_replace('&quot;','"',$config);
  724. $configArr=json_decode($config,true);
  725. if(!$configArr){
  726. $result['msg']='设置数据格式不正确';
  727. exit(json_encode($result));
  728. }
  729. $productTemplate=$this->sConn->createCommand("select template_id,product_type,target_type,subject_id from product_template where template_id='{$id}'")->queryRow();
  730. if(!$productTemplate){
  731. $result['msg']='模板id不正确';
  732. exit(json_encode($result));
  733. }else{
  734. $subject_id = $productTemplate["subject_id"];
  735. }
  736. if(!$this->checkoutJson($configArr,$productTemplate['product_type'],$productTemplate['target_type'],$subject_id)){
  737. $result['msg']='设置数据格式不正确';
  738. exit(json_encode($result));
  739. }
  740. if($productTemplate['target_type']==1){
  741. //班级模板
  742. if(isset($configArr['studentLevelDivide']['levelDetails'])){
  743. foreach ($configArr['studentLevelDivide']['levelDetails'] as $val){
  744. if(isset($val['trainPushDetail']) && !$val['trainPushDetail']['pushDifficulty']){
  745. $result['msg']='推送配置难度不能为空';
  746. exit(json_encode($result));
  747. }
  748. }
  749. }else{
  750. $result['msg']='设置数据格式不正确';
  751. exit(json_encode($result));
  752. }
  753. }
  754. $criteria = new CDbCriteria();
  755. $criteria->addCondition("template_id={$id}");
  756. SProductTemplate::model()->updateAll(array('config_text'=>$config),$criteria);
  757. $result['status'] = 1;
  758. $result['msg']='操作成功';
  759. exit(json_encode($result));
  760. }
  761. //根据类型读取模板
  762. public function actionGetTemplateByType(){
  763. $type = intval(Req::post('type')); //模板类型 1-错题本 2-个性化学习方案 3-个性化学习宝
  764. $targetType=intval(Req::post('target_type')); //使用类型:1班级模板,2学生模板
  765. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  766. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  767. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  768. if(!$type ){
  769. $result['msg']='参数错误';
  770. exit(json_encode($result));
  771. }
  772. $isBeta = $this->isBeta($subject_id);
  773. $sql="select template_id,template_name,target_type from product_template where product_type='{$type} ' and subject_id={$subject_id} and is_beta={$isBeta}";
  774. if($targetType && in_array($targetType,array(1,2))){
  775. $sql.=" and target_type='".$targetType."'";
  776. }
  777. $productTemplate=$this->sConn->createCommand($sql)->queryAll();
  778. $result['status'] = 1;
  779. $result['msg']='操作成功';
  780. $result['data']=$productTemplate;
  781. exit(json_encode($result));
  782. }
  783. //班级定制列表,get方法访问空页面,post请求数据
  784. public function actionProductClassSet(){
  785. if (Yii::app()->request->getIsPostRequest()) {
  786. $page=intval(Req::post('page'));
  787. $class_id=Req::post('class_id');
  788. $grade_id=Req::post('grade_id');
  789. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  790. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  791. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  792. if(!$page) $page=1;
  793. $isBeta = $this->isBeta($subject_id);
  794. $pageLimit =10;
  795. $offset=($page-1)*$pageLimit;
  796. $semesterId=$this->semesterId;
  797. $pages=array();
  798. //wrong_book 或wb ,isp ,wb_isp
  799. if($class_id){
  800. $data=$this->sConn->createCommand("select class_id,grade,wrong_book,isp,wb_isp from product_class_set where class_id='{$class_id}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31")->queryAll();
  801. }else{
  802. if($grade_id){
  803. $count=$this->sConn->createCommand("select count(*) as count from product_class_set where semester_id='{$semesterId}' and grade='{$grade_id}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31")->queryRow();
  804. $total=$count['count'];
  805. $totalPage=ceil($total/$pageLimit);
  806. $data=$this->sConn->createCommand("select class_id,grade,wrong_book,isp,wb_isp from product_class_set where semester_id='{$semesterId}' and grade='{$grade_id}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31 limit {$offset},{$pageLimit}")->queryAll();
  807. }else{
  808. $count=$this->sConn->createCommand("select count(*) as count from product_class_set where semester_id='{$semesterId}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31")->queryRow();
  809. $total=$count['count'];
  810. $totalPage=ceil($total/$pageLimit);
  811. $data=$this->sConn->createCommand("select class_id,grade,wrong_book,isp,wb_isp from product_class_set where semester_id='{$semesterId}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31 limit {$offset},{$pageLimit}")->queryAll();
  812. }
  813. $pages=array(
  814. 'totalPage'=>$totalPage,
  815. 'total'=>$total,
  816. 'nowPage'=>$page
  817. );
  818. }
  819. if($data){
  820. //读取所有默认模板
  821. $defaultTemplateArr=array();
  822. $defaultTemplate=$this->sConn->createCommand("select template_name,product_type,target_type from product_template where is_default=1 and target_type=1 and subject_id='{$subject_id}' and is_beta={$isBeta}")->queryAll();
  823. foreach ($defaultTemplate as $value){
  824. $defaultTemplateArr[$value['product_type']]=$value['template_name'];
  825. }
  826. foreach ($data as $key => $val){
  827. $classInfo=$this->sConn->createCommand("select class_name,level from class where class_id='".$val['class_id']."'")->queryRow();
  828. $data[$key]['class_name']=$classInfo['class_name'];
  829. $data[$key]['level']=$classInfo['level'];
  830. //读取模板名
  831. if($val['wrong_book']){
  832. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['wrong_book']}' and is_beta={$isBeta}")->queryRow();
  833. $data[$key]['error_book_name']=$Template['template_name'];
  834. }else{
  835. $data[$key]['error_book_name']=$defaultTemplateArr[1];
  836. }
  837. if($val['isp']){
  838. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['isp']}' and is_beta={$isBeta}")->queryRow();
  839. $data[$key]['step2_name']=$Template['template_name'];
  840. }else{
  841. $data[$key]['step2_name']=$defaultTemplateArr[2];
  842. }
  843. if($val['wb_isp']){
  844. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['wb_isp']}' and is_beta={$isBeta}")->queryRow();
  845. $data[$key]['step3_name']=$Template['template_name'];
  846. }else{
  847. $data[$key]['step3_name']=$defaultTemplateArr[3];
  848. }
  849. }
  850. }
  851. $result['list']=$data;
  852. $result['pages']=$pages;
  853. exit(json_encode(array('status'=>1,'data'=>$result)));
  854. }else{
  855. //判断版本
  856. $_num= '';
  857. $use_version = '';
  858. if(isset(Yii::app()->session['coachInfo']->use_version))
  859. {
  860. $use_version = Yii::app()->session['coachInfo']->use_version;
  861. }else
  862. {
  863. $use_version = Yii::app()->session['coachInfo']['use_version'];
  864. }
  865. if(!$use_version)
  866. {
  867. $use_version = 100;
  868. }
  869. $version_number = implode('',explode('.',$use_version));
  870. if(strlen($version_number)<7)
  871. {
  872. for($i=0;$i<7-strlen($version_number);$i++)
  873. {
  874. $_num.='0';
  875. }
  876. }
  877. $version_number=(int)$version_number.$_num;
  878. $isShowCustomCard=1;
  879. $data['isShowCustomCard']=$isShowCustomCard;
  880. $this->render('customMadeListForClass',$data);
  881. }
  882. }
  883. //学生定制列表,get方法访问空页面,post请求数据
  884. public function actionProductStudentSet(){
  885. if (Yii::app()->request->getIsPostRequest()) {
  886. $page=intval(Req::post('page'));
  887. $class_id=Req::post('class_id');
  888. $grade_id=Req::post('grade_id');
  889. $student_name=Req::post('student_name');
  890. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  891. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  892. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  893. if(!$page) $page=1;
  894. $pageLimit =10;
  895. $offset=($page-1)*$pageLimit;
  896. $semesterId=$this->semesterId;
  897. $subject_id=$this->subjectId;
  898. $pages=array();
  899. $where=array();
  900. $where[]=" semester_id='{$semesterId}'";
  901. $where[]=" use_custom=0";
  902. $where[]=" subject_id='{$subject_id}'";
  903. $where[]=" product_type!=31";
  904. if($class_id){
  905. $where[]=" class_id='{$class_id}'";
  906. }
  907. if($grade_id){
  908. $where[]=" grade='{$grade_id}'";
  909. }
  910. if($student_name){
  911. $where[]=" student_name like '%".$student_name."%'";
  912. }
  913. if($subject_id){
  914. $where[]=" subject_id='{$subject_id}'";
  915. }
  916. $isBeta = $this->isBeta($subject_id);
  917. $where[]= " is_beta={$isBeta}";
  918. $count=$this->sConn->createCommand("select count(*) as count from product_student_set where ".implode(' and ',$where))->queryRow();
  919. $total=$count['count'];
  920. $totalPage=ceil($total/$pageLimit);
  921. $data=$this->sConn->createCommand("select student_id,class_id,grade,wrong_book,isp,wb_isp,student_name from product_student_set where ".implode(' and ',$where)." limit {$offset},{$pageLimit}")->queryAll();
  922. $pages=array(
  923. 'totalPage'=>$totalPage,
  924. 'total'=>$total,
  925. 'nowPage'=>$page
  926. );
  927. if($data){
  928. //取出所有学生,再查询行政班级名字
  929. $student_arr = array();
  930. foreach ($data as $value) {
  931. $student_arr[$value['student_id']] = $value['student_id'];
  932. }
  933. $stu_rel_class = $this->getStudentXzClassName(array_keys($student_arr));
  934. //读取所有默认模板
  935. $defaultTemplateArr=array();
  936. $defaultTemplate=$this->sConn->createCommand("select template_name,product_type,target_type from product_template where is_default=1 and target_type=1 and subject_id = '{$subject_id}' and is_beta={$isBeta}")->queryAll();
  937. foreach ($defaultTemplate as $value){
  938. $defaultTemplateArr[$value['product_type']]=$value['template_name'];
  939. }
  940. foreach ($data as $key => $val){
  941. $classInfo=$this->sConn->createCommand("select class_name,level from class where class_id='".$val['class_id']."'")->queryRow();
  942. if (isset($stu_rel_class[$val['student_id']])) {
  943. $data[$key]['class_name']=$stu_rel_class[$val['student_id']];
  944. }else{
  945. $data[$key]['class_name']=$classInfo['class_name'];
  946. }
  947. $data[$key]['level']=$classInfo['level'];
  948. //读取系统准考证号
  949. $student=$this->conn->createCommand("select student_card from student where student_id='".$val['student_id']."'")->queryRow();
  950. $data[$key]['student_card']=$student['student_card'];
  951. $classTemplateData=$this->sConn->createCommand("select wrong_book,isp,wb_isp from product_class_set where class_id='".$val['class_id']."' and subject_id = '{$subject_id}' and is_beta={$isBeta} and product_type!=31")->queryRow();
  952. //读取模板名
  953. if($val['wrong_book']){
  954. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['wrong_book']}' and is_beta={$isBeta}")->queryRow();
  955. $data[$key]['error_book_name']=$Template['template_name'];
  956. }else{
  957. if($classTemplateData['wrong_book']){
  958. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$classTemplateData['wrong_book']}' and is_beta={$isBeta}")->queryRow();
  959. $data[$key]['error_book_name']=$Template['template_name'];
  960. }else{
  961. $data[$key]['error_book_name']=$defaultTemplateArr[1];
  962. }
  963. }
  964. if($val['isp']){
  965. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['isp']}' and is_beta={$isBeta}")->queryRow();
  966. $data[$key]['step2_name']=$Template['template_name'];
  967. }else{
  968. if($classTemplateData['isp']){
  969. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$classTemplateData['isp']}' and is_beta={$isBeta}")->queryRow();
  970. $data[$key]['step2_name']=$Template['template_name'];
  971. }else{
  972. $data[$key]['step2_name']=$defaultTemplateArr[2];
  973. }
  974. }
  975. if($val['wb_isp']){
  976. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['wb_isp']}' and is_beta={$isBeta}")->queryRow();
  977. $data[$key]['step3_name']=$Template['template_name'];
  978. }else{
  979. if($classTemplateData['wb_isp']){
  980. $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$classTemplateData['wb_isp']}' and is_beta={$isBeta}")->queryRow();
  981. $data[$key]['step3_name']=$Template['template_name'];
  982. }else{
  983. $data[$key]['step3_name']=$defaultTemplateArr[3];
  984. }
  985. }
  986. }
  987. }
  988. $result['list']=$data;
  989. $result['pages']=$pages;
  990. exit(json_encode(array('status'=>1,'data'=>$result)));
  991. }else{
  992. //判断版本
  993. $_num= '';
  994. $use_version = '';
  995. if(isset(Yii::app()->session['coachInfo']->use_version))
  996. {
  997. $use_version = Yii::app()->session['coachInfo']->use_version;
  998. }else
  999. {
  1000. $use_version = Yii::app()->session['coachInfo']['use_version'];
  1001. }
  1002. if(!$use_version)
  1003. {
  1004. $use_version = 100;
  1005. }
  1006. $version_number = implode('',explode('.',$use_version));
  1007. if(strlen($version_number)<7)
  1008. {
  1009. for($i=0;$i<7-strlen($version_number);$i++)
  1010. {
  1011. $_num.='0';
  1012. }
  1013. }
  1014. $version_number=(int)$version_number.$_num;
  1015. $isShowCustomCard=1;
  1016. $data['isShowCustomCard']=$isShowCustomCard;
  1017. $this->render('customMadeListForStudent',$data);
  1018. }
  1019. }
  1020. //学生自定义配置列表,get方法访问空页面,post请求数据
  1021. public function actionCustomProductStudentSet(){
  1022. if (Yii::app()->request->getIsPostRequest()) {
  1023. $page=intval(Req::post('page'));
  1024. $class_id=Req::post('class_id');
  1025. $grade_id=Req::post('grade_id');
  1026. $student_name=Req::post('student_name');
  1027. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  1028. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  1029. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  1030. if(!$page) $page=1;
  1031. $pageLimit =10;
  1032. $offset=($page-1)*$pageLimit;
  1033. $semesterId=$this->semesterId;
  1034. $subject_id=$this->subjectId;
  1035. $pages=array();
  1036. $where=array();
  1037. $where[]=" semester_id='{$semesterId}'";
  1038. $where[]=" use_custom=1";
  1039. $where[]=" subject_id='{$subject_id}'";
  1040. $where[]=" product_type!=31";
  1041. if($class_id){
  1042. $where[]=" class_id='{$class_id}'";
  1043. }
  1044. if($grade_id){
  1045. $where[]=" grade='{$grade_id}'";
  1046. }
  1047. if($student_name){
  1048. $where[]=" student_name like '%".$student_name."%'";
  1049. }
  1050. if($subject_id){
  1051. $where[]=" subject_id='{$subject_id}'";
  1052. }
  1053. //抢先体验版
  1054. $isBeta = $this->isBeta($subject_id);
  1055. $where[] = " is_beta='{$isBeta}'";
  1056. $count=$this->sConn->createCommand("select count(*) as count from product_student_set where ".implode(' and ',$where))->queryRow();
  1057. $total=$count['count'];
  1058. $totalPage=ceil($total/$pageLimit);
  1059. $data=$this->sConn->createCommand("select student_id,student_name,class_id,grade,custom_config_img,custom_config_json from product_student_set where ".implode(' and ',$where)." limit {$offset},{$pageLimit}")->queryAll();
  1060. $pages=array(
  1061. 'totalPage'=>$totalPage,
  1062. 'total'=>$total,
  1063. 'nowPage'=>$page
  1064. );
  1065. if($data){
  1066. //取出所有学生,再查询行政班级名字
  1067. $student_arr = array();
  1068. foreach ($data as $value) {
  1069. $student_arr[$value['student_id']] = $value['student_id'];
  1070. }
  1071. $stu_rel_class = $this->getStudentXzClassName(array_keys($student_arr));
  1072. foreach ($data as $key => $val){
  1073. $classInfo=$this->sConn->createCommand("select class_name,level from class where class_id='".$val['class_id']."'")->queryRow();
  1074. if (isset($stu_rel_class[$val['student_id']])) {
  1075. $data[$key]['class_name']=$stu_rel_class[$val['student_id']];
  1076. }else{
  1077. $data[$key]['class_name']=$classInfo['class_name'];
  1078. }
  1079. $data[$key]['level']=$classInfo['level'];
  1080. //读取系统准考证号
  1081. $student=$this->conn->createCommand("select student_card from student where student_id='".$val['student_id']."'")->queryRow();
  1082. $data[$key]['student_card']=$student['student_card'];
  1083. }
  1084. }
  1085. $result['list']=$data;
  1086. $result['pages']=$pages;
  1087. exit(json_encode(array('status'=>1,'data'=>$result)));
  1088. }else{
  1089. //判断版本
  1090. $_num= '';
  1091. $use_version = '';
  1092. if(isset(Yii::app()->session['coachInfo']->use_version))
  1093. {
  1094. $use_version = Yii::app()->session['coachInfo']->use_version;
  1095. }else
  1096. {
  1097. $use_version = Yii::app()->session['coachInfo']['use_version'];
  1098. }
  1099. if(!$use_version)
  1100. {
  1101. $use_version = 100;
  1102. }
  1103. $version_number = implode('',explode('.',$use_version));
  1104. if(strlen($version_number)<7)
  1105. {
  1106. for($i=0;$i<7-strlen($version_number);$i++)
  1107. {
  1108. $_num.='0';
  1109. }
  1110. }
  1111. $version_number=(int)$version_number.$_num;
  1112. $isShowCustomCard=1;
  1113. $data['isShowCustomCard']=$isShowCustomCard;
  1114. $this->render('studentOptionalCard',$data);
  1115. }
  1116. }
  1117. //删除学生自定义配置
  1118. public function actionDelStudentOptionalCard(){
  1119. $student_id=Req::post('student_id');
  1120. $subject_id=$this->subjectId;
  1121. if(!$student_id){
  1122. $result['msg']='参数异常';
  1123. exit(json_encode($result));
  1124. }
  1125. $semesterId=$this->semesterId;
  1126. $isBeta = $this->isBeta($subject_id);
  1127. $data=$this->sConn->createCommand("select count(*) as count from product_student_set where student_id='{$student_id}' and semester_id='{$semesterId}' and use_custom=1 and subject_id='{$subject_id}' and is_beta={$isBeta}")->queryRow();
  1128. if($data){
  1129. $rs=$this->sConn->createCommand("update product_student_set set use_custom=0 where student_id='{$student_id}' and semester_id='{$semesterId}' and subject_id='{$subject_id}' and is_beta={$isBeta}")->execute();
  1130. if($rs){
  1131. exit(json_encode(array('status'=>1,'msg'=>'删除成功')));
  1132. }else{
  1133. exit(json_encode(array('status'=>0,'msg'=>'删除失败')));
  1134. }
  1135. }else{
  1136. exit(json_encode(array('status'=>0,'msg'=>'学生自定义记录不存在')));
  1137. }
  1138. }
  1139. //新增班级定制
  1140. public function actionCustomMadeForClass(){
  1141. $this->render('customMadeForClass');
  1142. }
  1143. //新增学生定制
  1144. public function actionCustomMadeForStudent(){
  1145. $this->render('customMadeForStudent');
  1146. }
  1147. //保存班级定制
  1148. public function actionSaveClassSet(){
  1149. $post=Req::post('json');
  1150. $product_type=Req::post('template_type');
  1151. // $product_type=$post['template_type']; //1 错题本 2 二步 3 三步
  1152. $classIds=Req::post('classes'); //班级id组 包含年级
  1153. $template_id=Req::post('template_id');
  1154. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  1155. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  1156. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  1157. $result['status'] = 0;
  1158. if(!$product_type ){
  1159. $result['msg']='请选择模板类型';
  1160. exit(json_encode($result));
  1161. }
  1162. if(!$classIds){
  1163. $result['msg']='请选择班级';
  1164. exit(json_encode($result));
  1165. }
  1166. if(!$template_id){
  1167. $result['msg']='请选择模板';
  1168. exit(json_encode($result));
  1169. }
  1170. $isBeta = $this->isBeta($subject_id);
  1171. $templateInfo=$this->sConn->createCommand("select product_type,target_type from product_template where template_id='{$template_id}' and is_beta={$isBeta}")->queryRow();
  1172. if($templateInfo['product_type']!=$product_type){
  1173. $result['msg']='模板类型不正确';
  1174. exit(json_encode($result));
  1175. }
  1176. if($product_type==1){
  1177. $field='wrong_book';
  1178. }elseif ($product_type==2){
  1179. $field='isp';
  1180. }elseif($product_type==3){
  1181. $field='wb_isp';
  1182. }else{
  1183. $result['msg']='模板类型错误';
  1184. exit(json_encode($result));
  1185. }
  1186. $updateSql=array();
  1187. $insertSql=array();
  1188. foreach ($classIds as $val){
  1189. if(!isset($val['class_id']) || !$val['class_id']){
  1190. $result['msg']='班级数据错误';
  1191. exit(json_encode($result));
  1192. }
  1193. $classInfo=$this->sConn->createCommand("select class_id,grade from class where class_id='{$val['class_id']}'")->queryRow();
  1194. if(!$classInfo){
  1195. $result['msg']='选择的班级不存在';
  1196. exit(json_encode($result));
  1197. }
  1198. $classSet=$this->sConn->createCommand("select class_id from product_class_set where class_id='{$val['class_id']}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type<>31")->queryRow();
  1199. $sql='';
  1200. if($classSet){
  1201. $updateSql[]="update product_class_set set `".$field."`='".$template_id."',semester_id='".$this->semesterId."' where class_id='".$val['class_id']."' and subject_id='{$subject_id}' and is_beta={$isBeta}";
  1202. }else{
  1203. $insertSql[]="insert into product_class_set(`class_id`,`semester_id`,`grade`,`".$field."`,`subject_id`,`is_beta`) values('".$val['class_id']."','".$this->semesterId."','".$classInfo['grade']."','".$template_id."','".$subject_id."','".$isBeta."')";
  1204. }
  1205. }
  1206. $trans = $this->sConn->beginTransaction();
  1207. try{
  1208. if($updateSql){
  1209. foreach ($updateSql as $sql){
  1210. $this->sConn->createCommand($sql)->execute();
  1211. }
  1212. }
  1213. if($insertSql){
  1214. foreach ($insertSql as $sql){
  1215. $this->sConn->createCommand($sql)->execute();
  1216. }
  1217. }
  1218. $trans->commit();
  1219. $result['status'] = 1;
  1220. $result['msg'] = "更新成功";
  1221. }catch (Exception $e){
  1222. $trans->rollBack();
  1223. $result['status'] = 0;
  1224. $result['msg'] = "更新失败";
  1225. }
  1226. exit(json_encode($result));
  1227. }
  1228. //保存学生定制
  1229. public function actionSaveStudentSet(){
  1230. $post=Req::post('json');
  1231. $product_type=Req::post('template_type');//1 错题本 2 二步 3 三步
  1232. // $product_type=$post['template_type']; //1 错题本 2 二步 3 三步
  1233. $studentIds=Req::post('students');
  1234. $template_id=Req::post('template_id');
  1235. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  1236. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  1237. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  1238. $isBeta = $this->isBeta($subject_id);
  1239. $result['status'] = 0;
  1240. if(!$product_type){
  1241. $result['msg']='请选择模板类型';
  1242. exit(json_encode($result));
  1243. }
  1244. if(!$studentIds){
  1245. $result['msg']='请选择学生';
  1246. exit(json_encode($result));
  1247. }
  1248. if(!$template_id){
  1249. $result['msg']='请选择模板';
  1250. exit(json_encode($result));
  1251. }
  1252. $templateInfo=$this->sConn->createCommand("select product_type,target_type from product_template where template_id='{$template_id}' and is_beta={$isBeta}")->queryRow();
  1253. if($templateInfo['product_type']!=$product_type){
  1254. $result['msg']='模板类型不正确';
  1255. exit(json_encode($result));
  1256. }
  1257. if($product_type==1){
  1258. $field='wrong_book';
  1259. }elseif ($product_type==2){
  1260. $field='isp';
  1261. }elseif($product_type==3){
  1262. $field='wb_isp';
  1263. }else{
  1264. $result['msg']='模板类型错误';
  1265. exit(json_encode($result));
  1266. }
  1267. $err=array();
  1268. $updateSql=array();
  1269. $insertSql=array();
  1270. $isBeta = $this->isBeta($subject_id);
  1271. foreach ($studentIds as $val){
  1272. if(!$val['student_id'] || !$val['realname'] || !$val['class_id'] || !$val['grade_id']){
  1273. $result['msg']='学生数据错误';
  1274. exit(json_encode($result));
  1275. }
  1276. $classInfo=$this->sConn->createCommand("select class_id,grade from class where class_id='{$val['class_id']}'")->queryRow();
  1277. if(!$classInfo){
  1278. $result['msg']='选择的班级不存在';
  1279. exit(json_encode($result));
  1280. }
  1281. $studentSet=$this->sConn->createCommand("select student_id,student_name,use_custom,semester_id from product_student_set where student_id='{$val['student_id']}' and subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31")->queryRow();
  1282. $sql='';
  1283. if($studentSet){
  1284. if($studentSet['use_custom']==1 && $studentSet['semester_id']==$this->semesterId){
  1285. $err[]=$studentSet['student_name'];
  1286. continue;
  1287. }elseif($studentSet['use_custom']==1){
  1288. $updateSql[]="update product_student_set set `".$field."`='".$template_id."',use_custom=0,semester_id='".$this->semesterId."' where student_id='".$val['student_id']."' and subject_id='".$subject_id."' and product_type!=31";
  1289. }else{
  1290. $updateSql[]="update product_student_set set `".$field."`='".$template_id."',semester_id='".$this->semesterId."' where student_id='".$val['student_id']."' and subject_id='".$subject_id."' and product_type!=31";
  1291. }
  1292. }else{
  1293. $insertSql[]="insert into product_student_set(`student_id`,`student_name`,`semester_id`,`class_id`,`grade`,`".$field."`,`subject_id`,`is_beta`) values('".$val['student_id']."','".$val['realname']."','".$this->semesterId."','".$val['class_id']."','".$classInfo['grade']."','".$template_id."','".$subject_id."','".$isBeta."')";
  1294. }
  1295. }
  1296. $trans = $this->sConn->beginTransaction();
  1297. try{
  1298. if($updateSql){
  1299. foreach ($updateSql as $sql){
  1300. $this->sConn->createCommand($sql)->execute();
  1301. }
  1302. }
  1303. if($insertSql){
  1304. foreach ($insertSql as $sql){
  1305. $this->sConn->createCommand($sql)->execute();
  1306. }
  1307. }
  1308. $trans->commit();
  1309. $result['status'] = 1;
  1310. if($err){
  1311. $result['msg']='更新完成,学生:【'.implode(',',$err).'】因已使用自选卡未更新';
  1312. }else{
  1313. $result['msg']='更新完成';
  1314. }
  1315. }catch (Exception $e){
  1316. $trans->rollBack();
  1317. $result['status'] = 0;
  1318. $result['msg'] = "更新失败";
  1319. }
  1320. exit(json_encode($result));
  1321. }
  1322. //根据年级读取班级
  1323. public function actionGetClassByGrade(){
  1324. $grade_id = Req::post("grade_id");
  1325. $class_array = array();
  1326. if(!in_array($grade_id,array(0,1,2,3)))
  1327. {
  1328. echo json_encode(array('status'=>0,'result'=>array()));exit;
  1329. }
  1330. if($grade_id){
  1331. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=:class_type',array(':grade' => $grade_id,':semester_id'=>$this->semesterId,':class_type'=>1));
  1332. }else{
  1333. $class_data = ClassModel::model()->findAll(' semester_id=:semester_id and class_type=:class_type',array(':semester_id'=>$this->semesterId ,':class_type'=>1));
  1334. }
  1335. if($class_data){
  1336. foreach($class_data as $v )
  1337. {
  1338. $class_array[] = $v->attributes;
  1339. }
  1340. echo json_encode(array('status'=>1,'result'=>$class_array));exit;
  1341. }
  1342. echo json_encode(array('status'=>0,'result'=>array()));exit;
  1343. }
  1344. //班级恢复默认
  1345. public function actionResetClassSet(){
  1346. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  1347. $subject_id = isset(Yii::app()->session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3;
  1348. $subject_id = $post_subject_id?$post_subject_id:$subject_id;
  1349. $isBeta = $this->isBeta($subject_id);
  1350. $sql = "select class_id from product_class_set where subject_id = '{$subject_id}' and is_beta={$isBeta} and (wrong_book!=0 or isp!=0 or wb_isp!=0) and product_type!=31";
  1351. $class_set = $this->sConn->createCommand($sql)->queryRow();
  1352. if(!$class_set){
  1353. echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit;
  1354. }
  1355. if($this->sConn->createCommand("update product_class_set set wrong_book=0,isp=0,wb_isp=0 where subject_id = '{$subject_id}' and is_beta={$isBeta} and product_type!=31")->execute()){
  1356. echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit;
  1357. }else{
  1358. echo json_encode(array('status'=>0,'msg'=>'操作失败'));exit;
  1359. }
  1360. }
  1361. //学生恢复默认
  1362. public function actionResetStudentSet(){
  1363. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  1364. $subject_id = isset(Yii::app()->session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3;
  1365. $subject_id = $post_subject_id?$post_subject_id:$subject_id;
  1366. $isBeta = $this->isBeta($subject_id);
  1367. $sql = "select student_id from product_student_set where subject_id = '{$subject_id}' and is_beta={$isBeta} and (wrong_book!=0 or isp!=0 or wb_isp!=0) and product_type!=31";
  1368. $student_set = $this->sConn->createCommand($sql)->queryRow();
  1369. if(!$student_set){
  1370. echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit;
  1371. }
  1372. if($this->sConn->createCommand("update product_student_set set wrong_book=0,isp=0,wb_isp=0 where subject_id='{$subject_id}' and is_beta={$isBeta} and product_type!=31")->execute()){
  1373. echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit;
  1374. }else{
  1375. echo json_encode(array('status'=>0,'msg'=>'操作失败'));exit;
  1376. }
  1377. }
  1378. //选择版本切换
  1379. public function actionSwitchEdition(){
  1380. $edition=intval(Req::post('edition')); //产品设置版本,2,3 抢先版4
  1381. if(!in_array($edition,array(2,3,4))){
  1382. echo json_encode(array('status'=>0,'msg'=>'版本不正确'));exit;
  1383. }
  1384. $transaction = $this->sConn->beginTransaction();
  1385. try {
  1386. $switch = $this->sConn->createCommand("select id from producut_set_edition ")->queryRow();
  1387. if (!$switch) {
  1388. $this->sConn->createCommand("insert into producut_set_edition(`id`,`switch`) values(1,2) ")->execute();
  1389. }
  1390. if($edition==2){
  1391. $SendLabel=$this->sConn->createCommand("select paper_id from paper where labelled_type=2 and is_labelled in(2,3,5) limit 1")->queryRow();
  1392. if($SendLabel){
  1393. echo json_encode(array('status'=>0,'msg'=>'当前有正在标注的教师版本,请完成或撤销标注后修改'));exit;
  1394. }
  1395. }
  1396. if($this->sConn->createCommand("update producut_set_edition set switch={$edition} where id=1 ")->execute()){
  1397. if ($edition != 2) {
  1398. $this->initTemplate3();
  1399. }
  1400. }
  1401. $transaction->commit();
  1402. echo json_encode(array('status' => 1, 'msg' => '操作成功'));
  1403. exit;
  1404. }catch (\Exception $exception){
  1405. $transaction->rollback();
  1406. echo json_encode(array('status'=>0,'msg'=>'操作失败'));exit;
  1407. }
  1408. }
  1409. public function actionDownPdf(){
  1410. $isBeta = $this->isBeta($this->subjectId);
  1411. // TODO 下载文件替换
  1412. $schoolId=$this->schoolId;
  1413. if(strlen($schoolId)<=3){
  1414. $fileStr = $isBeta ? 'optional_card_8_3.3.pdf' : 'optional_card_8.pdf';
  1415. }else{
  1416. $fileStr = $isBeta ? 'optional_card_9_3.3.pdf' : 'optional_card_9.pdf';
  1417. }
  1418. $filename= dirname(dirname(dirname(__FILE__))).'/assets/data/'.$fileStr;
  1419. if (FALSE!== ($handler = fopen($filename, 'r')))
  1420. {
  1421. header('Content-Description: File Transfer');
  1422. header('Content-Type: application/octet-stream');
  1423. header('Content-Disposition: attachment; filename=学生自选卡.pdf');
  1424. header('Content-Transfer-Encoding: chunked'); //changed to chunked
  1425. header('Expires: 0');
  1426. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1427. header('Pragma: public');
  1428. while (!feof($handler)) {
  1429. file_put_contents("php://output", fread($handler, 4096));
  1430. }
  1431. fclose($handler);
  1432. }
  1433. }
  1434. //修改自选卡
  1435. public function actionSaveOptionalCard(){
  1436. $studentId=Req::post('studentId');
  1437. $json=Req::post('json');
  1438. $subject_id=$this->subjectId;
  1439. if(!$studentId){
  1440. echo json_encode(array('status'=>0,'msg'=>'学生ID不正确 '));exit;
  1441. }
  1442. $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id
  1443. $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3;
  1444. $subject_id = $post_subject_id?$post_subject_id:$session_subject_id;
  1445. $json=str_replace('&quot;','"',$json);
  1446. $jsonData=json_decode($json,true);
  1447. if(!$jsonData){
  1448. echo json_encode(array('status'=>0,'msg'=>'配置参数格式不正确 '));exit;
  1449. }
  1450. $isBeta = $this->isBeta($this->subjectId);
  1451. $studentSetting=$this->sConn->createCommand("select student_name from product_student_set where student_id='{$studentId}' and semester_id='{$this->semesterId}' and subject_id='{$subject_id}' and is_beta={$isBeta}")->queryRow();
  1452. if(!$studentSetting){
  1453. echo json_encode(array('status'=>0,'msg'=>'未发现该学生配置数据'));exit;
  1454. }
  1455. //TODO 区分3.0和抢先版
  1456. if($isBeta){
  1457. $defaultConfig='{
  1458. "studentLevelDivide": {
  1459. "levelDetails": [
  1460. {
  1461. "isPushTrain": true,
  1462. "errorPushDetail": {
  1463. },
  1464. "trainPushDetail": {
  1465. }
  1466. }
  1467. ]
  1468. },
  1469. "errorTypeSetting": {
  1470. "hasEncourage":true,
  1471. "hasScoreDetail":true,
  1472. "hasPromoteGuide":false,
  1473. "hasErrorOriginNote":true,
  1474. "hasTrainTypesetting":false,
  1475. "testVideo":false,
  1476. "scoreOfCollege":true,
  1477. "classmateOptimization":false,
  1478. "commonProblems":true,
  1479. "hasWrongAnswer":false,
  1480. "hasRankingChange":false,
  1481. "hasAchievementChange":false,
  1482. "hasMathSituation":false,
  1483. "historyCollection":true,
  1484. "pushQuestionUpgrade":false
  1485. }
  1486. }';
  1487. }else{
  1488. $defaultConfig='{
  1489. "studentLevelDivide": {
  1490. "levelDetails": [
  1491. {
  1492. "isPushTrain": true,
  1493. "errorPushDetail": {
  1494. },
  1495. "trainPushDetail": {
  1496. }
  1497. }
  1498. ]
  1499. },
  1500. "errorTypeSetting": {
  1501. "hasEncourage": true,
  1502. "hasRankingChange": true,
  1503. "hasAchievementChange": true,
  1504. "hasGoodKnowledge": true,
  1505. "hasLoseKnowledge": true,
  1506. "hasScoreDetail": true,
  1507. "hasErrorOriginNote": true,
  1508. "hasDividePage": true,
  1509. "pushQuestionUpgrade":true,
  1510. "hasWrongAnswer": true,
  1511. "isWrongAnswerEnd": true
  1512. }
  1513. }';
  1514. }
  1515. $customConfig=json_decode($defaultConfig,true);
  1516. $errorPushDetailValue[15]=array(
  1517. 'A'=>'pushLose',
  1518. 'B'=>'pushZero',
  1519. 'C'=>'pushNone'
  1520. );
  1521. $errorPushDetailValue[16]=array(
  1522. 'A'=>'pushLose',
  1523. 'B'=>'pushZero',
  1524. 'C'=>'pushNone'
  1525. );
  1526. $errorPushDetailValue[17]=array(
  1527. 'A'=>'pushLose',
  1528. 'B'=>'pushThree',
  1529. 'C'=>'pushHalf',
  1530. 'D'=>'pushNone'
  1531. );
  1532. $errorPushDetailValue[18]=array(
  1533. 'A'=>'pushLose',
  1534. 'B'=>'pushThree',
  1535. 'C'=>'pushHalf',
  1536. 'D'=>'pushNone'
  1537. );
  1538. $errorPushDetailValue[19]=array(
  1539. 'A'=>'1',
  1540. 'B'=>'2',
  1541. 'C'=>'3',
  1542. 'D'=>'0'
  1543. );
  1544. $trainPushDetailValue[20]=array(
  1545. 'A'=>'0',
  1546. 'B'=>'1',
  1547. 'C'=>'3',
  1548. // 'D'=>'3'
  1549. );
  1550. $trainPushDetailValue[21]=array(
  1551. 'A'=>'1',
  1552. 'B'=>'2',
  1553. 'C'=>'3',
  1554. 'D'=>'3'
  1555. );
  1556. $defaultValues=array(
  1557. 'A'=>'0',
  1558. 'B'=>'1',
  1559. 'C'=>'2',
  1560. 'D'=>'3'
  1561. );
  1562. $errorPushDetail=array();
  1563. $trainPushDetail=array();
  1564. $maxTopicNumber=0; //变式训练推送题数量最大值
  1565. $pushDifficulty=0; //变式训练推送难度
  1566. if(count($jsonData)!=27 && count($jsonData)!=26){
  1567. $this->output(0, "配置参数数量不正确");
  1568. }
  1569. if($isBeta){
  1570. /** 3.4版本 **/
  1571. foreach ($jsonData as $key => $val){
  1572. switch ($val['questionNum']){
  1573. case 1: //激励语
  1574. if(!$val['answer']){
  1575. $customConfig['errorTypeSetting']['hasEncourage']=true;
  1576. }elseif($val['answer']=='A'){
  1577. $customConfig['errorTypeSetting']['hasEncourage']=true;
  1578. }else{
  1579. $customConfig['errorTypeSetting']['hasEncourage']=false;
  1580. }
  1581. break;
  1582. case 2: //得分明细
  1583. if(!$val['answer']){
  1584. $customConfig['errorTypeSetting']['hasScoreDetail']=true;
  1585. }elseif($val['answer']=='A'){
  1586. $customConfig['errorTypeSetting']['hasScoreDetail']=true;
  1587. }else{
  1588. $customConfig['errorTypeSetting']['hasScoreDetail']=false;
  1589. }
  1590. break;
  1591. case 3: //提升指导
  1592. if(!$val['answer']){
  1593. $customConfig['errorTypeSetting']['hasPromoteGuide']=true;
  1594. }elseif($val['answer']=='A'){
  1595. $customConfig['errorTypeSetting']['hasPromoteGuide']=true;
  1596. }else{
  1597. $customConfig['errorTypeSetting']['hasPromoteGuide']=false;
  1598. }
  1599. break;
  1600. case 4: //排名变化图
  1601. if(!$val['answer']){
  1602. $customConfig['errorTypeSetting']['hasRankingChange']=true;
  1603. }elseif($val['answer']=='A'){
  1604. $customConfig['errorTypeSetting']['hasRankingChange']=true;
  1605. }else{
  1606. $customConfig['errorTypeSetting']['hasRankingChange']=false;
  1607. }
  1608. break;
  1609. case 5: //成绩变化图
  1610. if(!$val['answer']){
  1611. $customConfig['errorTypeSetting']['hasAchievementChange']=true;
  1612. }elseif($val['answer']=='A'){
  1613. $customConfig['errorTypeSetting']['hasAchievementChange']=true;
  1614. }else{
  1615. $customConfig['errorTypeSetting']['hasAchievementChange']=false;
  1616. }
  1617. break;
  1618. case 6: //数学情境
  1619. if(!$val['answer']){
  1620. $customConfig['errorTypeSetting']['hasMathSituation']=true;
  1621. }elseif($val['answer']=='A'){
  1622. $customConfig['errorTypeSetting']['hasMathSituation']=true;
  1623. }else{
  1624. $customConfig['errorTypeSetting']['hasMathSituation']=false;
  1625. }
  1626. break;
  1627. case 7: //学史典藏
  1628. if(!$val['answer']){
  1629. $customConfig['errorTypeSetting']['historyCollection']=true;
  1630. }elseif($val['answer']=='A'){
  1631. $customConfig['errorTypeSetting']['historyCollection']=true;
  1632. }else{
  1633. $customConfig['errorTypeSetting']['historyCollection']=false;
  1634. }
  1635. break;
  1636. case 8: //错题原笔迹
  1637. if(!$val['answer']){
  1638. $customConfig['errorTypeSetting']['hasErrorOriginNote']=true;
  1639. }elseif($val['answer']=='A'){
  1640. $customConfig['errorTypeSetting']['hasErrorOriginNote']=true;
  1641. }else{
  1642. $customConfig['errorTypeSetting']['hasErrorOriginNote']=false;
  1643. }
  1644. break;
  1645. case 9: //变式训练题排版方式(是否和错题一起)
  1646. if(!$val['answer']){
  1647. $customConfig['errorTypeSetting']['hasTrainTypesetting']=true;
  1648. }elseif($val['answer']=='A'){
  1649. $customConfig['errorTypeSetting']['hasTrainTypesetting']=true;
  1650. }else{
  1651. $customConfig['errorTypeSetting']['hasTrainTypesetting']=false;
  1652. }
  1653. break;
  1654. case 10: //考点视频二维码
  1655. if(!$val['answer']){
  1656. $customConfig['errorTypeSetting']['testVideo']=true;
  1657. }elseif($val['answer']=='A'){
  1658. $customConfig['errorTypeSetting']['testVideo']=true;
  1659. }else{
  1660. $customConfig['errorTypeSetting']['testVideo']=false;
  1661. }
  1662. break;
  1663. case 11: //考点高考分值表
  1664. if(!$val['answer']){
  1665. $customConfig['errorTypeSetting']['scoreOfCollege']=true;
  1666. }elseif($val['answer']=='A'){
  1667. $customConfig['errorTypeSetting']['scoreOfCollege']=true;
  1668. }else{
  1669. $customConfig['errorTypeSetting']['scoreOfCollege']=false;
  1670. }
  1671. break;
  1672. case 12: //同学优解
  1673. if(!$val['answer']){
  1674. $customConfig['errorTypeSetting']['classmateOptimization']=true;
  1675. }elseif($val['answer']=='A'){
  1676. $customConfig['errorTypeSetting']['classmateOptimization']=true;
  1677. }else{
  1678. $customConfig['errorTypeSetting']['classmateOptimization']=false;
  1679. }
  1680. break;
  1681. case 13: //共性问题
  1682. if(!$val['answer']){
  1683. $customConfig['errorTypeSetting']['commonProblems']=true;
  1684. }elseif($val['answer']=='A'){
  1685. $customConfig['errorTypeSetting']['commonProblems']=true;
  1686. }else{
  1687. $customConfig['errorTypeSetting']['commonProblems']=false;
  1688. }
  1689. break;
  1690. case 14: //题目和答案是否一起
  1691. if(!$val['answer']){
  1692. $customConfig['errorTypeSetting']['titleAnswerMerge']=true;
  1693. }elseif($val['answer']=='A'){
  1694. $customConfig['errorTypeSetting']['titleAnswerMerge']=true;
  1695. }else{
  1696. $customConfig['errorTypeSetting']['titleAnswerMerge']=false;
  1697. }
  1698. break;
  1699. case 15: //不需要错题答案解析
  1700. if(!$val['answer']){
  1701. $customConfig['errorTypeSetting']['hasWrongAnswer']=true;
  1702. }elseif($val['answer']=='A'){
  1703. $customConfig['errorTypeSetting']['hasWrongAnswer']=true;
  1704. }else{
  1705. $customConfig['errorTypeSetting']['hasWrongAnswer']=false;
  1706. }
  1707. break;
  1708. case 16:
  1709. if(isset($errorPushDetailValue[15][$val['answer']])){
  1710. $errorPushDetail['select'][]=$errorPushDetailValue[15][$val['answer']];
  1711. }else{
  1712. $errorPushDetail['select']=array('pushLose');
  1713. }
  1714. break;
  1715. case 17:
  1716. if(isset($errorPushDetailValue[16][$val['answer']])){
  1717. $errorPushDetail['fillInBlank'][]=$errorPushDetailValue[16][$val['answer']];
  1718. }else{
  1719. $errorPushDetail['fillInBlank'][]=$errorPushDetailValue[16]['A'];
  1720. }
  1721. break;
  1722. case 18:
  1723. if(isset($errorPushDetailValue[17][$val['answer']])){
  1724. $errorPushDetail['answer'][]=$errorPushDetailValue[17][$val['answer']];
  1725. }else{
  1726. $errorPushDetail['answer'][]=$errorPushDetailValue[17]['A'];;
  1727. }
  1728. break;
  1729. case 19:
  1730. if(isset($errorPushDetailValue[18][$val['answer']])){
  1731. $errorPushDetail['chooseAnswer'][]=$errorPushDetailValue[18][$val['answer']];
  1732. }else{
  1733. $errorPushDetail['chooseAnswer'][]=$errorPushDetailValue[18]['A'];;
  1734. }
  1735. break;
  1736. case 20:
  1737. $values=array();
  1738. if($val['answer']){
  1739. $options=explode(',',$val['answer']);
  1740. if($options){
  1741. foreach ($options as $v){
  1742. if(isset($errorPushDetailValue[19][$v])){
  1743. $values[]=$errorPushDetailValue[19][$v];
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if(!$values){
  1749. $values[]=$errorPushDetailValue[19]['D'];
  1750. }
  1751. $errorPushDetail['difficulty']=$values;
  1752. break;
  1753. case 21:
  1754. if(isset($trainPushDetailValue[20][$val['answer']])){
  1755. $pushDifficulty=$trainPushDetailValue[20][$val['answer']];
  1756. }else{
  1757. $pushDifficulty=$trainPushDetailValue[20]['A'];
  1758. }
  1759. break;
  1760. case 22:
  1761. if(isset($defaultValues[$val['answer']])){
  1762. $trainPushDetail['pushNumber']['select']=$defaultValues[$val['answer']];
  1763. }else{
  1764. $trainPushDetail['pushNumber']['select']=$defaultValues['C'];
  1765. }
  1766. $maxTopicNumber = $trainPushDetail['pushNumber']['select'];
  1767. $trainPushDetail['pushDifficulty']['select'] = array();
  1768. if($maxTopicNumber){
  1769. for($i=0;$i<$maxTopicNumber;$i++){
  1770. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  1771. }
  1772. }
  1773. break;
  1774. case 23:
  1775. if(isset($defaultValues[$val['answer']])){
  1776. $trainPushDetail['pushNumber']['fillInBlank']=$defaultValues[$val['answer']];
  1777. }else{
  1778. $trainPushDetail['pushNumber']['fillInBlank']=$defaultValues['C'];
  1779. }
  1780. if($maxTopicNumber<$trainPushDetail['pushNumber']['fillInBlank']){
  1781. $maxTopicNumber=$trainPushDetail['pushNumber']['fillInBlank'];
  1782. $trainPushDetail['pushDifficulty']['select'] = array();
  1783. for($i=0;$i<$maxTopicNumber;$i++){
  1784. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  1785. }
  1786. }
  1787. break;
  1788. case 24:
  1789. if(isset($defaultValues[$val['answer']])){
  1790. $trainPushDetail['pushNumber']['answer']=$defaultValues[$val['answer']];
  1791. }else{
  1792. $trainPushDetail['pushNumber']['answer']=$defaultValues['B'];
  1793. }
  1794. if($maxTopicNumber<$trainPushDetail['pushNumber']['answer']){
  1795. $maxTopicNumber=$trainPushDetail['pushNumber']['answer'];
  1796. $trainPushDetail['pushDifficulty']['select'] = array();
  1797. for($i=0;$i<$maxTopicNumber;$i++){
  1798. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  1799. }
  1800. }
  1801. break;
  1802. case 25:
  1803. if(isset($defaultValues[$val['answer']])){
  1804. $trainPushDetail['pushNumber']['chooseAnswer']=$defaultValues[$val['answer']];
  1805. }else{
  1806. $trainPushDetail['pushNumber']['chooseAnswer']=$defaultValues['B'];
  1807. }
  1808. if($maxTopicNumber<$trainPushDetail['pushNumber']['chooseAnswer']){
  1809. $maxTopicNumber=$trainPushDetail['pushNumber']['chooseAnswer'];
  1810. $trainPushDetail['pushDifficulty']['select'] = array();
  1811. for($i=0;$i<$maxTopicNumber;$i++){
  1812. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  1813. }
  1814. }
  1815. break;
  1816. case 26:
  1817. if(!$val['answer']){
  1818. $customConfig['errorTypeSetting']['pushQuestionUpgrade']=true;
  1819. }elseif($val['answer']=='A'){
  1820. $customConfig['errorTypeSetting']['pushQuestionUpgrade']=true;
  1821. }else{
  1822. $customConfig['errorTypeSetting']['pushQuestionUpgrade']=false;
  1823. }
  1824. break;
  1825. default:
  1826. $this->output(1, "上传题目数量错误");
  1827. }
  1828. }
  1829. }else{
  1830. foreach ($jsonData as $key => $val){
  1831. switch ($val['questionNum']){
  1832. case 1:
  1833. if(!$val['answer']){
  1834. $customConfig['errorTypeSetting']['hasEncourage']=true;
  1835. }elseif($val['answer']=='A'){
  1836. $customConfig['errorTypeSetting']['hasEncourage']=true;
  1837. }else{
  1838. $customConfig['errorTypeSetting']['hasEncourage']=false;
  1839. }
  1840. break;
  1841. case 2:
  1842. if(!$val['answer']){
  1843. $customConfig['errorTypeSetting']['hasRankingChange']=true;
  1844. }elseif($val['answer']=='A'){
  1845. $customConfig['errorTypeSetting']['hasRankingChange']=true;
  1846. }else{
  1847. $customConfig['errorTypeSetting']['hasRankingChange']=false;
  1848. }
  1849. break;
  1850. case 3:
  1851. if(!$val['answer']){
  1852. $customConfig['errorTypeSetting']['hasAchievementChange']=true;
  1853. }elseif($val['answer']=='A'){
  1854. $customConfig['errorTypeSetting']['hasAchievementChange']=true;
  1855. }else{
  1856. $customConfig['errorTypeSetting']['hasAchievementChange']=false;
  1857. }
  1858. break;
  1859. case 4:
  1860. if(!$val['answer']){
  1861. $customConfig['errorTypeSetting']['hasGoodKnowledge']=true;
  1862. }elseif($val['answer']=='A'){
  1863. $customConfig['errorTypeSetting']['hasGoodKnowledge']=true;
  1864. }else{
  1865. $customConfig['errorTypeSetting']['hasGoodKnowledge']=false;
  1866. }
  1867. break;
  1868. case 5:
  1869. if(!$val['answer']){
  1870. $customConfig['errorTypeSetting']['hasLoseKnowledge']=true;
  1871. }elseif($val['answer']=='A'){
  1872. $customConfig['errorTypeSetting']['hasLoseKnowledge']=true;
  1873. }else{
  1874. $customConfig['errorTypeSetting']['hasLoseKnowledge']=false;
  1875. }
  1876. break;
  1877. case 6:
  1878. if(!$val['answer']){
  1879. $customConfig['errorTypeSetting']['hasScoreDetail']=true;
  1880. }elseif($val['answer']=='A'){
  1881. $customConfig['errorTypeSetting']['hasScoreDetail']=true;
  1882. }else{
  1883. $customConfig['errorTypeSetting']['hasScoreDetail']=false;
  1884. }
  1885. break;
  1886. case 7: //考试难度小贴士
  1887. if(!$val['answer']){
  1888. $customConfig['errorTypeSetting']['examinationDifficulty']=true;
  1889. }elseif($val['answer']=='A'){
  1890. $customConfig['errorTypeSetting']['examinationDifficulty']=true;
  1891. }else{
  1892. $customConfig['errorTypeSetting']['examinationDifficulty']=false;
  1893. }
  1894. break;
  1895. case 8: //考点视频二维码
  1896. if(!$val['answer']){
  1897. $customConfig['errorTypeSetting']['testVideo']=true;
  1898. }elseif($val['answer']=='A'){
  1899. $customConfig['errorTypeSetting']['testVideo']=true;
  1900. }else{
  1901. $customConfig['errorTypeSetting']['testVideo']=false;
  1902. }
  1903. break;
  1904. case 9: //考点高考分值表
  1905. if(!$val['answer']){
  1906. $customConfig['errorTypeSetting']['scoreOfCollege']=true;
  1907. }elseif($val['answer']=='A'){
  1908. $customConfig['errorTypeSetting']['scoreOfCollege']=true;
  1909. }else{
  1910. $customConfig['errorTypeSetting']['scoreOfCollege']=false;
  1911. }
  1912. break;
  1913. case 10: //同学优解
  1914. if(!$val['answer']){
  1915. $customConfig['errorTypeSetting']['classmateOptimization']=true;
  1916. }elseif($val['answer']=='A'){
  1917. $customConfig['errorTypeSetting']['classmateOptimization']=true;
  1918. }else{
  1919. $customConfig['errorTypeSetting']['classmateOptimization']=false;
  1920. }
  1921. break;
  1922. case 11:
  1923. if(!$val['answer']){
  1924. $customConfig['errorTypeSetting']['hasErrorOriginNote']=true;
  1925. }elseif($val['answer']=='A'){
  1926. $customConfig['errorTypeSetting']['hasErrorOriginNote']=true;
  1927. }else{
  1928. $customConfig['errorTypeSetting']['hasErrorOriginNote']=false;
  1929. }
  1930. break;
  1931. case 12:
  1932. if(!$val['answer']){
  1933. $customConfig['errorTypeSetting']['hasTrainTypesetting']=true;
  1934. }elseif($val['answer']=='A'){
  1935. $customConfig['errorTypeSetting']['hasTrainTypesetting']=true;
  1936. }else{
  1937. $customConfig['errorTypeSetting']['hasTrainTypesetting']=false;
  1938. }
  1939. break;
  1940. case 13:
  1941. if(!$val['answer']){
  1942. $customConfig['errorTypeSetting']['hasDividePage']=true;
  1943. }elseif($val['answer']=='A'){
  1944. $customConfig['errorTypeSetting']['hasDividePage']=true;
  1945. }else{
  1946. $customConfig['errorTypeSetting']['hasDividePage']=false;
  1947. }
  1948. break;
  1949. case 14: //两步错题答案解析不展示
  1950. if(!$val['answer']){
  1951. $customConfig['errorTypeSetting']['hasWrongAnswer']=true;
  1952. }elseif($val['answer']=='A'){
  1953. $customConfig['errorTypeSetting']['hasWrongAnswer']=true;
  1954. }else{
  1955. $customConfig['errorTypeSetting']['hasWrongAnswer']=false;
  1956. }
  1957. break;
  1958. case 15: //错题是否显示在最后
  1959. if(!$val['answer']){
  1960. $customConfig['errorTypeSetting']['isWrongAnswerEnd']=true;
  1961. }elseif($val['answer']=='A'){
  1962. $customConfig['errorTypeSetting']['isWrongAnswerEnd']=true;
  1963. }else{
  1964. $customConfig['errorTypeSetting']['isWrongAnswerEnd']=false;
  1965. }
  1966. break;
  1967. case 16: //共性问题
  1968. if(!$val['answer']){
  1969. $customConfig['errorTypeSetting']['commonProblems']=true;
  1970. }elseif($val['answer']=='A'){
  1971. $customConfig['errorTypeSetting']['commonProblems']=true;
  1972. }else{
  1973. $customConfig['errorTypeSetting']['commonProblems']=false;
  1974. }
  1975. break;
  1976. case 17:
  1977. if(isset($errorPushDetailValue[15][$val['answer']])){
  1978. $errorPushDetail['select'][]=$errorPushDetailValue[15][$val['answer']];
  1979. }else{
  1980. $errorPushDetail['select']=array('pushLose');
  1981. }
  1982. break;
  1983. case 18:
  1984. if(isset($errorPushDetailValue[16][$val['answer']])){
  1985. $errorPushDetail['fillInBlank'][]=$errorPushDetailValue[16][$val['answer']];
  1986. }else{
  1987. $errorPushDetail['fillInBlank'][]=$errorPushDetailValue[16]['A'];
  1988. }
  1989. break;
  1990. case 19:
  1991. if(isset($errorPushDetailValue[17][$val['answer']])){
  1992. $errorPushDetail['answer'][]=$errorPushDetailValue[17][$val['answer']];
  1993. }else{
  1994. $errorPushDetail['answer'][]=$errorPushDetailValue[17]['A'];;
  1995. }
  1996. break;
  1997. case 20:
  1998. if(isset($errorPushDetailValue[18][$val['answer']])){
  1999. $errorPushDetail['chooseAnswer'][]=$errorPushDetailValue[18][$val['answer']];
  2000. }else{
  2001. $errorPushDetail['chooseAnswer'][]=$errorPushDetailValue[18]['A'];;
  2002. }
  2003. break;
  2004. case 21:
  2005. $values=array();
  2006. if($val['answer']){
  2007. $options=explode(',',$val['answer']);
  2008. if($options){
  2009. foreach ($options as $v){
  2010. if(isset($errorPushDetailValue[19][$v])){
  2011. $values[]=$errorPushDetailValue[19][$v];
  2012. }
  2013. }
  2014. }
  2015. }
  2016. if(!$values){
  2017. $values[]=$errorPushDetailValue[19]['D'];
  2018. }
  2019. $errorPushDetail['difficulty']=$values;
  2020. break;
  2021. case 22:
  2022. if(isset($trainPushDetailValue[20][$val['answer']])){
  2023. $pushDifficulty=$trainPushDetailValue[20][$val['answer']];
  2024. }else{
  2025. $pushDifficulty=$trainPushDetailValue[20]['A'];
  2026. }
  2027. break;
  2028. case 23:
  2029. if(isset($trainPushDetailValue[21][$val['answer']])){
  2030. $trainPushDetail['pushNumber']['select']=$trainPushDetailValue[21][$val['answer']];
  2031. }else{
  2032. $trainPushDetail['pushNumber']['select']=$trainPushDetailValue[21]['B'];
  2033. }
  2034. for($i=0;$i<$trainPushDetail['pushNumber']['select'];$i++){
  2035. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  2036. }
  2037. break;
  2038. case 24:
  2039. if(isset($trainPushDetailValue[21][$val['answer']])){
  2040. $trainPushDetail['pushNumber']['fillInBlank']=$trainPushDetailValue[21][$val['answer']];
  2041. }else{
  2042. $trainPushDetail['pushNumber']['fillInBlank']=$trainPushDetailValue[21]['B'];
  2043. }
  2044. if($maxTopicNumber<$trainPushDetail['pushNumber']['fillInBlank']){
  2045. $maxTopicNumber=$trainPushDetail['pushNumber']['fillInBlank'];
  2046. }
  2047. if(isset($trainPushDetail['pushDifficulty']['select']) && count($trainPushDetail['pushDifficulty']['select'])<$trainPushDetail['pushNumber']['fillInBlank']){
  2048. $trainPushDetail['pushDifficulty']['select']=array();
  2049. for($i=0;$i<$trainPushDetail['pushNumber']['fillInBlank'];$i++){
  2050. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  2051. }
  2052. }
  2053. break;
  2054. case 25:
  2055. if(isset($trainPushDetailValue[21][$val['answer']])){
  2056. $trainPushDetail['pushNumber']['answer']=$trainPushDetailValue[21][$val['answer']];
  2057. }else{
  2058. $trainPushDetail['pushNumber']['answer']=$trainPushDetailValue[21]['B'];
  2059. }
  2060. if(isset($trainPushDetail['pushDifficulty']['select']) && count($trainPushDetail['pushDifficulty']['select'])<$trainPushDetail['pushNumber']['answer']){
  2061. $trainPushDetail['pushDifficulty']['select']=array();
  2062. for($i=0;$i<$trainPushDetail['pushNumber']['answer'];$i++){
  2063. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  2064. }
  2065. }
  2066. break;
  2067. case 26:
  2068. if(isset($trainPushDetailValue[21][$val['answer']])){
  2069. $trainPushDetail['pushNumber']['chooseAnswer']=$trainPushDetailValue[21][$val['answer']];
  2070. }else{
  2071. $trainPushDetail['pushNumber']['chooseAnswer']=$trainPushDetailValue[21]['B'];
  2072. }
  2073. if(isset($trainPushDetail['pushDifficulty']['select']) && count($trainPushDetail['pushDifficulty']['select'])<$trainPushDetail['pushNumber']['chooseAnswer']){
  2074. $trainPushDetail['pushDifficulty']['select']=array();
  2075. for($i=0;$i<$trainPushDetail['pushNumber']['chooseAnswer'];$i++){
  2076. $trainPushDetail['pushDifficulty']['select'][]=$pushDifficulty;
  2077. }
  2078. }
  2079. break;
  2080. case 27:
  2081. if(!$val['answer']){
  2082. $customConfig['errorTypeSetting']['pushQuestionUpgrade']=true;
  2083. }elseif($val['answer']=='A'){
  2084. $customConfig['errorTypeSetting']['pushQuestionUpgrade']=true;
  2085. }else{
  2086. $customConfig['errorTypeSetting']['pushQuestionUpgrade']=false;
  2087. }
  2088. break;
  2089. default:
  2090. $this->output(1, "上传题目数量错误");
  2091. }
  2092. }
  2093. }
  2094. $customConfig['studentLevelDivide']['levelDetails'][0]['errorPushDetail']=$errorPushDetail;
  2095. $customConfig['studentLevelDivide']['levelDetails'][0]['trainPushDetail']=$trainPushDetail;
  2096. $this->sConn->createCommand("update product_student_set set use_custom=1,custom_config_json='".json_encode($customConfig)."' where student_id='{$studentId}' and semester_id='{$this->semesterId}' and subject_id='{$subject_id}' and is_beta={$isBeta}")->execute();
  2097. echo json_encode(array('status'=>1,'msg'=>'修改成功 '));exit;
  2098. }
  2099. //修改英语自选卡
  2100. public function actionSaveEnglishOptionalCard(){
  2101. $subject=isset($_POST["subject"])?$_POST["subject"]:'';
  2102. $student_id=isset($_POST["studentId"])?$_POST["studentId"]:'';
  2103. $json=isset($_POST["json"])?$_POST["json"]:'';
  2104. $subject_id=$this->subjectId;
  2105. if(!$student_id){
  2106. $this->output(0, "学生ID不能为空");
  2107. }
  2108. if(!$json){
  2109. $this->output(0, "学生勾选数据不能为空");
  2110. }
  2111. if($subject!=8){
  2112. $this->output(0, "科目错误 ");
  2113. }
  2114. $studentImg=isset($_POST["studentImg"])?$_POST["studentImg"]:'';
  2115. $file['src']=$studentImg;
  2116. //json数据转换
  2117. $jsonData=@json_decode($json,true);
  2118. if(!$jsonData){
  2119. $this->output(0, "数据格式错误");
  2120. }
  2121. $customConfig=array(
  2122. 'moduleName'=>'个性化学习宝',
  2123. 'moduleType'=>'english_3',
  2124. 'setting'=>array(
  2125. 'achievementAnalysisAndGoalSetting' =>1, //成长轨迹
  2126. 'analyzeAndFindTheCause' =>1, //阶段小结
  2127. 'readingTrainingLevel' =>array( //阅读训练分等级
  2128. 'questionTypeScore' =>1, //题型得分表
  2129. 'analysisOfWrongQuestions' =>1 //错分析表
  2130. ),
  2131. 'scoringTraining' =>array( //提分训练
  2132. 'scoreRaisingTraining' =>1, //提分训练
  2133. 'errorAnalysis' =>1, //错因分析
  2134. 'vocabularyAccumulation' =>1, //词汇积累
  2135. 'syntacticAnalysis' =>1, //句法剖析
  2136. 'skillInspiration' =>1, //技巧点拨
  2137. 'readingLevelDescription' =>1, //阅读等级说明
  2138. 'compositionDisplay' =>1, //作文展示
  2139. 'thinkingOfExamination' =>1, //审题思路
  2140. 'standardModelText' =>1, //标准范文
  2141. 'modelTextHighlights' =>1, //范文亮点
  2142. 'writingTemplate' =>1, //写作模板
  2143. ),
  2144. 'variantTrainingOfCommonProblems' =>1, //共性问题变式训练
  2145. 'numberOfWrongQuestions' =>array( //错题数量
  2146. //考后复习部分设置
  2147. 'scoringTraining' =>array(
  2148. 'readingComprehension' =>'1', //阅读理解 1配1,2配2
  2149. 'taskBasedReading' =>1, //短文改错1,2,3==>任务型阅读
  2150. 'sevenChooseFive' =>1, //七选五1,2,3
  2151. 'gestaltFilling' =>'1', //完形填空 1配1,2配2
  2152. 'grammaticalFillIn' =>'1', //语法填空
  2153. 'vocabularyApplication' =>1, //词汇运用
  2154. 'variantTraining' =>1, //变式训练
  2155. ),
  2156. )
  2157. )
  2158. );
  2159. $answer19=array(
  2160. 'A'=>'3',
  2161. 'B'=>'6',
  2162. 'C'=>'10',
  2163. 'D'=>'0'
  2164. );
  2165. $answer20=array(
  2166. 'A'=>'1',
  2167. 'B'=>'2',
  2168. 'C'=>'3',
  2169. 'D'=>'0'
  2170. );
  2171. if(count($jsonData)!=21){
  2172. $this->output(0, "配置参数数量不正确");
  2173. }
  2174. foreach ($jsonData as $key => $val){
  2175. switch ($val['questionNum']){
  2176. case 1: //成长轨迹
  2177. if(!$val['answer']){
  2178. $customConfig['setting']['achievementAnalysisAndGoalSetting']=1;
  2179. }elseif($val['answer']=='A'){
  2180. $customConfig['setting']['achievementAnalysisAndGoalSetting']=1;
  2181. }else{
  2182. $customConfig['setting']['achievementAnalysisAndGoalSetting']=0;
  2183. }
  2184. break;
  2185. case 2://阶段小结
  2186. if(!$val['answer']){
  2187. $customConfig['setting']['analyzeAndFindTheCause']=1;
  2188. }elseif($val['answer']=='A'){
  2189. $customConfig['setting']['analyzeAndFindTheCause']=1;
  2190. }else{
  2191. $customConfig['setting']['analyzeAndFindTheCause']=0;
  2192. }
  2193. break;
  2194. case 3://题型得分表
  2195. if(!$val['answer']){
  2196. $customConfig['setting']['readingTrainingLevel']['questionTypeScore']=1;
  2197. }elseif($val['answer']=='A'){
  2198. $customConfig['setting']['readingTrainingLevel']['questionTypeScore']=1;
  2199. $customConfig['setting']['readingTrainingLevel']['analysisOfWrongQuestions']=1;
  2200. }else{
  2201. $customConfig['setting']['readingTrainingLevel']['questionTypeScore']=0;
  2202. $customConfig['setting']['readingTrainingLevel']['analysisOfWrongQuestions']=0;
  2203. }
  2204. break;
  2205. case 4://错题分析表
  2206. if(!$val['answer']){
  2207. $customConfig['setting']['readingTrainingLevel']['analysisOfWrongQuestions']=1;//错题分析表
  2208. }elseif($val['answer']=='A'){
  2209. $customConfig['setting']['readingTrainingLevel']['analysisOfWrongQuestions']=1;//错题分析表
  2210. }else{
  2211. $customConfig['setting']['readingTrainingLevel']['analysisOfWrongQuestions']=0;//错题分析表
  2212. }
  2213. break;
  2214. case 5://提分训练
  2215. if(!$val['answer']){
  2216. $customConfig['setting']['scoringTraining']['scoreRaisingTraining']=1;
  2217. }elseif($val['answer']=='A'){
  2218. $customConfig['setting']['scoringTraining']['scoreRaisingTraining']=1;
  2219. }else{
  2220. $customConfig['setting']['scoringTraining']['scoreRaisingTraining']=0;
  2221. }
  2222. break;
  2223. case 6://错因分析
  2224. if(!$val['answer']){
  2225. $customConfig['setting']['scoringTraining']['errorAnalysis']=1;
  2226. }elseif($val['answer']=='A'){
  2227. $customConfig['setting']['scoringTraining']['errorAnalysis']=1;
  2228. }else{
  2229. $customConfig['setting']['scoringTraining']['errorAnalysis']=0;
  2230. }
  2231. break;
  2232. case 7://词汇积累
  2233. if(!$val['answer']){
  2234. $customConfig['setting']['scoringTraining']['vocabularyAccumulation']=1;
  2235. }elseif($val['answer']=='A'){
  2236. $customConfig['setting']['scoringTraining']['vocabularyAccumulation']=1;
  2237. }else{
  2238. $customConfig['setting']['scoringTraining']['vocabularyAccumulation']=0;
  2239. }
  2240. break;
  2241. case 8: //句法剖析
  2242. if(!$val['answer']){
  2243. $customConfig['setting']['scoringTraining']['syntacticAnalysis']=1;
  2244. }elseif($val['answer']=='A'){
  2245. $customConfig['setting']['scoringTraining']['syntacticAnalysis']=1;
  2246. }else{
  2247. $customConfig['setting']['scoringTraining']['syntacticAnalysis']=0;
  2248. }
  2249. break;
  2250. case 9: //技巧点拨
  2251. if(!$val['answer']){
  2252. $customConfig['setting']['scoringTraining']['skillInspiration']=1;
  2253. }elseif($val['answer']=='A'){
  2254. $customConfig['setting']['scoringTraining']['skillInspiration']=1;
  2255. }else{
  2256. $customConfig['setting']['scoringTraining']['skillInspiration']=0;
  2257. }
  2258. break;
  2259. case 10://阅读等级说明
  2260. if(!$val['answer']){
  2261. $customConfig['setting']['scoringTraining']['readingLevelDescription']=1;
  2262. }elseif($val['answer']=='A'){
  2263. $customConfig['setting']['scoringTraining']['readingLevelDescription']=1;
  2264. }else{
  2265. $customConfig['setting']['scoringTraining']['readingLevelDescription']=0;
  2266. }
  2267. break;
  2268. case 11://作文展示
  2269. if(!$val['answer']){
  2270. $customConfig['setting']['scoringTraining']['compositionDisplay']=1;
  2271. }elseif($val['answer']=='A'){
  2272. $customConfig['setting']['scoringTraining']['compositionDisplay']=1;
  2273. }else{
  2274. $customConfig['setting']['scoringTraining']['compositionDisplay']=0;
  2275. }
  2276. break;
  2277. case 12: //审题思路
  2278. if(!$val['answer']){
  2279. $customConfig['setting']['scoringTraining']['thinkingOfExamination']=1;
  2280. }elseif($val['answer']=='A'){
  2281. $customConfig['setting']['scoringTraining']['thinkingOfExamination']=1;
  2282. }else{
  2283. $customConfig['setting']['scoringTraining']['thinkingOfExamination']=0;
  2284. }
  2285. break;
  2286. case 13://标准范文
  2287. if(!$val['answer']){
  2288. $customConfig['setting']['scoringTraining']['standardModelText']=1;
  2289. }elseif($val['answer']=='A'){
  2290. $customConfig['setting']['scoringTraining']['standardModelText']=1;
  2291. }else{
  2292. $customConfig['setting']['scoringTraining']['standardModelText']=0;
  2293. }
  2294. break;
  2295. case 14://范文亮点
  2296. if(!$val['answer']){
  2297. $customConfig['setting']['scoringTraining']['modelTextHighlights']=1;
  2298. }elseif($val['answer']=='A'){
  2299. $customConfig['setting']['scoringTraining']['modelTextHighlights']=1;
  2300. }else{
  2301. $customConfig['setting']['scoringTraining']['modelTextHighlights']=0;
  2302. }
  2303. break;
  2304. case 15://写作模板
  2305. if(!$val['answer']){
  2306. $customConfig['setting']['scoringTraining']['writingTemplate']=1;
  2307. }elseif($val['answer']=='A'){
  2308. $customConfig['setting']['scoringTraining']['writingTemplate']=1;
  2309. }else{
  2310. $customConfig['setting']['scoringTraining']['writingTemplate']=0;
  2311. }
  2312. break;
  2313. case 16://共性问题变式训练
  2314. if(!$val['answer']){
  2315. $customConfig['setting']['variantTrainingOfCommonProblems']=1;
  2316. }elseif($val['answer']=='A'){
  2317. $customConfig['setting']['variantTrainingOfCommonProblems']=1;
  2318. }else{
  2319. $customConfig['setting']['variantTrainingOfCommonProblems']=0;
  2320. }
  2321. break;
  2322. case 17://词汇运用
  2323. if(!$val['answer'] && isset($answer19[$val['answer']])){
  2324. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['vocabularyApplication']=$answer19[$val['answer']];
  2325. }else{
  2326. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['vocabularyApplication']=0;
  2327. }
  2328. break;
  2329. case 18://阅读理解
  2330. if(!$val['answer'] && isset($answer20[$val['answer']])){
  2331. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['readingComprehension']=$answer20[$val['answer']];
  2332. }else{
  2333. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['readingComprehension']=0;
  2334. }
  2335. break;
  2336. case 19://完形填空
  2337. if(!$val['answer'] && isset($answer20[$val['answer']])){
  2338. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['gestaltFilling']=$answer20[$val['answer']];
  2339. }else{
  2340. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['gestaltFilling']=0;
  2341. }
  2342. break;
  2343. case 20://七选五
  2344. if(!$val['answer'] && isset($answer20[$val['answer']])){
  2345. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['sevenChooseFive']=$answer20[$val['answer']];
  2346. }else{
  2347. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['sevenChooseFive']=0;
  2348. }
  2349. break;
  2350. case 21://语法填空
  2351. if(!$val['answer'] && isset($answer20[$val['answer']])){
  2352. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['grammaticalFillIn']=$answer20[$val['answer']];
  2353. }else{
  2354. $customConfig['setting']['numberOfWrongQuestions']['scoringTraining']['grammaticalFillIn']=0;
  2355. }
  2356. break;
  2357. default:
  2358. $this->output(1, "上传题目数量错误");
  2359. }
  2360. }
  2361. $this->sConn->createCommand("update product_student_set set use_custom=1,custom_config_json='".json_encode($customConfig)."' where student_id='{$student_id}' and semester_id='{$this->semesterId}' and subject_id='{$subject_id}'")->execute();
  2362. echo json_encode(array('status'=>1,'msg'=>'修改成功 '));exit;
  2363. }
  2364. //切换学科
  2365. public function actionChangeSubject(){
  2366. $subjectId=Req::post('subjectId')?Req::post('subjectId'):0;
  2367. if(!$subjectId){
  2368. echo json_encode(array('status'=>0,'msg'=>'学科不正确 '));exit;
  2369. }else{
  2370. Yii::app()->session['session_duoxueke_subject_id'] = $subjectId;
  2371. Yii::app()->session['session_subject_id'] = $subjectId;
  2372. echo json_encode(array('status'=>1));exit;
  2373. }
  2374. }
  2375. //获取当前学科
  2376. function actionGetSubject(){
  2377. // echo json_encode($_SESSION);exit;
  2378. // echo $_SESSION['session_duoxueke_subject_id'];exit;
  2379. $subjectId = Yii::app()->session['session_duoxueke_subject_id'];
  2380. echo $subjectId;exit;
  2381. }
  2382. //初始化产品设置
  2383. public function actionInitProductSetting(){
  2384. $subjectId = Yii::app()->session['session_duoxueke_subject_id'];
  2385. if($subjectId == 12 || in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2386. $this->initTemplate3();
  2387. echo json_encode(array('status'=>1));exit;
  2388. }else{
  2389. echo json_encode(array('status'=>0,'msg'=>'学科错误'));exit;
  2390. }
  2391. echo json_encode(array('status'=>1));exit;
  2392. }
  2393. /**
  2394. *
  2395. */
  2396. //教师教案班级列表
  2397. public function actionTeachingList(){
  2398. $ttModel = new TeachingTemplate();
  2399. $teacherId = Req::post('teacher_id')?(string)Req::post('teacher_id'):''; //接口传的教师ID
  2400. $grade = Req::post('grade')?intval(Req::post('grade')):0; //接口传的年级
  2401. $classId = Req::post('class_id')?(string)Req::post('class_id'):''; //接口传的班级ID
  2402. $limit = Req::post('limit')?intval(Req::post('limit')):15; //接口传的每页显示条数
  2403. $page = Req::post('page')?intval(Req::post('page')):1; //接口传的当前页
  2404. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2405. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2406. $subjectId = 3;
  2407. }
  2408. if($subjectId != 3){
  2409. echo json_encode(array('status'=>0,'msg'=>'学科错误'));exit;
  2410. }
  2411. if($subjectId == 3){
  2412. $json = '{"common":1,"common_wrong":1,"paper":1,"paper_wrong":1,"real_topic":1,"classmateOptimization":1}';
  2413. $status = $ttModel->initTemplate($subjectId,$json,'班级默认模板');
  2414. if(!$status){
  2415. echo json_encode(array('status'=>0,'msg'=>'初始化模板失败'));exit;
  2416. }
  2417. }
  2418. $list = $ttModel->listTemplate($subjectId,$teacherId,$grade,$classId,$limit,$page);
  2419. echo json_encode(array('status'=>1,'data'=>$list));exit;
  2420. }
  2421. //教师讲案搜索教师
  2422. public function actionTeachingSearchTeacher(){
  2423. $ttModel = new TeachingTemplate();
  2424. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2425. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2426. $subjectId = 3;
  2427. }
  2428. $list = $ttModel->teacherList($subjectId);
  2429. echo json_encode(array('status'=>1,'data'=>$list));exit;
  2430. }
  2431. //教师讲案编辑保存
  2432. public function actionTeachingEdit(){
  2433. $ttModel = new TeachingTemplate();
  2434. $classId = Req::post('class_id')?Req::post('class_id'):''; //接口传的班级ID
  2435. if(!$classId){
  2436. echo json_encode(array('status'=>0,'msg'=>'班级ID不正确'));exit;
  2437. }else{
  2438. $classIdArr = explode(",",$classId);
  2439. }
  2440. $templateId = Req::post('template_id')?intval(Req::post('template_id')):0; //接口传的模板ID
  2441. if(!$templateId){
  2442. echo json_encode(array('status'=>0,'msg'=>'模板ID不正确'));exit;
  2443. }
  2444. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2445. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2446. $subjectId = 3;
  2447. }
  2448. $status = $ttModel->editTemplate($classIdArr,$subjectId,$templateId);
  2449. if($status){
  2450. echo json_encode(array('status'=>1));exit;
  2451. }else{
  2452. echo json_encode(array('status'=>0,'msg'=>'保存失败'));exit;
  2453. }
  2454. }
  2455. //教师讲案恢复默认
  2456. public function actionTeachingRestoreClass(){
  2457. $ttModel = new TeachingTemplate();
  2458. $classId = Req::post('class_id')?(string)Req::post('class_id'):''; //接口传的班级ID
  2459. if(!$classId){
  2460. echo json_encode(array('status'=>0,'msg'=>'班级ID不正确'));exit;
  2461. }
  2462. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2463. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2464. $subjectId = 3;
  2465. }
  2466. $status = $ttModel->restoreClassDefault($classId,$subjectId);
  2467. if($status){
  2468. echo json_encode(array('status'=>1));exit;
  2469. }else{
  2470. echo json_encode(array('status'=>0,'msg'=>'操作失败'));exit;
  2471. }
  2472. }
  2473. //教师讲案模板列表
  2474. public function actionTeachingTemplateList(){
  2475. $ttModel = new TeachingTemplate();
  2476. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2477. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2478. $subjectId = 3;
  2479. }
  2480. $list = $ttModel->getList($subjectId);
  2481. echo json_encode(array('status'=>1,'data'=>$list));exit;
  2482. }
  2483. //教师讲案模板详情
  2484. public function actionTeachingTemplateDetail(){
  2485. $ttModel = new TeachingTemplate();
  2486. $templateId = Req::post('template_id')?intval(Req::post('template_id')):0; //接口传的模板ID
  2487. if(!$templateId){
  2488. echo json_encode(array('status'=>0,'msg'=>'模板ID不正确'));exit;
  2489. }
  2490. $list = $ttModel->detailTemplate($templateId);
  2491. echo json_encode(array('status'=>1,'data'=>$list));exit;
  2492. }
  2493. //教师讲案模板设置保存
  2494. public function actionTeachingTemplateSave(){
  2495. $ttModel = new TeachingTemplate();
  2496. $templateId = Req::post('template_id')?intval(Req::post('template_id')):0; //接口传的模板ID
  2497. $json = Req::post('json')?(string)Req::post('json'):''; //接口传的设置
  2498. if(!$templateId){
  2499. echo json_encode(array('status'=>0,'msg'=>'模板ID不正确'));exit;
  2500. }
  2501. if(!$json){
  2502. echo json_encode(array('status'=>0,'msg'=>'设置参数不正确'));exit;
  2503. }else{
  2504. $json=str_replace('&quot;','"',$json);
  2505. }
  2506. $status = $ttModel->saveTemplate($templateId,$json);
  2507. if($status){
  2508. echo json_encode(array('status'=>1));exit;
  2509. }else{
  2510. echo json_encode(array('status'=>0,'msg'=>'保存失败'));exit;
  2511. }
  2512. }
  2513. //教师讲案模板改名
  2514. public function actionTeachingTemplateChangeName(){
  2515. $ttModel = new TeachingTemplate();
  2516. $templateId = Req::post('template_id')?intval(Req::post('template_id')):0; //接口传的模板ID
  2517. $templateName = Req::post('template_name')?(string)Req::post('template_name'):''; //接口传的模板名称
  2518. if(!$templateId){
  2519. echo json_encode(array('status'=>0,'msg'=>'模板ID不正确'));exit;
  2520. }
  2521. if(!$templateName){
  2522. echo json_encode(array('status'=>0,'msg'=>'模板名称不正确'));exit;
  2523. }
  2524. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2525. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2526. $subjectId = 3;
  2527. }
  2528. $status = $ttModel->changeName($templateId,$templateName,$subjectId);
  2529. if($status['status'] == 1){
  2530. echo json_encode(array('status'=>1));exit;
  2531. }else{
  2532. echo json_encode(array('status'=>0,'msg'=>$status['error']));exit;
  2533. }
  2534. }
  2535. //教师讲案模板删除
  2536. public function actionTeachingTemplateDel(){
  2537. $ttModel = new TeachingTemplate();
  2538. $templateId = Req::post('template_id')?intval(Req::post('template_id')):0; //接口传的模板ID
  2539. if(!$templateId){
  2540. echo json_encode(array('status'=>0,'msg'=>'模板ID不正确'));exit;
  2541. }
  2542. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2543. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2544. $subjectId = 3;
  2545. }
  2546. $status = $ttModel->delTemplate($templateId,$subjectId);
  2547. if($status['status'] == 1){
  2548. echo json_encode(array('status'=>1));exit;
  2549. }else{
  2550. echo json_encode(array('status'=>0,'msg'=>$status['error']));exit;
  2551. }
  2552. }
  2553. //教师讲案模板复制
  2554. public function actionTeachingTemplateCopy(){
  2555. $ttModel = new TeachingTemplate();
  2556. $templateId = Req::post('template_id')?intval(Req::post('template_id')):0; //接口传的模板ID
  2557. if(!$templateId){
  2558. echo json_encode(array('status'=>0,'msg'=>'模板ID不正确'));exit;
  2559. }
  2560. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2561. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2562. $subjectId = 3;
  2563. }
  2564. $error = $ttModel->copyTemplate($templateId,$subjectId);
  2565. if(!$error){
  2566. echo json_encode(array('status'=>1));exit;
  2567. }else{
  2568. echo json_encode(array('status'=>0,'msg'=>$error));exit;
  2569. }
  2570. }
  2571. /**
  2572. * 教师讲案跳转
  2573. */
  2574. public function actionTeachingIndex(){
  2575. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2576. //////新跳转规则////////
  2577. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2578. Header("Location: ".Yii::app()->params['product_setting_url']."index.html#/TeachSet/ClassList");
  2579. exit;
  2580. }else{
  2581. Yii::app()->jump->error('学科错误!');
  2582. }
  2583. }
  2584. /**
  2585. * 获取样式类型
  2586. */
  2587. public function actionGetStyleType()
  2588. {
  2589. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2590. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2591. $subjectId = 3;
  2592. }
  2593. $styleVersion = new SSubjectStyleVersion();
  2594. echo json_encode(array('status'=>1, 'data'=>array('style_type'=>$styleVersion->getStyleType($subjectId))));exit;
  2595. }
  2596. /**
  2597. * 样式类型切换
  2598. */
  2599. public function actionSwitchStyle()
  2600. {
  2601. $styleType = (int)Req::post('style_type');
  2602. $subjectId=Yii::app()->session['session_duoxueke_subject_id'];
  2603. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  2604. $subjectId = 3;
  2605. }
  2606. $count = SSubjectStyleVersion::model()->updateAll(array('style_type'=>$styleType, 'update_time'=>time()),'subject_id=:subject_id',array(':subject_id'=>$subjectId));
  2607. if($count>0){
  2608. echo json_encode(array('status'=>1,'msg'=>'更新成功'));exit;
  2609. }else{
  2610. echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit;
  2611. }
  2612. }
  2613. /**
  2614. * 是否是完整版词汇宝
  2615. * @return bool
  2616. */
  2617. public function isWholeMagic(){
  2618. $http = http('order/goods-type/open-time/'.$this->schoolId, 'GET', $this->authUsername);
  2619. $response = formatResponse($http);
  2620. return isset($response['data']) && !empty($response['data']) ? (strtotime($response['data'])<1653926400 ? true : false) : false;
  2621. }
  2622. /**
  2623. * 词汇宝模块恢复
  2624. */
  2625. public function actionResumeModule(){
  2626. $psId = (int)Req::get('ps_id');
  2627. $model = SProductSetting::model()->findByPk($psId);
  2628. $config = json_decode($model->custom_config, true);
  2629. $config['setting']['isWhole'] = 1;
  2630. SProductSetting::model()->updateByPk($psId, array('custom_config'=>json_encode($config, true)));
  2631. echo 1;exit;
  2632. }
  2633. }