OrderController.php 173 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090
  1. <?php
  2. class OrderController extends Controller{
  3. public function init(){
  4. if(!Yii::app()->params["order_open"]){
  5. echo "该模块尚未开放,敬请期待"; exit;
  6. }
  7. parent::init();
  8. }
  9. public function xiaoshu($num){
  10. if(is_numeric($num)){
  11. $num= explode(".", $num);
  12. if(!isset($num[1])){
  13. return $num[0].".00";
  14. }else{
  15. if(strlen($num[1])==1){
  16. return $num[0].".".$num[1]."0";
  17. }else{
  18. return $num[0].".".$num[1];
  19. }
  20. }
  21. }
  22. }
  23. public function actionIndex(){
  24. $class_id = safe_replace(Yii::app()->request->getParam('class_id'));
  25. $student_id = safe_replace(Yii::app()->request->getParam('student_id'));
  26. $status_old=$status = safe_replace(Yii::app()->request->getParam('status'));
  27. $semester_id = safe_replace(Yii::app()->request->getParam('semester_id'))?safe_replace(Yii::app()->request->getParam('semester_id')):$this->semesterId;
  28. $nianji = safe_replace(Yii::app()->request->getParam('nianji'))?safe_replace(Yii::app()->request->getParam('nianji')):-1;
  29. $from = safe_replace(Yii::app()->request->getParam('from'));
  30. $classify=0;
  31. $type= Yii::app()->request->getParam("type")?Yii::app()->request->getParam("type"):"ordinary";
  32. if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){
  33. Yii::app()->jump->error('参数不正确');
  34. }else{
  35. switch ($type){
  36. case "test":
  37. $classify=array(2,20);
  38. break;
  39. case "all":
  40. $classify=1;
  41. break;
  42. default :
  43. $classify=0;
  44. break;
  45. }
  46. }
  47. $data = array();
  48. $data['ordertype'] = $type;
  49. $order_ids = array();
  50. $class_array = array();
  51. if (Yii::app()->request->getParam('class_id')||Yii::app()->request->getParam('nianji') ||Yii::app()->request->getParam('semester_id') || (Yii::app()->request->getParam('class_id') && Yii::app()->request->getParam('student_id')) || safe_replace(Yii::app()->request->getParam('status'))|| safe_replace(Yii::app()->request->getParam('from')))
  52. {
  53. if($semester_id!=="-1"&&($class_id=="-1"||$class_id=="0")){//选了年级并且没选班级
  54. if($nianji=="-1"){
  55. $classs= ClassModel::model()->getClassBySemester($semester_id);
  56. }else{
  57. $classs= ClassModel::model()->getClassBySemesternianji($semester_id,$nianji);
  58. }
  59. if(!empty($classs)){
  60. $class_id=array();
  61. foreach($classs as $v){
  62. $class_id[]=$v['class_id'];
  63. }
  64. }else{
  65. $class_id=false;
  66. }
  67. }
  68. if($nianji!="-1"&&$class_id==="-1"){
  69. $classarr= ClassModel::model()->findAll("grade=:grade",array(":grade"=>$nianji));
  70. $class_id=array();
  71. foreach($classarr as $v){
  72. $class_id[]=$v['class_id'];
  73. }
  74. }
  75. if($class_id==="-1")
  76. {
  77. if($status==2)
  78. {
  79. $status ="0";
  80. }if($status==3)
  81. {
  82. $status ="2";
  83. }
  84. if($status==4)
  85. {
  86. $status ="3";
  87. }
  88. if($classify==0){
  89. $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,array(),$status,$from);
  90. }else{
  91. $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,array(),$status,-1);
  92. }
  93. if($order_data){
  94. foreach($order_data['result'] as $v)
  95. {
  96. $order_ids[$v['id']] = $v['id'];
  97. }
  98. }
  99. }
  100. else
  101. {
  102. // if(!is_array($class_id)&&$class_id){
  103. // if($type!="test"){
  104. // $order_student_data = CMSOrderStudent::model()->getOrderIDByClassId($class_id,$student_id);
  105. // }else{
  106. // $order_student_data = CMSOrderClazz::model()->getOrderIDByClassId($class_id);
  107. // }
  108. // }else if($class_id){
  109. if($class_id){
  110. if(!is_array($class_id)){
  111. $class_id=array($class_id);
  112. }
  113. if($type!="test"){
  114. $order_student_data = CMSOrderStudent::model()->getOrderIDInClassId($class_id,$student_id);
  115. }else{
  116. $class_ids="";
  117. foreach($class_id as $v){
  118. $class_ids.="'".$v."',";
  119. }
  120. $class_ids=substr($class_ids,0,strlen($class_ids)-1);
  121. $sql="select os.order_id from order_clazz as os join `order` as o on o.id=os.order_id where o.classify in (2,20) and os.clazz_id in (". $class_ids.")";
  122. $order_student_data_1=Yii::app()->db251->createCommand($sql)->queryAll();
  123. $sql="select os.order_id from order_student as os join `order` as o on o.id=os.order_id where o.classify in (2,20) and os.clazz_id in (". $class_ids.")";
  124. $order_student_data=Yii::app()->db251->createCommand($sql)->queryAll();
  125. if($order_student_data_1){
  126. $order_student_data= array_merge($order_student_data_1,$order_student_data);
  127. }
  128. }
  129. }else{
  130. $order_student_data=false;
  131. }
  132. if($order_student_data)
  133. {
  134. foreach($order_student_data as $v)
  135. { $v=(object)$v;
  136. $order_ids[$v->order_id] = $v->order_id;
  137. }
  138. }
  139. if($status=="2")
  140. {
  141. $status ="0";
  142. }if($status=="3")
  143. {
  144. $status ="2";
  145. }if($status==4)
  146. {
  147. $status ="3";
  148. }
  149. $student_data = StudentInfo::model()->getStudentInClassId($class_id);
  150. if($student_data)
  151. {
  152. $data['class_student'] = $student_data;
  153. }
  154. if($order_ids)
  155. {
  156. if($classify==0){
  157. $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,$order_ids,$status,$from);
  158. }else{
  159. $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,$order_ids,$status,-1);
  160. }
  161. }else
  162. {
  163. $order_data = array();
  164. }
  165. }
  166. if($status==2){
  167. $status=3;
  168. }
  169. $data['search'] = array(
  170. 'class_id' => Yii::app()->request->getParam('class_id'),
  171. 'student_id' => Yii::app()->request->getParam('student_id'),
  172. 'status' => $status_old,
  173. 'semester_id' => Yii::app()->request->getParam('semester_id'),
  174. 'nianji' => Yii::app()->request->getParam('nianji'),
  175. 'from' => Yii::app()->request->getParam('from'),
  176. );
  177. $data['student_name'] = StudentInfo::model()->getRealname(Yii::app()->request->getParam('student_id'));
  178. }else
  179. {
  180. $order_data = CMSOrder::model()->getPageList($this->schoolId,$classify);
  181. if($order_data)
  182. {
  183. foreach($order_data['result'] as $v)
  184. {
  185. $order_ids[$v->id] = $v->id;
  186. }
  187. }
  188. $data['search'] = array();
  189. }
  190. $work_flow_id="";
  191. if(isset($order_data['result'])){
  192. foreach($order_data['result'] as $v)
  193. { if($v->work_flow_id){
  194. $work_flow_id.=$v->work_flow_id.",";
  195. }
  196. }
  197. $work_flow_id=substr($work_flow_id,0,strlen($work_flow_id)-1);
  198. }
  199. if($work_flow_id){
  200. $sql="SELECT
  201. id
  202. FROM
  203. `order`
  204. WHERE
  205. work_flow_id IN (
  206. SELECT
  207. work_flow_id
  208. FROM
  209. work_flow_detail
  210. WHERE
  211. id IN (
  212. SELECT
  213. work_flow_detail_id
  214. FROM
  215. work_flow_user
  216. WHERE
  217. work_flow_detail_id IN (
  218. SELECT
  219. id
  220. FROM
  221. work_flow_detail
  222. WHERE
  223. work_flow_id IN ($work_flow_id)
  224. )
  225. )
  226. )";
  227. $isdel= Yii::app()->db251->createCommand($sql)->queryAll();
  228. $data['isdel'] =$isdel;
  229. }
  230. $data['return'] = $order_data;
  231. $order_goods_data = CMSOrderGoods::model()->getGoodsByOrderId($order_ids);
  232. if($order_goods_data)
  233. {
  234. foreach($order_goods_data as $v)
  235. {
  236. $data['goods'][$v->order_id]['gname'] = $v->goods_name;
  237. $data['goods'][$v->order_id]['grade'] = $v->grade;
  238. }
  239. }else
  240. {
  241. $data['goods'] = '';
  242. }
  243. if($type=="all"){
  244. $orderpay= CMSPayment::model()->getOrderPay($order_ids);
  245. foreach($orderpay as $k=>$v){
  246. $data['pay'][$v['order_id']][]=$v;
  247. }
  248. // var_dump($data['pay']);exit;
  249. $orderpay= CMSPayment::model()->getOrderPay($order_ids,-1);
  250. foreach($orderpay as $k=>$v){
  251. $data['paystatus'][$v['order_id']][]=$v;
  252. }
  253. }elseif($type=="test"){
  254. if($order_ids){
  255. $arr= Yii::app()->db251->createCommand("select COUNT(DISTINCT clazz_id )as num,sum(students) as stunum,order_id from order_clazz where order_id in (".implode(",", $order_ids).") group by order_id")->queryAll();
  256. $stunum=array();
  257. $classnum=array();
  258. if($arr){
  259. foreach($arr as $k=>$v){
  260. $classnum[$v['order_id']]=$v['num'];
  261. $stunum[$v['order_id']]=$v['stunum'];
  262. }
  263. }
  264. $sql="select count(DISTINCT clazz_id) as num,count(student_id) as stunum ,order_id from order_student where order_id in (".implode(",", $order_ids).") GROUP BY order_id";
  265. $arr= Yii::app()->db251->createCommand($sql)->queryAll();
  266. if($arr){
  267. foreach($arr as $k=>$v){
  268. $classnum[$v['order_id']]=$v['num'];
  269. $stunum[$v['order_id']]=$v['stunum'];
  270. }
  271. }
  272. $data['classnum']=$classnum;
  273. $data['stunum']=$stunum;
  274. }
  275. }else{
  276. $orderpay= CMSOrderPay::model()->getOrderPay($order_ids);
  277. foreach($orderpay as $k=>$v){
  278. $data['pay'][$v['order_id']]=$v;
  279. }
  280. }
  281. $data['semester']=array();
  282. $semester= Semester::model()->findAll();
  283. foreach($semester as $k=>$v){
  284. $data['semester'][$v['semester_id']]=$v;
  285. }
  286. //获取班级
  287. $class_data = ClassModel::model()->getClassBySemesternianji($semester_id,$nianji);
  288. $data['nowsemesterId']=$this->semesterId;
  289. if($class_data)
  290. {
  291. $data['classes'] = $class_data;
  292. foreach($class_data as $v)
  293. {
  294. $class_array[$v->class_id] = $v->class_name;
  295. }
  296. $data['class_name'] = $class_array;
  297. }
  298. if($type=='ordinary'){
  299. $this->render("index",$data);
  300. }elseif($type=="test"){
  301. $this->render("indextest",$data);
  302. }else{
  303. $this->render("indexall",$data);
  304. }
  305. }
  306. public function actionDelete(){
  307. $order_id = Yii::app()->request->getParam('order_id');
  308. $orderinfo=CMSOrder::model()->find("id=:id",array(":id"=>$order_id));
  309. if($orderinfo->type==0){
  310. Yii::app()->jump->error('非学管订单不能取消');
  311. }
  312. $sql="select wu.id from work_flow_user as wu LEFT JOIN work_flow_detail as wd on wu.work_flow_detail_id=wd.id LEFT JOIN `order` as o on o.work_flow_id=wd.work_flow_id where o.id=$order_id";
  313. $arr=Yii::app()->db251->createCommand($sql)->queryRow();
  314. if(empty($arr)){
  315. if($orderinfo->classify!=1){
  316. $num=CMSOrder::model()->updateAll(array("status"=>3),"id=:id",array(":id"=>$order_id));
  317. }else{
  318. $payarr= CMSPayment::model()->findAll("order_id=:id",array(":id"=>$order_id));
  319. if(count($payarr)>1){
  320. Yii::app()->jump->error('已有'.count($payarr)."期缴费,不能取消订单");
  321. }else{
  322. $payment_status="1_3";
  323. $num=CMSOrder::model()->updateAll(array("status"=>3,"payment_status"=>$payment_status),"id=:id",array(":id"=>$order_id));
  324. CMSPayment::model()->updateAll(array("status"=>3),"id=:id",array(":id"=>$payarr[0]->id));
  325. }
  326. }
  327. if($num>0){
  328. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  329. if(!$orders_id){
  330. Yii::app()->jump->error('接口错误');
  331. }
  332. $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  333. if($orderlogid=="-1"){
  334. Yii::app()->jump->error('logid获取失败,添加失败!');
  335. }
  336. $order_operate_log_odj = new CMSOrderOperateLog();
  337. $order_operate_log_odj->id =$orderlogid;
  338. $order_operate_log_odj->role_name = '学管';
  339. $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name'];
  340. $order_operate_log_odj->info = '取消了订单';
  341. $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time());
  342. $order_operate_log_odj->order_id = $order_id;
  343. $order_operate_log_odj->save();
  344. $this->redirect(Yii::app()->request->urlReferrer);
  345. }else{
  346. Yii::app()->jump->error('取消失败,系统错误');
  347. }
  348. }else{
  349. Yii::app()->jump->error('此订单已开始审核,不能取消');
  350. }
  351. }
  352. public function actionGetstudent_test(){
  353. $class_id = safe_replace(Yii::app()->request->getPost('class_id'));
  354. $goods_id = safe_replace(Yii::app()->request->getPost('goods_id'));
  355. $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_id));
  356. $good_type = $goods_data->type_id;
  357. if($class_id&&$good_type){
  358. $sql="SELECT
  359. oc.clazz_id
  360. FROM
  361. order_clazz AS oc
  362. JOIN `order` AS o ON o.id = oc.order_id
  363. JOIN order_goods AS og ON o.id = og.order_id
  364. WHERE
  365. oc.clazz_id = {$class_id}
  366. and og.goods_type_id={$good_type} and o.classify=2 and o.status=1 GROUP BY oc.clazz_id";
  367. $class=Yii::app()->db251->createCommand($sql)->queryAll();
  368. }else{
  369. echo json_encode(array('status'=>3));exit;
  370. }
  371. if(empty($class)){
  372. $oldclass=array();
  373. $sql="SELECT
  374. class_id
  375. FROM
  376. student_class_relation
  377. WHERE
  378. class_id != {$class_id}
  379. AND student_id IN (
  380. SELECT
  381. student_id
  382. FROM
  383. student_class_relation
  384. WHERE
  385. class_id = {$class_id}
  386. AND STATUS = 0
  387. )
  388. GROUP BY class_id";
  389. $oldclass=SStudentInfo::model()->findAllBySql($sql); //学生如果有转班的话获取转班前的班级
  390. $class_ids=array();
  391. foreach($oldclass as $v){
  392. $class_ids[]=$v['class_id'];
  393. }
  394. $class_ids[]=$class_id;
  395. if(count($class_ids)>1){
  396. $class_ids= implode(",", $class_ids);
  397. }else{
  398. $class_ids=$class_ids[0];
  399. }
  400. /**
  401. * 1、修改:
  402. * 背景 以前的试用订单的下单条件是每个学科每个商品每个学校的每个人只可以试用一次,由于2017~2018学年的销售策略变更,改为每个学期可以试用一次(每个学科每个商品每个学校每个人)。
  403. * 需求描述
  404. * 修改学管端下试用订单选择学生时的条件,如果本学期已经试用过则无法加入试用订单。
  405. * 开发时间:20180228
  406. * 作者:刘红伟
  407. * 2、再修改:
  408. *
  409. * 根据订单开始时间
  410. * 2018-03-06
  411. *
  412. * 3、再修改:
  413. * 增加多个赛时。
  414. *2018-03-06
  415. */
  416. //查当前班级所在学期
  417. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  418. if(!$class_data)
  419. {
  420. echo json_encode(array('status'=>3));exit;
  421. }
  422. //获取学期
  423. $semester_data = Semester::model()->find('semester_id=:semester_id',array(':semester_id'=>$class_data->semester_id));
  424. if(!$semester_data)
  425. {
  426. echo json_encode(array('status'=>3));exit;
  427. }
  428. $start_time = date('Y-m-d H:i:s',$semester_data->start_time);
  429. $end_time = date('Y-m-d H:i:s',$semester_data->end_time);
  430. if(Yii::app()->crm_login_cache->getValue('zsy_season_time_key')){
  431. $time = time();
  432. $season_time = json_decode(Yii::app()->crm_login_cache->getValue('zsy_season_time_key'),1);//获取redis赛时时间
  433. if($season_time)
  434. {
  435. foreach ($season_time as $v)
  436. {
  437. if($time>$v['startTime'] && $time<$v['endTime'])//比对赛时的时间
  438. {
  439. $start_time = date('Y-m-d H:i:s',$v['startTime']);
  440. $end_time = date('Y-m-d H:i:s',$v['endTime']);
  441. }
  442. }
  443. }
  444. }
  445. //查试用订单:根据学期的开始时间与结束时间
  446. $sql="SELECT
  447. os.clazz_id,
  448. os.student_id
  449. FROM
  450. order_student AS os
  451. left JOIN `order` AS o ON o.id = os.order_id
  452. left JOIN order_goods AS og ON o.id = og.order_id
  453. WHERE
  454. os.clazz_id in ({$class_ids})
  455. and og.goods_type_id={$good_type}
  456. and o.classify=20
  457. and o.status in (0,1)
  458. and o.trial_begin_time >= '".$start_time."'
  459. and o.trial_begin_time <= '".$end_time."'
  460. GROUP BY os.student_id";//去除转班来的学生.......
  461. $orderstu=Yii::app()->db251->createCommand($sql)->queryAll();
  462. $orderstuids=array();
  463. foreach($orderstu as $v){
  464. $orderstuids[$v['student_id']]=$v['student_id'];
  465. }
  466. $sql="SELECT
  467. s.realname,
  468. s.student_id
  469. FROM
  470. student_info AS s
  471. JOIN student_class_relation AS scr ON s.student_id = scr.student_id
  472. WHERE
  473. scr.class_id = {$class_id}
  474. and scr.`status`=0";
  475. $stu=SStudentInfo::model()->findAllBySql($sql);
  476. $student_ids=array();
  477. foreach($stu as $v)
  478. {
  479. $student_ids[$v->student_id] = $v->student_id;
  480. }
  481. $BStudent_model=new BusinessStudent();
  482. $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId);
  483. $stu=array();
  484. if($student_ids){
  485. $sql="SELECT
  486. s.realname,
  487. s.student_id
  488. FROM
  489. student_info AS s
  490. JOIN student_class_relation AS scr ON s.student_id = scr.student_id
  491. WHERE
  492. scr.class_id = {$class_id}
  493. and s.student_id in (". implode(",", $student_ids).")
  494. and scr.`status`=0";
  495. $stu=SStudentInfo::model()->findAllBySql($sql);
  496. }
  497. $stuinfo=array();
  498. $orderstu=array();
  499. foreach($stu as $k=>$v){
  500. $student_ids[]=$v['student_id'];
  501. }
  502. $BStudent_model=new BusinessStudent();
  503. $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId);
  504. if($student_ids){
  505. $sql="SELECT
  506. s.realname,
  507. s.student_id
  508. FROM
  509. student_info AS s
  510. JOIN student_class_relation AS scr ON s.student_id = scr.student_id
  511. WHERE
  512. scr.class_id = {$class_id} and scr.student_id in (". implode(",", $student_ids).")
  513. and scr.`status`=0";
  514. $stuinfo=array();
  515. $orderstu=array();
  516. foreach($stu as $k=>$v){
  517. if(!isset($orderstuids[$v->student_id])){
  518. $stuinfo[$k]['student_id']=$v['student_id'];
  519. $stuinfo[$k]['realname']=$v['realname'];
  520. }else{
  521. $orderstu[$k]['student_id']=$v['student_id'];
  522. $orderstu[$k]['realname']=$v['realname'];
  523. }
  524. }
  525. echo json_encode(array('status'=>0,'result'=>$stuinfo,"orderstu"=>array()));exit;
  526. }else{
  527. echo json_encode(array('status'=>3));exit;
  528. }
  529. }else{
  530. $stu= SStudentInfo::model()->findAll("class_id=:class_id ",array(":class_id"=>$class_id));
  531. $student_ids=array();
  532. foreach($stu as $k=>$v){
  533. $student_ids[]=$v['student_id'];
  534. }
  535. $BStudent_model=new BusinessStudent();
  536. $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId);
  537. $student_id=array();
  538. foreach($student_ids as $v){
  539. $student_id[$v]=$v;
  540. }
  541. $orderstu=array();
  542. foreach($stu as $k=>$v){
  543. if(isset($student_id[$v->student_id])){
  544. $orderstu[$k]['student_id']=$v->student_id;
  545. $orderstu[$k]['realname']=$v->realname;
  546. }
  547. }
  548. echo json_encode(array('status'=>0,'result'=>array(),"orderstu"=>array()));exit;
  549. }
  550. }
  551. public function actionGetstudent()
  552. {
  553. $data = array();
  554. $orderid = safe_replace(Yii::app()->request->getPost('orderid'));
  555. $class_id = safe_replace(Yii::app()->request->getPost('class_id'));
  556. $goods_id = safe_replace(Yii::app()->request->getPost('goods_id'));
  557. $student_ids = array();
  558. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  559. $student_data = array();
  560. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>0));
  561. if($student_class_data)
  562. {
  563. foreach($student_class_data as $v)
  564. {
  565. $student_ids[$v->student_id] = $v->student_id;
  566. }
  567. }
  568. $where="";
  569. if($student_ids){
  570. $where =" and os.student_id in (".implode(",", $student_ids).")";
  571. $student_ids=array();
  572. }
  573. $today=date("Y-m-d H:i:s");
  574. $semester=new SSemester();
  575. $nowsem=$semester->getCurrentSemester();
  576. $sql="SELECT
  577. os.student_name,
  578. os.student_id
  579. FROM
  580. `order` AS o
  581. JOIN order_goods AS og ON o.id = og.order_id
  582. JOIN order_student AS os ON o.id = os.order_id
  583. left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id
  584. WHERE
  585. og.goods_id={$goods_id}
  586. and o.status in (0,1)
  587. {$where} and os.chargeback=0 AND (
  588. (
  589. o.trial_end_time > '{$today}'
  590. OR ogs.`code` = '{$nowsem['refer_code']}'
  591. )
  592. AND o.id NOT IN (
  593. SELECT
  594. business_key
  595. FROM
  596. zsy_service
  597. WHERE
  598. STATUS = 1
  599. )
  600. )";
  601. $order_stuid=Yii::app()->db251->createCommand($sql)->queryAll();
  602. $order_stuids=array();
  603. foreach($order_stuid as $v){
  604. $order_stuids[]=$v['student_id'];
  605. }
  606. if(!empty($order_stuids)){
  607. $student_class_data = SStudentClassRelation::model()->findAll(' student_id not in ('.implode(",",$order_stuids).') and class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>0));
  608. }else{
  609. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>0));
  610. }
  611. if($student_class_data)
  612. {
  613. foreach($student_class_data as $v)
  614. {
  615. $student_ids[$v->student_id] = $v->student_id;
  616. }
  617. $BStudent_model=new BusinessStudent();
  618. $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId);
  619. $BStudent_model=new BusinessStudent();
  620. $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId);
  621. $criteria = new CDbCriteria();
  622. $criteria->addInCondition('student_id',$student_ids);
  623. $student_data = SStudentInfo::model()->findAll($criteria);
  624. unset($criteria);
  625. }
  626. $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_id));
  627. $orderstu=array();
  628. if($orderid){
  629. $orderstus= CMSOrderStudent::model()->findAll("order_id=:oid and clazz_id=:cid",array(":oid"=>$orderid,":cid"=>$class_id));
  630. foreach($orderstus as $v)
  631. {
  632. $orderstu[] = $v->attributes;
  633. }
  634. }
  635. if($student_data && $class_data)
  636. {
  637. if($goods_data)
  638. {
  639. if($goods_data->apply_class==-1 || $goods_data->apply_class >= $class_data->grade)
  640. {
  641. foreach($student_data as $v)
  642. {
  643. $data[] = $v->attributes;
  644. }
  645. echo json_encode(array('status'=>1,'result'=>$data,"orderstu"=>$orderstu));exit;
  646. }
  647. // else
  648. // {
  649. // echo json_encode(array('status'=>2,'result'=>'',"orderstu"=>$orderstu));exit;
  650. // }
  651. }else
  652. {
  653. foreach($student_data as $v)
  654. {
  655. $data[] = $v->attributes;
  656. }
  657. echo json_encode(array('status'=>1,'result'=>$data,"orderstu"=>$orderstu));exit;
  658. }
  659. }
  660. echo json_encode(array('status'=>0,'result'=>'',"orderstu"=>$orderstu));exit;
  661. }
  662. public function actionGetstudents()
  663. {
  664. $data = array();
  665. $class_id = safe_replace(Yii::app()->request->getPost('class_id'));
  666. $student_data = StudentInfo::model()->getStudentByClassId($class_id);
  667. if($student_data )
  668. {
  669. foreach($student_data as $v)
  670. {
  671. $data[] = $v->attributes;
  672. }
  673. echo json_encode(array('status'=>1,'result'=>$data));exit;
  674. }
  675. echo json_encode(array('status'=>0,'result'=>''));exit;
  676. }
  677. public function actionGetclass()
  678. {
  679. $data = array();
  680. $semester_id = safe_replace(Yii::app()->request->getPost('semester_id'));
  681. $nianji = safe_replace(Yii::app()->request->getPost('nianji'));
  682. if(!$nianji){
  683. $clss_data = ClassModel::model()->getClassBySemester($semester_id);
  684. }else{
  685. $clss_data = ClassModel::model()->getClassBySemesternianji($semester_id,$nianji);
  686. }
  687. if($clss_data )
  688. {
  689. foreach($clss_data as $v)
  690. {
  691. $data[] = $v->attributes;
  692. }
  693. echo json_encode(array('status'=>1,'result'=>$data));exit;
  694. }
  695. echo json_encode(array('status'=>0,'result'=>''));exit;
  696. }
  697. public function actionEditOrderback(){
  698. $data = array();
  699. $order_id = Yii::app()->request->getParam('order_id');
  700. $data['old_order_id']=$old_order_id = Yii::app()->request->getParam('old_order_id');
  701. $data['type']= Yii::app()->request->getParam('type');
  702. if(!$order_id){
  703. Yii::app()->jump->error('参数不正确!');
  704. }
  705. $sql="select o.*,ob.* from `order` as o left join order_back as ob on o.id=ob.order_id where o.id={$order_id}";
  706. $orderinfo= Yii::app()->db251->createCommand($sql)->queryAll();
  707. $orderinfo=$orderinfo[0];
  708. if($orderinfo['status']!=2&&$orderinfo['status']!=3){
  709. Yii::app()->jump->error('审核不通过订单才能编辑!');
  710. }else{
  711. $sql="select os.* from order_student as os join `order` as o on o.id=os.order_id where os.order_id={$old_order_id} and o.school_id={$this->schoolId} GROUP BY os.clazz_id";
  712. $data['classes']=Yii::app()->db251->createCommand($sql)->queryAll();
  713. $data['stu']= CMSOrderStudent::model()->findAll("order_id=:id order by clazz_id asc",array(":id"=>$order_id));
  714. $data['action']="edit";
  715. $data['orderid']=$order_id;
  716. $data['orderinfo']=$orderinfo;
  717. $this->render('back_add',$data);
  718. }
  719. }
  720. public function actionEditOrder(){
  721. $order_id = Yii::app()->request->getParam('order_id');
  722. if(!$order_id){
  723. Yii::app()->jump->error('参数不正确!');
  724. }
  725. $type= isset($_GET['type'])?$_GET['type']:"ordinary";
  726. if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){
  727. Yii::app()->jump->error('参数不正确');
  728. }else{
  729. switch ($type){
  730. case "test":
  731. $classify=2;
  732. break;
  733. case "all":
  734. $classify=1;
  735. break;
  736. default :
  737. $classify=0;
  738. break;
  739. }
  740. }
  741. $data['type']=$type;
  742. $criteria = new CDbCriteria();
  743. $criteria->select="*";
  744. $criteria->addCondition('id=:id');
  745. $criteria->params[':id'] = $order_id;
  746. $orderinfo= CMSOrder::model()->find($criteria);
  747. if($orderinfo['status']!=2&&$orderinfo['status']!=3){
  748. Yii::app()->jump->error('审核不通过订单才能编辑!');
  749. }
  750. $data = array();
  751. $type= isset($_GET['type'])?$_GET['type']:"ordinary";
  752. if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){
  753. Yii::app()->jump->error('参数不正确');
  754. }
  755. $data['type']=$type;
  756. //获取商品
  757. $goods_type_data = CMSGoodsType::model()->findAll('is_delete=:is_delete',array('is_delete'=>0));
  758. if($goods_type_data)
  759. {
  760. $data['goods_type'] = $goods_type_data;
  761. }
  762. if($type=="all"||$type=="test"){
  763. $data['orderinfo']=Yii::app()->db251->createCommand('select g.effective_date,g.classify as g_classify,g.grade,g.goods_type_name,goods.apply_class,goods.price as gprice,gs.promotion_price as g_price1,gs.price as g_price,o.*,g.goods_id,s.subject_name,g.goods_type_id from'
  764. . ' `order` as o left join order_goods as g on o.id=g.order_id left join order_goods_subject as s on s.order_id=o.id left join goods_spec as gs on gs.goods_id=g.goods_id '
  765. . 'left join goods on goods.id=g.goods_id where o.id='.$order_id)->queryRow();
  766. $data['goods_sem']= CMSOrderGoodsSemester::model()->find("order_id=:id",array(":id"=>$order_id));
  767. if($type=="all"){
  768. $data['pay']= Yii::app()->db251->createCommand("select * from payment where order_id=$order_id order by id asc")->queryRow();
  769. $data['payok']= Yii::app()->db251->createCommand("select sum(pay_money) as summoney from payment where order_id=$order_id and status=1")->queryRow();
  770. $data['orderinfo']= array_merge($data['orderinfo'],$data['pay'],$data['payok']);
  771. }
  772. }elseif($type=="ordinary"){
  773. $data['orderinfo']=Yii::app()->db251->createCommand('select g.effective_date,g.classify as g_classify,g.grade,g.goods_type_name,op.pay_cert,op.pay_account,op.pay_money,op.pay_time,goods.apply_class,goods.price as gprice,gs.promotion_price as g_price1,gs.price as g_price,o.*,g.goods_id,s.subject_name,g.goods_type_id from'
  774. . ' `order` as o left join order_goods as g on o.id=g.order_id left join order_goods_subject as s on s.order_id=o.id left join goods_spec as gs on gs.goods_id=g.goods_id '
  775. . 'left join goods on goods.id=g.goods_id left join order_pay as op on op.order_id=o.id where o.id='.$order_id)->queryRow();
  776. }
  777. $goods_data = CMSGoods::model()->findAll('type_id=:type_id and status=:status and is_delete=:is_delete',array(':type_id'=>$data['orderinfo']['goods_type_id'],':status'=>1,':is_delete'=>0));
  778. if($goods_data)
  779. {
  780. $data['goods_data'] = $goods_data;
  781. }
  782. //班级
  783. $class_data = ClassModel::model()->getClassBySemesternianji($this->semesterId,$data['orderinfo']['apply_class']);
  784. if($class_data)
  785. {
  786. $data['classes'] = $class_data;
  787. }
  788. $data['goods_spec_data'] = CMSGoodsSpec::model()->findAll('goods_id=:goods_id ',array(':goods_id'=>$data['orderinfo']['goods_id']));
  789. if($type!="test"){
  790. $data['stu']= CMSOrderStudent::model()->findAll("order_id=:id order by clazz_id asc",array(":id"=>$order_id));
  791. }else{
  792. $criteria = new CDbCriteria();
  793. $criteria->select="*";
  794. $criteria->addCondition('order_id=:orderid');
  795. $criteria->params[':orderid'] = $order_id;
  796. $data['class']= CMSOrderClazz::model()->findAll($criteria);
  797. $classid=array();
  798. foreach($data['class'] as $v){
  799. $classid[]=$v['clazz_id'];
  800. }
  801. $criteria = new CDbCriteria();
  802. $criteria->select="*";
  803. $criteria->addNotInCondition('class_id', $classid);//去掉订单里的班级
  804. if($data['orderinfo']['grade']!=-1){
  805. $criteria->addCondition('grade=:grade');
  806. $criteria->params[':grade'] = $data['orderinfo']['grade'];
  807. }
  808. $data['classes']= ClassModel::model()->findAll($criteria);
  809. }
  810. if($type!="ordinary"){
  811. $data['sem']= Semester::model()->find(array(
  812. 'select' =>array('semester_name'),
  813. 'condition' => 'status=1',
  814. ));
  815. }
  816. $data['action']="edit";
  817. $data['orderid']=$order_id;
  818. $this->render('add',$data);
  819. }
  820. public function actionAdd(){
  821. $data = array();
  822. $type= isset($_GET['type'])?$_GET['type']:"ordinary";
  823. if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){
  824. Yii::app()->jump->error('参数不正确');
  825. }
  826. $data['type']=$type;
  827. if($type!="all"){
  828. $data['sem']= Semester::model()->find(array(
  829. 'select' =>array('semester_name'),
  830. 'condition' => 'status=1',
  831. ));
  832. }
  833. //获取商品
  834. $goods_type_data = CMSGoodsType::model()->findAll('is_delete=:is_delete',array('is_delete'=>0));
  835. if($goods_type_data)
  836. {
  837. $data['goods_type'] = $goods_type_data;
  838. }
  839. //班级
  840. $class_data = ClassModel::model()->getClassBySemester($this->semesterId);
  841. if($class_data)
  842. {
  843. $data['classes'] = $class_data;
  844. }
  845. //商品规格
  846. /**
  847. * 1、修改:
  848. *开发者:刘红伟
  849. * 时间:2018-03-06
  850. * 限定订单开始时间与结束时间
  851. *
  852. * 修改学管端下试用订单选择学生时的条件,如果本赛季已经试用过则无法加入试用订单;
  853. * . 试用订单属于哪个赛季按照试用订单的开始时间计算;
  854. * 时间:2018-03-06
  855. * 开发者:刘红伟
  856. */
  857. //获取学期
  858. $semester_data = Semester::model()->find('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  859. if(!$semester_data)
  860. {
  861. echo json_encode(array('status'=>3));exit;
  862. }
  863. $start_time = date('Y-m-d',$semester_data->start_time);
  864. $end_time = date('Y-m-d',$semester_data->end_time);
  865. $time = time();
  866. $season_time = json_decode(Yii::app()->crm_login_cache->getValue('zsy_season_time_key'),1);//获取redis赛时时间
  867. if($season_time)
  868. {
  869. foreach ($season_time as $v)
  870. {
  871. if($time>$v['startTime'] && $time<$v['endTime'])//比对赛时的时间
  872. {
  873. $start_time = date('Y-m-d',$v['startTime']);
  874. $end_time = date('Y-m-d',$v['endTime']);
  875. }
  876. }
  877. }
  878. //商品关联学科
  879. $data['action']="add";
  880. $data['start_time']=$start_time;
  881. $data['end_time']=$end_time;
  882. $this->render('add',$data);
  883. }
  884. public function actionBack_add(){
  885. $data['orderid']=$order_id = Yii::app()->request->getParam('order_id');
  886. $data['type']= Yii::app()->request->getParam('type');
  887. if(!$order_id){
  888. Yii::app()->jump->error('参数不正确!');
  889. }
  890. $sql="select os.*,o.* from order_student as os join `order` as o on o.id=os.order_id where os.order_id={$order_id} and o.school_id={$this->schoolId} GROUP BY os.clazz_id";
  891. $data['classes']=Yii::app()->db251->createCommand($sql)->queryAll();
  892. $data['price']=0;
  893. if($data['classes']){
  894. $data['price']=$data['classes'][0]['total_price']/$data['classes'][0]['quantity'];
  895. }
  896. $this->render('back_add',$data);
  897. }
  898. public function actionget_back_student(){
  899. $class_id = Yii::app()->request->getPost('class_id');
  900. $orderid = Yii::app()->request->getPost('orderid');
  901. $old_order_id = Yii::app()->request->getPost('old_order_id');
  902. if(!$old_order_id){
  903. $sql="select os.* from order_student as os join `order` as o on o.id=os.order_id where os.order_id='{$orderid}' and o.school_id={$this->schoolId} and os.clazz_id='{$class_id}' and os.chargeback=0";
  904. }else{
  905. $sql="select os.* from order_student as os join `order` as o on o.id=os.order_id where os.order_id='{$old_order_id}' and o.school_id={$this->schoolId} and os.clazz_id='{$class_id}' and os.chargeback=0";
  906. }
  907. $stus=Yii::app()->db251->createCommand($sql)->queryAll();
  908. if($stus){
  909. echo json_encode(array('status'=>1,'result'=>$stus));exit;
  910. }else{
  911. echo json_encode(array('status'=>0,'result'=>''));exit;
  912. }
  913. }
  914. public function actionEdit()
  915. {
  916. $data = array();
  917. //获取商品
  918. $goods_type_data = CMSGoodsType::model()->findAll('is_delete=:is_delete',array('is_delete'=>0));
  919. if($goods_type_data)
  920. {
  921. $data['goods_type'] = $goods_type_data;
  922. }
  923. //班级
  924. $class_data = ClassModel::model()->getClassBySemester($this->semesterId);
  925. if($class_data)
  926. {
  927. $data['classes'] = $class_data;
  928. }
  929. //商品规格
  930. //商品关联学科
  931. $this->render('add',$data);
  932. }
  933. public function actionGetgoods()
  934. {
  935. $type_id = Yii::app()->request->getPost('type_id');
  936. $sem= new SSemester();
  937. $nowsem=$sem->getCurrentSemester();
  938. $goods_array = array();
  939. if($type_id){
  940. $goods_data=Yii::app()->db251->createCommand('select g.* from goods as g LEFT JOIN goods_term as gt on g.id=gt.goods_id where g.type_id='.$type_id.' and g.status=1 and g.is_delete=0 and (gt.`code`='.$nowsem['refer_code'].' or g.classify=1)')->queryAll();
  941. if($goods_data)
  942. {
  943. foreach($goods_data as $v)
  944. {
  945. $goods_array[] = $v;
  946. }
  947. echo json_encode(array('status'=>1,'result'=>$goods_array));exit;
  948. }
  949. }
  950. echo json_encode(array('status'=>0,'result'=>''));exit;
  951. }
  952. public function actionGetsubject()
  953. {
  954. $goods_id = Yii::app()->request->getPost('goods_id');
  955. $type = Yii::app()->request->getPost('type');
  956. $goods_array = array();
  957. $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_id));
  958. if($goods_data)
  959. {
  960. $goods_spec_data = CMSGoodsSpec::model()->findAll('goods_id=:goods_id ',array(':goods_id'=>$goods_id));
  961. $goods_tem=CMSGoodsTerm::model()->find('goods_id=:goods_id ',array(':goods_id'=>$goods_id));
  962. $sem= Semester::model()->find('status=1 ');
  963. if($goods_spec_data)
  964. {
  965. foreach($goods_spec_data as $v)
  966. {
  967. $goods_array[] = $v->attributes;
  968. }
  969. // if($type!="test"){
  970. // echo json_encode(array('status'=>1,'result'=>$goods_array,'apply_class'=>$goods_data->apply_class));exit;
  971. // }else{
  972. $classarr=array();
  973. // if($type=="test"){//找到该学校开过试用订单的班级
  974. // $sql="select oc.clazz_id from `order` as o join order_clazz as oc on o.id=oc.order_id where o.school_id ={$this->schoolId} and o.classify=2";
  975. //
  976. // $test_class_id=Yii::app()->db251->createCommand($sql)->queryAll();
  977. // $test_class_ids=array();
  978. // foreach($test_class_id as $v){
  979. // $test_class_ids[]=$v['clazz_id'];
  980. // }
  981. // }
  982. if($goods_data->apply_class!=-1){
  983. if($type=="test"){//去除试用过的班级
  984. $class= ClassModel::model()->findAll("grade=".$goods_data->apply_class." and semester_id=".$sem['semester_id']);
  985. }else{
  986. $class= ClassModel::model()->findAll("grade=".$goods_data->apply_class." and semester_id=".$sem['semester_id']);
  987. }
  988. }else{
  989. if($type=="test"){//去除试用过的班级
  990. $class= ClassModel::model()->findAll("semester_id=".$sem['semester_id']);
  991. }else{
  992. $class= ClassModel::model()->findAll("semester_id=".$sem['semester_id']);
  993. }
  994. }
  995. if($class){
  996. foreach($class as $v)
  997. {
  998. $classarr[] = $v->attributes;
  999. }
  1000. }
  1001. echo json_encode(array('status'=>1,'result'=>$goods_array,'apply_class'=>$goods_data->apply_class,'class'=>$classarr));exit;
  1002. // }
  1003. }
  1004. }
  1005. echo json_encode(array('status'=>0,'result'=>'','apply_class'=>''));exit;
  1006. }
  1007. public function actionGetsubject_one()
  1008. {
  1009. $goods_spec_id = Yii::app()->request->getPost('goods_spec_id');
  1010. $goods_spec_data = CMSGoodsSpec::model()->find('id=:id ',array(':id'=>$goods_spec_id))->attributes;
  1011. if($goods_spec_data)
  1012. {
  1013. if($goods_spec_data['promotion_price'])
  1014. {
  1015. $goods_spec_data['price'] = $goods_spec_data['promotion_price'];
  1016. }
  1017. $goods= CMSGoods::model()->find("id=:id",array(":id"=>$goods_spec_data['goods_id']));
  1018. $sem= Semester::model()->find("status=1");
  1019. echo json_encode(array('status'=>1,'result'=>$goods_spec_data,"semname"=>$sem['semester_name'],"classify"=>$goods['classify'],"effective_date"=>$goods['effective_date']));exit;
  1020. }
  1021. echo json_encode(array('status'=>0,'result'=>''));exit;
  1022. }
  1023. public function checktime($paytime){
  1024. $time= strtotime($paytime);
  1025. if(!$time){
  1026. $paytime= explode(" ", $paytime);
  1027. if(count($paytime)!=2){
  1028. return false;
  1029. }
  1030. $date=$paytime[0];
  1031. $time=$paytime[1];
  1032. $time= explode(":", $time);
  1033. if(count($time)!=3){
  1034. return false;
  1035. }
  1036. if($time[1]=="60"){
  1037. $time[1]="59";
  1038. }else{
  1039. return false;
  1040. }
  1041. return $date." ".$time[0].":".$time[1].":".$time[2];
  1042. }
  1043. return $paytime;
  1044. }
  1045. public function actionInsert()
  1046. {
  1047. $type_id = Yii::app()->request->getPost('type_id');
  1048. $goods_id = Yii::app()->request->getPost('goods_id');
  1049. $goods_spec_id = Yii::app()->request->getPost('goods_spec_id');
  1050. $class_id = Yii::app()->request->getPost('class_id');
  1051. $pay_account = Yii::app()->request->getPost('pay_account');
  1052. $pay_money = Yii::app()->request->getPost('pay_money');
  1053. $pay_time = Yii::app()->request->getPost('pay_time');
  1054. if($pay_time){
  1055. if(!$pay_time=$this->checktime($pay_time)){
  1056. Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index'));
  1057. }
  1058. }
  1059. $apply_class_hide = Yii::app()->request->getPost('apply_class_hide');
  1060. $select_grade = Yii::app()->request->getPost('select_grade');
  1061. $student_ids = Yii::app()->request->getPost('student_ids');
  1062. $class_name = Yii::app()->request->getPost('class_name');
  1063. $good_type_name = Yii::app()->request->getPost('good_type_name');
  1064. $next_pay_time = Yii::app()->request->getPost('next_pay_time');
  1065. $trial_begin_time = Yii::app()->request->getPost('trial_begin_time');
  1066. $trial_begin_time_test = Yii::app()->request->getPost('trial_begin_time_test');
  1067. $ordertype=Yii::app()->request->getPost('type');
  1068. if($apply_class_hide==-1){
  1069. $apply_class_hide=$select_grade;
  1070. }
  1071. if($ordertype=="ordinary"){
  1072. $classify=0;
  1073. }elseif($ordertype=="all"){
  1074. $classify=1;
  1075. }else{
  1076. $classify=20;
  1077. }
  1078. if(!$class_id)
  1079. {
  1080. Yii::app()->jump->error('请选择班级');
  1081. }
  1082. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  1083. if($class_data)
  1084. {
  1085. $apply_class_hide = $class_data->grade;
  1086. $select_grade = $class_data->grade;
  1087. }
  1088. if($classify!=20){//不是试用订单的话
  1089. if(!$type_id || !$goods_id || !$goods_spec_id || !$class_id ||$trial_begin_time=="0000-00-00 00:00:00" )
  1090. {
  1091. Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add'));
  1092. }
  1093. //图片上传
  1094. if(Yii::app()->params["fdfs_open"]){
  1095. if($_FILES['pic']['name']!=""&&$_FILES['pic']['type']!=""){
  1096. //验证图片
  1097. $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1));
  1098. $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
  1099. if(!in_array($type, $allow_type))
  1100. {
  1101. Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add'));
  1102. }
  1103. $f_file_tmp = $_FILES['pic']['tmp_name'];
  1104. $f_real_name = $_FILES['pic']['name'];
  1105. $f_file_name = dirname($f_file_tmp)."/".$f_real_name;
  1106. @copy($f_file_tmp, $f_file_name);
  1107. @rename($f_file_tmp, $f_file_name);
  1108. $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']);
  1109. $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type);
  1110. if(!$file_info)
  1111. {
  1112. Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add'));
  1113. }
  1114. @unlink($f_file_name);
  1115. $file_name = $file_info;
  1116. }else{
  1117. $file_name="";
  1118. }
  1119. }else{
  1120. $file_name='aa.jpg';
  1121. }
  1122. }else{//试用订单
  1123. if(!$type_id || !$goods_id || !$goods_spec_id ||$trial_begin_time=="0000-00-00 00:00:00" )
  1124. {
  1125. Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add'));
  1126. }
  1127. }
  1128. $student_array = array();
  1129. $student_id_array = array();
  1130. $spec_id = array();
  1131. $spec_array = array();
  1132. $student_num = 0;
  1133. $order_no = $this->_getMillisecond().rand(1,9).rand(1,9).rand(1,9); //订单编号
  1134. if($class_id||$classify==20)
  1135. {
  1136. $stujson=json_decode($student_ids);
  1137. $class_ids=array();
  1138. foreach($stujson as $k=>$v){
  1139. $class_ids[]=$v->classid;
  1140. }
  1141. $student_data = StudentInfo::model()->getStudentInClassId($class_ids);
  1142. $_class_id = 0;
  1143. if($student_data)
  1144. {
  1145. foreach($student_data as $v)
  1146. {
  1147. $student_array[$v->student_id] = $v->realname;
  1148. $student_id_array[$v->student_id] = $v->student_id;
  1149. $_class_id = $v->class_id;
  1150. }
  1151. }
  1152. $_class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$_class_id));
  1153. if($_class_data){
  1154. $apply_class_hide = $_class_data->grade;
  1155. }
  1156. if(!$student_ids)
  1157. {
  1158. Yii::app()->jump->error('请选择学生,重新上传!',Yii::app()->createUrl('order/add'));
  1159. }
  1160. $student_num=Yii::app()->request->getPost('stusum');
  1161. $student_id_array= json_decode($student_ids);
  1162. if($goods_spec_id)
  1163. {
  1164. $goods_spec_data = CMSGoodsSpec::model()->find('id=:id ',array(':id'=>$goods_spec_id));
  1165. if($goods_spec_data)
  1166. {
  1167. if($goods_spec_data->promotion_price)
  1168. {
  1169. $goods_spec_data->price = $goods_spec_data->promotion_price;
  1170. }
  1171. $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_spec_data->goods_id));
  1172. $goods_term_data = CMSGoodsTerm::model()->findAll('goods_id=:goods_id',array(':goods_id'=>$goods_spec_data->goods_id));
  1173. if($goods_data )
  1174. {
  1175. //$term_data = CMSTerm::model()->find('id=:id',array(':id'=>$goods_data->term_id));
  1176. $goods_spec_realtion_data = CMSGoodsSpecRealtion::model()->findAll('goods_spec_id=:goods_spec_id',array(':goods_spec_id'=>$goods_spec_id));
  1177. if($goods_spec_realtion_data)
  1178. {
  1179. foreach($goods_spec_realtion_data as $v)
  1180. {
  1181. $spec_id[$v->subject_id] = $v->subject_id;
  1182. }
  1183. }
  1184. if($spec_id)
  1185. {
  1186. $Criteria = new CDbCriteria();
  1187. $Criteria->addInCondition('id',$spec_id);
  1188. $subject_data = CMSSubject::model()->findAll($Criteria);
  1189. if($subject_data)
  1190. {
  1191. foreach($subject_data as $v)
  1192. {
  1193. $spec_array[$v->id] = $v->name;
  1194. }
  1195. Yii::app()->db251->active = false;
  1196. //取出商品信息
  1197. // $transaction= Yii::app()->db251->beginTransaction();//建立事务
  1198. Yii::app()->db251->createCommand("START TRANSACTION")->execute();
  1199. try
  1200. {
  1201. $order_odj = new CMSOrder();
  1202. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1203. if(!$orders_id){
  1204. throw new CException('接口错误');
  1205. }
  1206. $orderid=$orders_id->errCode=="00"? $orders_id->data->id:"-1";
  1207. if($orderid=="-1"){
  1208. throw new CException('orderid获取失败,添加失败!');
  1209. }
  1210. $order_odj->id = $orderid;
  1211. $order_odj->order_no = $order_no;
  1212. if($classify!=20){
  1213. $order_odj->total_price = $student_num*$goods_spec_data->price;
  1214. }else{
  1215. $order_odj->total_price = 0;
  1216. }
  1217. // $order_odj->pay_money = $pay_money;
  1218. $order_odj->openid = $this->coachId;
  1219. $order_odj->create_time = date('Y-m-d H:i:s',time());
  1220. // $order_odj->pay_time = $pay_time;
  1221. $order_odj->status = 0;
  1222. // $order_odj->prepay_id = null;
  1223. $order_odj->type = 1;
  1224. $order_odj->classify = $classify;
  1225. $order_odj->grade = $apply_class_hide;
  1226. $order_odj->school_id = $this->schoolId;
  1227. $order_odj->school_name = Yii::app()->session['session_school_name'];
  1228. // $order_odj->pay_account = $pay_account;
  1229. // $order_odj->pay_cert = $file_name;
  1230. $order_odj->apply_time = null;
  1231. if($classify==1){
  1232. $order_odj->payment_status ="1_0";
  1233. }
  1234. $order_odj->create_user = Yii::app()->session['coachInfo']['real_name'];
  1235. $order_odj->quantity = $student_num;
  1236. if($classify==20){
  1237. $order_odj->trial_begin_time = $trial_begin_time_test;
  1238. }else{
  1239. if($goods_data->classify!=0){//不是试用订单但是商品是以有效期结算
  1240. if(strtotime($trial_begin_time)== strtotime(date("Y-m-d"))){
  1241. $trial_begin_time=date("Y-m-d H:i:s");
  1242. $trial_end_time=date("Y-m-d H:i:s",(strtotime($trial_begin_time) + 3600*24*$goods_data->effective_date));
  1243. }else{
  1244. $trial_end_time=date("Y-m-d",(strtotime($trial_begin_time) + 3600*24*($goods_data->effective_date)-1))." 23:59:59";
  1245. }
  1246. $order_odj->trial_begin_time = $trial_begin_time;
  1247. $order_odj->trial_end_time = $trial_end_time;
  1248. }
  1249. }
  1250. $order_odj->save();
  1251. $order_ids = $order_odj->getOldPrimaryKey();
  1252. if($classify!=20){//不是试用订单才有支付信息
  1253. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1254. if(!$orders_id){
  1255. throw new CException('接口错误');
  1256. }
  1257. $orderpayid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  1258. if($orderpayid=="-1"){
  1259. throw new CException('orderpayid获取失败,添加失败!');
  1260. }
  1261. if($ordertype!="all"){
  1262. $order_pay=new CMSOrderPay();
  1263. $order_pay->id=$orderpayid;
  1264. $order_pay->order_id=$orderid;
  1265. if($classify!=20){
  1266. $order_pay->pay_money=$pay_money;
  1267. }else{
  1268. $order_pay->pay_money=0;
  1269. }
  1270. if($pay_time){
  1271. $order_pay->pay_time=$pay_time;
  1272. }
  1273. $order_pay->pay_account=$pay_account;
  1274. $order_pay->pay_cert=$file_name;
  1275. $order_pay->save();
  1276. }else{
  1277. $payment=new CMSPayment();
  1278. $payment->id=$orderpayid;
  1279. $payment->order_id=$orderid;
  1280. $payment->pay_money=$pay_money;
  1281. if($pay_time){
  1282. $payment->pay_time=$pay_time;
  1283. }
  1284. $payment->pay_account=$pay_account;
  1285. $payment->pay_cert=$file_name;
  1286. $payment->status=0;
  1287. if($next_pay_time){
  1288. $payment->next_pay_time=$next_pay_time;
  1289. }
  1290. $payment->save();
  1291. }
  1292. }
  1293. if($order_ids)
  1294. {
  1295. $order_goods_odj = new CMSOrderGoods();
  1296. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1297. if(!$orders_id){
  1298. throw new CException('接口错误!');
  1299. }
  1300. $ordergoodid=$orders_id->errCode=="00"? $orders_id->data->id:"-1";
  1301. if($ordergoodid=="-1"){
  1302. throw new CException('orderpayid获取失败,添加失败!');
  1303. }
  1304. $order_goods_odj->id = $ordergoodid;
  1305. $order_goods_odj->goods_name = $goods_data->goods_name;
  1306. if($classify!=20){
  1307. $order_goods_odj->price = $goods_spec_data->price;
  1308. }else{
  1309. $order_goods_odj->price=0;
  1310. }
  1311. $order_goods_odj->order_id = $orderid;
  1312. $order_goods_odj->goods_id = $goods_data->id;
  1313. $order_goods_odj->goods_type_id = $type_id;
  1314. $order_goods_odj->goods_type_name = $good_type_name;
  1315. $order_goods_odj->subject_names = $goods_spec_data->name;
  1316. $order_goods_odj->grade = $goods_data->apply_class;
  1317. $order_goods_odj->thumbnail = $goods_data->thumbnail;
  1318. if($goods_data->classify!=0){
  1319. $order_goods_odj->classify = $goods_data->classify;
  1320. $order_goods_odj->effective_date = $goods_data->effective_date;
  1321. }
  1322. $order_goods_odj->save();
  1323. if($goods_term_data){
  1324. $sql='';
  1325. $sqlArr=array();
  1326. $i=0;
  1327. $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id'].(count($goods_term_data))));
  1328. if(!$orders_ids||$orders_ids->errCode!="00"){
  1329. throw new CException('接口错误4!');
  1330. }else{
  1331. $orders_ids=$orders_ids->data;
  1332. }
  1333. foreach($goods_term_data as $v)
  1334. {
  1335. if ($i == 0) {
  1336. $sql .= "INSERT INTO `order_goods_semester` (`id`,`order_id`,`goods_id`,`code`,`name`)VALUES ";
  1337. } else {
  1338. $sql .= ", ";
  1339. }
  1340. $ordergoodsemesterid= isset($orders_ids[0])?$orders_ids[0]:-1;
  1341. array_splice($orders_ids,0,1);
  1342. if(!$ordergoodsemesterid){
  1343. throw new CException('ordergoodsemesterid获取失败,添加失败!');
  1344. }
  1345. $sql.='('.$ordergoodsemesterid.','.$order_ids['id'].','.$v->goods_id.',"'.$v->code.'","'.$v->name.'")';
  1346. $i++;
  1347. if ($i == 200) {
  1348. $i = 0;
  1349. $sql.= ";";
  1350. $sqlArr[] = $sql;
  1351. $sql = "";
  1352. }
  1353. }
  1354. if ($sql) {
  1355. $sqlArr[] = $sql;
  1356. }
  1357. foreach ($sqlArr as $v) {
  1358. Yii::app()->db251->createCommand($v)->execute();
  1359. }
  1360. }
  1361. $sql='';
  1362. $sqlArr=array();
  1363. $i=0;
  1364. $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id'].(count($goods_spec_realtion_data)>0?count($goods_spec_realtion_data):1)));
  1365. if(!$orders_ids||$orders_ids->errCode!="00"){
  1366. throw new CException('接口错误5!');
  1367. }else{
  1368. $orders_ids=$orders_ids->data;
  1369. }
  1370. foreach($goods_spec_realtion_data as $v)
  1371. {
  1372. if ($i == 0) {
  1373. $sql='INSERT INTO `order_goods_subject` (`id`,`subject_id` ,`subject_name` ,`order_id` ,`goods_id`) VALUES ';
  1374. } else {
  1375. $sql .= ", ";
  1376. }
  1377. $ordergoodsubjectid= isset($orders_ids[0])?$orders_ids[0]:-1;
  1378. array_splice($orders_ids,0,1);
  1379. if(!$ordergoodsubjectid){
  1380. throw new CException('ordergoodsubjectid获取失败,添加失败!');
  1381. }
  1382. $sql.='('.$ordergoodsubjectid.','.$v->subject_id.',"'.$spec_array[$v->subject_id].'","'.$order_ids['id'].'","'.$goods_data->id.'")';
  1383. $i++;
  1384. if ($i == 200) {
  1385. $i = 0;
  1386. $sql.= ";";
  1387. $sqlArr[] = $sql;
  1388. $sql = "";
  1389. }
  1390. }
  1391. // $sql = substr($sql,0,-1);
  1392. if ($sql) {
  1393. $sqlArr[] = $sql;
  1394. }
  1395. foreach ($sqlArr as $v) {
  1396. Yii::app()->db251->createCommand($v)->execute();
  1397. }
  1398. $order_operate_log_odj = new CMSOrderOperateLog();
  1399. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1400. if(!$orders_id){
  1401. throw new CException('接口错误!');
  1402. }
  1403. $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  1404. if($orderlogid=="-1"){
  1405. throw new CException('ordergoodsubjectid获取失败,添加失败!');
  1406. }
  1407. $order_operate_log_odj->id =$orderlogid;
  1408. $order_operate_log_odj->role_name = '学管';
  1409. $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name'];
  1410. if($classify!=20){
  1411. $order_operate_log_odj->info = '创建了订单,付款'.$this->xiaoshu($pay_money).'(元)';
  1412. }else{
  1413. $order_operate_log_odj->info = '创建了试用订单并提交审核';
  1414. }
  1415. $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time());
  1416. $order_operate_log_odj->order_id = $order_ids['id'];
  1417. $order_operate_log_odj->save();
  1418. $order_student_sql='';
  1419. $insertnum=0;
  1420. $sqlArr=array();
  1421. $i=0;
  1422. $stu_num=0;
  1423. foreach($student_id_array as $k=>$v)
  1424. {
  1425. $stu_num+=count($v->stus);
  1426. }
  1427. $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id'].($stu_num>0?$stu_num:1)));
  1428. if(!$orders_ids||$orders_ids->errCode!="00"){
  1429. throw new CException('接口错误');
  1430. }else{
  1431. $orders_ids=$orders_ids->data;
  1432. }
  1433. $insert_stu=array();
  1434. foreach($student_id_array as $k=>$v)
  1435. {
  1436. $class_id=$v->classid;
  1437. $class_name=$v->classname;
  1438. foreach($v->stus as $s){
  1439. if(!isset($insert_stu[$s])){
  1440. $insert_stu[$s]=$s;
  1441. if ($i == 0) {
  1442. $order_student_sql='INSERT INTO `order_student` (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name`) VALUES ';
  1443. } else {
  1444. $order_student_sql .= ", ";
  1445. }
  1446. $insertnum++;
  1447. $ordergoodstudentid= isset($orders_ids[0])?$orders_ids[0]:-1;
  1448. array_splice($orders_ids,0,1);
  1449. if(!$ordergoodstudentid){
  1450. throw new CException('ordergoodstudentid获取失败,添加失败!');
  1451. }
  1452. $order_student_sql.='('.$ordergoodstudentid.','.$order_ids['id'].',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'")';
  1453. $i++;
  1454. if ($i == 200) {
  1455. $i = 0;
  1456. $order_student_sql.= ";";
  1457. $sqlArr[] = $order_student_sql;
  1458. $order_student_sql = "";
  1459. }
  1460. }else{
  1461. throw new CException('学生重复,请重新添加!');
  1462. }
  1463. }
  1464. }
  1465. }
  1466. CMSGoods::model()->updateAll(array('buyer_num'=>($goods_data->buyer_num+$student_num)),'id=:id',array(':id'=>$goods_id));
  1467. if($insertnum>0){
  1468. if ($order_student_sql) {
  1469. $sqlArr[] = $order_student_sql;
  1470. }
  1471. foreach ($sqlArr as $v) {
  1472. Yii::app()->db251->createCommand($v)->execute();
  1473. }
  1474. }
  1475. Yii::app()->db251->createCommand("COMMIT")->execute();
  1476. $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$orderid));
  1477. if($check_order){
  1478. if($check_order->errCode!="00"){
  1479. throw new CException('添加失败,'.$check_order->errMsg);
  1480. }
  1481. }else{
  1482. throw new CException('添加失败,接口错误');
  1483. }
  1484. }catch(Exception $e)
  1485. {
  1486. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  1487. Yii::app()->jump->error($e->getMessage(),Yii::app()->createUrl('order/add'));
  1488. }
  1489. $this->redirect($this->createUrl('order/index'."?type=".$ordertype));
  1490. }
  1491. }
  1492. }
  1493. }
  1494. }
  1495. }
  1496. Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/add'));
  1497. }
  1498. public function actionInsert_back()
  1499. {
  1500. $back_account = Yii::app()->request->getPost('back_account');
  1501. $back_money = Yii::app()->request->getPost('back_money');
  1502. $student_ids = Yii::app()->request->getPost('student_ids');
  1503. $old_order_id = Yii::app()->request->getPost('old_order_id');
  1504. $type = Yii::app()->request->getPost('type');
  1505. if(!$student_ids )
  1506. {
  1507. Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/index'));
  1508. }
  1509. $student_array = array();
  1510. $student_id_array = array();
  1511. $spec_id = array();
  1512. $spec_array = array();
  1513. $student_num = 0;
  1514. $order_no = $this->_getMillisecond().rand(1,9).rand(1,9).rand(1,9); //订单编号
  1515. $student_id_array= json_decode($student_ids,true);
  1516. if(!$student_ids)
  1517. {
  1518. Yii::app()->jump->error('请选择学生,重新上传!',Yii::app()->createUrl('order/add'));
  1519. }
  1520. $class_ids=array();
  1521. $stu_num=0;
  1522. foreach($student_id_array as $k=>$v)
  1523. {
  1524. $stu_num+=count($v['stus']);
  1525. }
  1526. $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id']. ($stu_num)));
  1527. if(!$orders_ids||$orders_ids->errCode!="00"){
  1528. Yii::app()->jump->error('接口错误');
  1529. }else{
  1530. $orders_ids=$orders_ids->data;
  1531. }
  1532. foreach($student_id_array as $k=>$v){
  1533. $class_ids[]=$v['classid'];
  1534. }
  1535. $student_data = StudentInfo::model()->getStudentInClassId($class_ids);
  1536. if($student_data)
  1537. {
  1538. foreach($student_data as $v)
  1539. {
  1540. $student_array[$v->student_id] = $v->realname;
  1541. }
  1542. }
  1543. $student_num=Yii::app()->request->getPost('stusum');
  1544. Yii::app()->db251->active = false; // 关闭连接 close();
  1545. Yii::app()->db251->createCommand("START TRANSACTION")->execute();
  1546. try
  1547. {
  1548. $order_odj = new CMSOrder();
  1549. $old_order_info=$order_odj->getOrderInfo($old_order_id);
  1550. $back_parice=$old_order_info->total_price/$old_order_info->quantity*$student_num;
  1551. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1552. if(!$orders_id){
  1553. Yii::app()->jump->error('接口错误');
  1554. }
  1555. $orderid=$orders_id->errCode=="00"? $orders_id->data->id:"-1";
  1556. if($orderid=="-1"){
  1557. Yii::app()->jump->error('orderid获取失败,添加失败!');
  1558. }
  1559. $order_odj->id = $orderid;
  1560. $order_odj->order_no = $order_no;
  1561. $order_odj->total_price = $back_parice;
  1562. $order_odj->openid = $this->coachId;
  1563. $order_odj->create_time = date('Y-m-d H:i:s',time());
  1564. $order_odj->status = 0;
  1565. $order_odj->type = 1;
  1566. $order_odj->classify = 3;
  1567. $order_odj->school_id = $this->schoolId;
  1568. $order_odj->school_name = Yii::app()->session['session_school_name'];
  1569. $order_odj->apply_time = null;
  1570. $order_odj->create_user = Yii::app()->session['coachInfo']['real_name'];
  1571. $order_odj->quantity = $student_num;
  1572. $order_odj->original_order_id = $old_order_id;
  1573. $order_odj->save();
  1574. $order_ids = $order_odj->getOldPrimaryKey();
  1575. if($order_ids)
  1576. {
  1577. $order_back_odj = new CMSOrder_back();
  1578. $order_back_odj->order_id=$order_ids['id'];
  1579. $order_back_odj->account=$back_account;
  1580. $order_back_odj->money=$back_money;
  1581. $order_back_odj->save();
  1582. $order_student_sql='INSERT INTO `order_student`
  1583. (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name`
  1584. )VALUES ';
  1585. $insertnum=0;
  1586. foreach($student_id_array as $k=>$v)
  1587. {
  1588. $class_id=$v['classid'];
  1589. $class_name=$v['classname'];
  1590. foreach($v['stus'] as $s){
  1591. $insertnum++;
  1592. $ordergoodstudentid= isset($orders_ids[0])?$orders_ids[0]:-1;
  1593. array_splice($orders_ids,0,1);
  1594. if(!$ordergoodstudentid){
  1595. Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  1596. }
  1597. $order_student_sql.='('.$ordergoodstudentid.','.$order_ids['id'].',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'"),';
  1598. }
  1599. }
  1600. }
  1601. if($insertnum>0){
  1602. $order_student_sql = substr($order_student_sql,0,-1);
  1603. Yii::app()->db251->createCommand($order_student_sql)->execute();
  1604. }
  1605. $order_operate_log_odj = new CMSOrderOperateLog();
  1606. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1607. if(!$orders_id){
  1608. Yii::app()->jump->error('接口错误');
  1609. }
  1610. $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  1611. if($orderlogid=="-1"){
  1612. Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!');
  1613. }
  1614. $order_operate_log_odj->id =$orderlogid;
  1615. $order_operate_log_odj->role_name = '学管';
  1616. $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name'];
  1617. $order_operate_log_odj->info = '创建了退单并提交审核';
  1618. $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time());
  1619. $order_operate_log_odj->order_id = $order_ids['id'];
  1620. $order_operate_log_odj->save();
  1621. Yii::app()->db251->createCommand("COMMIT")->execute();
  1622. $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$orderid));
  1623. // $path=Yii::getPathOfAlias('webroot')."/assets/order_interface_log.txt";
  1624. // $myfile = fopen($path, "a");
  1625. //
  1626. // $txt = "退单操作,请求".Yii::app()->params['order_interface'].$orderid."接口 orderid:".$orderid." 返回errCode:".$check_order->errCode." \n";
  1627. // fwrite($myfile, $txt);
  1628. // fclose($myfile);
  1629. if($check_order){
  1630. if($check_order->errCode!="00"){
  1631. $this->deletedata($orderid);
  1632. Yii::app()->jump->error('添加失败,'.$check_order->errMsg,Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id));
  1633. }
  1634. }else{
  1635. $this->deletedata($orderid);
  1636. Yii::app()->jump->error('添加失败,接口错误',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id));
  1637. }
  1638. }catch(Exception $e)
  1639. {
  1640. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  1641. Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id));
  1642. }
  1643. $this->redirect($this->createUrl('order/info',array("order_id"=>$old_order_id,"type"=>$type)));
  1644. Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id));
  1645. }
  1646. public function deletedata($orderid=null){
  1647. if($orderid!=NULL){
  1648. $orderclazz=new CMSOrderClazz();
  1649. $orderclazz->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1650. $order_student=new CMSOrderStudent();
  1651. $order_student->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1652. $ordergoodssubject=new CMSOrderGoodsSubject();
  1653. $ordergoodssubject->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1654. $ordergoodssemester=new CMSOrderGoodsSemester();
  1655. $ordergoodssemester->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1656. $order_operate_log_odj = new CMSOrderOperateLog();
  1657. $order_operate_log_odj->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1658. $order_goods_odj = new CMSOrderGoods();
  1659. $order_goods_odj->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1660. $payment=new CMSPayment();
  1661. $payment->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1662. $order_pay=new CMSOrderPay();
  1663. $order_pay->deleteAll("order_id=:oid ",array(":oid"=>$orderid));
  1664. $order_odj = new CMSOrder();
  1665. $order_odj->deleteAll("id=:oid ",array(":oid"=>$orderid));
  1666. }
  1667. }
  1668. public function checkid($idarr){
  1669. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']."?_t=".rand(100000000,999999999)));
  1670. if(!$orders_id){
  1671. Yii::app()->jump->error('接口错误');
  1672. }
  1673. $orders_id=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  1674. if($orders_id=="-1"){
  1675. Yii::app()->jump->error('ID接口错误,返回:'.$orders_id->errCode);
  1676. }
  1677. if(isset($idarr[$orders_id])){
  1678. $this->checkid($idarr);
  1679. }else{
  1680. return $orders_id;
  1681. }
  1682. }
  1683. public function actionUpdate_back()
  1684. {
  1685. $order_id = Yii::app()->request->getPost('orderid');
  1686. $type = Yii::app()->request->getPost('type');
  1687. $old_order_id = Yii::app()->request->getPost('old_order_id');
  1688. $pay_account = Yii::app()->request->getPost('back_account');
  1689. $pay_money = Yii::app()->request->getPost('back_money');
  1690. $student_ids = Yii::app()->request->getPost('student_ids');
  1691. $stusum=Yii::app()->request->getPost('stusum');
  1692. Yii::app()->db251->createCommand("START TRANSACTION")->execute();
  1693. try
  1694. {
  1695. $order_obj=new CMSOrder();
  1696. $orderinfo=$order_obj->getOrderInfo($order_id);
  1697. $total_price=$orderinfo['total_price']/$orderinfo['quantity']*$stusum;
  1698. $orderdata=array(
  1699. "total_price"=>$total_price,
  1700. "quantity"=>$stusum
  1701. // "status"=>0
  1702. );
  1703. $order_obj->updateAll($orderdata,"id=:id",array(":id"=>$order_id));
  1704. $order_back_obj=new CMSOrder_back();
  1705. $orderdata=array();
  1706. $orderdata['account']=$pay_account;
  1707. $orderdata['money']=$pay_money;
  1708. $order_back_obj->updateAll($orderdata,"order_id=:id",array(":id"=>$order_id));
  1709. if($student_ids!=Yii::app()->request->getPost('old_stu_ids')){
  1710. $stujson=json_decode($student_ids);
  1711. $class_ids=array();
  1712. $student_array=array();
  1713. $student_id_array=array();
  1714. foreach($stujson as $k=>$v){
  1715. $class_ids[]=$v->classid;
  1716. }
  1717. $student_data = StudentInfo::model()->getStudentInClassId($class_ids);
  1718. if($student_data)
  1719. {
  1720. foreach($student_data as $v)
  1721. {
  1722. $student_array[$v->student_id] = $v->realname;
  1723. $student_id_array[$v->student_id] = $v->student_id;
  1724. }
  1725. }
  1726. $order_stu=new CMSOrderStudent();
  1727. $order_stu->deleteAll("order_id=:oid ",array(":oid"=>$order_id));
  1728. foreach($stujson as $k=>$v)
  1729. {
  1730. $class_id=$v->classid;
  1731. $class_name=$v->classname;
  1732. $idarr=array();
  1733. $newstunum=0;
  1734. $order_student_sql='INSERT INTO `order_student`
  1735. (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name`
  1736. )VALUES ';
  1737. foreach($v->stus as $s){
  1738. $newstunum++;
  1739. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  1740. if(!$orders_id){
  1741. Yii::app()->jump->error('接口错误');
  1742. }
  1743. $ordergoodstudentid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  1744. if($ordergoodstudentid=="-1"){
  1745. Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  1746. }
  1747. $order_student_sql.='('.$ordergoodstudentid.','.$order_id.',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'"),';
  1748. }
  1749. $order_student_sql = substr($order_student_sql,0,-1);
  1750. if($newstunum>0){
  1751. Yii::app()->db251->createCommand($order_student_sql)->execute();
  1752. }
  1753. }
  1754. }
  1755. Yii::app()->db251->createCommand("COMMIT")->execute();
  1756. $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$order_id));
  1757. // $path=Yii::getPathOfAlias('webroot')."/assets/order_interface_log.txt";
  1758. // $myfile = fopen($path, "a");
  1759. //
  1760. // $txt = "退单操作,请求".Yii::app()->params['order_interface'].$order_id."接口 orderid:".$order_id." 返回errCode:".$check_order->errCode." \n";
  1761. // fwrite($myfile, $txt);
  1762. // fclose($myfile);
  1763. if($check_order){
  1764. if($check_order->errCode!="00"){
  1765. // $this->deletedata($order_id);
  1766. Yii::app()->jump->error('添加失败,'.$check_order->errMsg,Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id));
  1767. }
  1768. }else{
  1769. // $this->deletedata($order_id);
  1770. Yii::app()->jump->error('添加失败,接口错误',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id));
  1771. }
  1772. } catch(CException $e)
  1773. {
  1774. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  1775. Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/index'));
  1776. }
  1777. $this->redirect($this->createUrl('order/info',array("order_id"=>$old_order_id,"type"=>$type)));
  1778. }
  1779. public function actionUpdate()
  1780. {
  1781. $order_id = Yii::app()->request->getPost('orderid');
  1782. $type_id = Yii::app()->request->getPost('type_id');
  1783. $goods_id = Yii::app()->request->getPost('goods_id');
  1784. $goods_spec_id = Yii::app()->request->getPost('goods_spec_id');
  1785. $class_id = Yii::app()->request->getPost('class_id');
  1786. //$students = Yii::app()->request->getPost('students');
  1787. $apply_class_hide = Yii::app()->request->getPost('apply_class_hide');
  1788. $pay_account = Yii::app()->request->getPost('pay_account');
  1789. $pay_money = Yii::app()->request->getPost('pay_money');
  1790. $pay_time = Yii::app()->request->getPost('pay_time');
  1791. if($pay_time){
  1792. if(!$pay_time=$this->checktime($pay_time)){
  1793. Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index'));
  1794. }
  1795. }
  1796. $student_ids = Yii::app()->request->getPost('student_ids');
  1797. $class_name = Yii::app()->request->getPost('class_name');
  1798. $good_type_name = Yii::app()->request->getPost('good_type_name');
  1799. $trial_begin_time=Yii::app()->request->getPost('trial_begin_time');
  1800. $trial_begin_time_test=Yii::app()->request->getPost('trial_begin_time_test');
  1801. $next_pay_time=Yii::app()->request->getPost('next_pay_time');
  1802. $ordertype=Yii::app()->request->getPost('type');
  1803. if($ordertype=="ordinary"){
  1804. $classify=0;
  1805. }elseif($ordertype=="all"){
  1806. $classify=1;
  1807. }else{
  1808. $classify=2;
  1809. }
  1810. if($classify!=2){//不是试用订单的话
  1811. if(!$type_id || !$goods_id || !$goods_spec_id || !$class_id ||$trial_begin_time=="0000-00-00 00:00:00")
  1812. {
  1813. Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add'));
  1814. }
  1815. if(!empty($_FILES['pic']['name'])){
  1816. //验证图片
  1817. $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1));
  1818. $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
  1819. if(!in_array($type, $allow_type))
  1820. {
  1821. Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add'));
  1822. }
  1823. //图片上传
  1824. if(Yii::app()->params["fdfs_open"]){
  1825. $f_file_tmp = $_FILES['pic']['tmp_name'];
  1826. $f_real_name = $_FILES['pic']['name'];
  1827. $f_file_name = dirname($f_file_tmp)."/".$f_real_name;
  1828. @copy($f_file_tmp, $f_file_name);
  1829. @rename($f_file_tmp, $f_file_name);
  1830. ///////////////////////////////////////////////////////////////////////////////////////
  1831. $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']);
  1832. $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type);
  1833. if(!$file_info)
  1834. {
  1835. Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add'));
  1836. }
  1837. @unlink($f_file_name);
  1838. $file_name = $file_info;
  1839. /////////////////////////////////////////////////////////////////////////////////////////
  1840. }else{
  1841. $file_name='aa.jpg';
  1842. }
  1843. /*$fdfs_obj = new FDFS(Yii::app()->params['fastdfs']);
  1844. $file_info = $fdfs_obj->fdfs_upload("pic");
  1845. if(!$file_info)
  1846. {
  1847. Yii::app()->jump->error('上传图片失败,请重新上传!');
  1848. }
  1849. $file_name = '/'.$file_info['1'].'/'.$file_info['0'];*/
  1850. }
  1851. }else{//试用订单
  1852. if(!$type_id || !$goods_id || !$goods_spec_id ||$trial_begin_time=="0000-00-00 00:00:00" )
  1853. {
  1854. Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add'));
  1855. }
  1856. }
  1857. if(!$class_id)
  1858. {
  1859. Yii::app()->jump->error('请选择班级');
  1860. }
  1861. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  1862. if($class_data)
  1863. {
  1864. $apply_class_hide = $class_data->grade;
  1865. $select_grade = $class_data->grade;
  1866. }
  1867. $student_array = array();
  1868. $student_id_array = array();
  1869. $spec_id = array();
  1870. $spec_array = array();
  1871. $student_num = 0;
  1872. $order_no = $this->_getMillisecond().rand(1,9).rand(1,9).rand(1,9); //订单编号
  1873. if($class_id||$classify==2)
  1874. {
  1875. if($classify!=2){
  1876. // if($classify==0){
  1877. // $student_data = StudentInfo::model()->getStudentByClassId($class_id);
  1878. // if($student_data)
  1879. // {
  1880. // foreach($student_data as $v)
  1881. // {
  1882. // $student_array[$v->student_id] = $v->realname;
  1883. // $student_id_array[$v->student_id] = $v->student_id;
  1884. // }
  1885. // }
  1886. // }else{
  1887. $stujson=json_decode($student_ids);
  1888. $class_ids=array();
  1889. foreach($stujson as $k=>$v){
  1890. $class_ids[]=$v->classid;
  1891. }
  1892. $student_data = StudentInfo::model()->getStudentInClassId($class_ids);
  1893. if($student_data)
  1894. {
  1895. foreach($student_data as $v)
  1896. {
  1897. $student_array[$v->student_id] = $v->realname;
  1898. $student_id_array[$v->student_id] = $v->student_id;
  1899. }
  1900. }
  1901. // }
  1902. }else{
  1903. $classinfo = ClassModel::model()->findAll("class_id in ($student_ids)");
  1904. $classarr=array();
  1905. foreach($classinfo as $k=>$v){
  1906. $classarr[$v['class_id']]=$v['class_name'];
  1907. }
  1908. }
  1909. if(!$student_ids)
  1910. {
  1911. Yii::app()->jump->error('请选择学生,重新上传!',Yii::app()->createUrl('order/add'));
  1912. }
  1913. //if($classify!=1){//普通和试用订单
  1914. if($classify==2){//试用订单
  1915. $student_id_array = explode(',',$student_ids);
  1916. $student_num = count($student_id_array);
  1917. }else{//统订和普通订单
  1918. $student_num=Yii::app()->request->getPost('stusum');
  1919. $student_id_array= json_decode($student_ids);
  1920. }
  1921. if($goods_spec_id)
  1922. {
  1923. $goods_spec_data = CMSGoodsSpec::model()->find('id=:id ',array(':id'=>$goods_spec_id));
  1924. if($goods_spec_data)
  1925. {
  1926. if($goods_spec_data->promotion_price)
  1927. {
  1928. $goods_spec_data->price = $goods_spec_data->promotion_price;
  1929. }
  1930. $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_spec_data->goods_id));
  1931. $goods_term_data = CMSGoodsTerm::model()->findAll('goods_id=:goods_id',array(':goods_id'=>$goods_spec_data->goods_id));
  1932. if($goods_data)
  1933. {
  1934. //$term_data = CMSTerm::model()->find('id=:id',array(':id'=>$goods_data->term_id));
  1935. $goods_spec_realtion_data = CMSGoodsSpecRealtion::model()->findAll('goods_spec_id=:goods_spec_id',array(':goods_spec_id'=>$goods_spec_id));
  1936. if($goods_spec_realtion_data)
  1937. {
  1938. foreach($goods_spec_realtion_data as $v)
  1939. {
  1940. $spec_id[$v->subject_id] = $v->subject_id;
  1941. }
  1942. }
  1943. if($spec_id)
  1944. {
  1945. $Criteria = new CDbCriteria();
  1946. $Criteria->addInCondition('id',$spec_id);
  1947. $subject_data = CMSSubject::model()->findAll($Criteria);
  1948. if($subject_data)
  1949. {
  1950. foreach($subject_data as $v)
  1951. {
  1952. $spec_array[$v->id] = $v->name;
  1953. }
  1954. //取出商品信息
  1955. // $transaction= Yii::app()->db251->beginTransaction();//建立事务
  1956. Yii::app()->db251->createCommand("START TRANSACTION")->execute();
  1957. try
  1958. {
  1959. $order_odj = new CMSOrder();
  1960. $orderdata['rder_no'] = $order_no;
  1961. if($classify!=2){
  1962. $orderdata['total_price'] = $student_num*$goods_spec_data->price;
  1963. }else{
  1964. $orderdata['total_price'] = 0;
  1965. }
  1966. // $order_odj->pay_money = $pay_money;
  1967. $orderdata['openid'] = $this->coachId;
  1968. $orderdata['create_time'] = date('Y-m-d H:i:s',time());
  1969. // $order_odj->pay_time = $pay_time;
  1970. $orderdata['grade'] = $apply_class_hide;
  1971. // $order_odj->prepay_id = null;
  1972. $orderdata['type'] = 1;
  1973. $orderdata['school_id'] = $this->schoolId;
  1974. $orderdata['school_name'] = Yii::app()->session['session_school_name'];
  1975. // $order_odj->pay_account = $pay_account;
  1976. // $order_odj->pay_cert = $file_name;
  1977. $orderdata['classify'] =$classify;
  1978. $orderdata['apply_time'] = null;
  1979. $orderdata['create_user'] = Yii::app()->session['coachInfo']['real_name'];
  1980. $orderdata['quantity'] = $student_num;
  1981. if($classify==1){
  1982. $orderdata['payment_status'] ="1_0";
  1983. }
  1984. if($classify==2){
  1985. $orderdata['trial_begin_time'] = $trial_begin_time_test;
  1986. }else{
  1987. if($goods_data->classify!=0){//商品是以有效期结算
  1988. if(strtotime($trial_begin_time)== strtotime(date("Y-m-d"))){
  1989. $trial_begin_time=date("Y-m-d H:i:s");
  1990. $trial_end_time=date("Y-m-d H:i:s",(strtotime($trial_begin_time) + 3600*24*$goods_data->effective_date));
  1991. }else{
  1992. $trial_end_time=date("Y-m-d",(strtotime($trial_begin_time) + 3600*24*($goods_data->effective_date)-1))." 23:59:59";
  1993. }
  1994. $orderdata['trial_begin_time'] = $trial_begin_time;
  1995. $orderdata['trial_end_time'] = $trial_end_time;
  1996. }
  1997. }
  1998. $order_odj->updateAll($orderdata,"id=:id",array(":id"=>$order_id));
  1999. if($classify!=2){//不是试用订单才有支付信息
  2000. if($classify==0){
  2001. $order_pay=new CMSOrderPay();
  2002. $orderpaydata['order_id']=$order_id;
  2003. $orderpaydata['pay_money']=$pay_money;
  2004. if($pay_time){
  2005. $orderpaydata['pay_time']=$pay_time;
  2006. }
  2007. $orderpaydata['pay_account']=$pay_account;
  2008. if(@$file_name){
  2009. $orderpaydata['pay_cert']=$file_name;
  2010. }
  2011. $order_pay->updateAll($orderpaydata,"order_id=:id",array(":id"=>$order_id));
  2012. }else{
  2013. $order_pay=new CMSPayment();
  2014. $orderpaydata['order_id']=$order_id;
  2015. $orderpaydata['pay_money']=$pay_money;
  2016. if($pay_time){
  2017. $orderpaydata['pay_time']=$pay_time;
  2018. }
  2019. $orderpaydata['pay_account']=$pay_account;
  2020. if(@$file_name){
  2021. $orderpaydata['pay_cert']=$file_name;
  2022. }if(@$next_pay_time){
  2023. $orderpaydata['next_pay_time']=$next_pay_time;
  2024. }
  2025. $order_pay->updateAll($orderpaydata,"order_id=:id",array(":id"=>$order_id));
  2026. // $paymentid=$order_pay->find("order_id=:id",array(":id"=>$order_id));
  2027. }
  2028. }
  2029. $order_goods_odj = new CMSOrderGoods();
  2030. $ordergoodsdata['goods_name'] = $goods_data->goods_name;
  2031. if($classify!=2){
  2032. $ordergoodsdata['price'] = $goods_spec_data->price;
  2033. }else{
  2034. $ordergoodsdata['price'] = 0;
  2035. }
  2036. $ordergoodsdata['order_id'] = $order_id;
  2037. $ordergoodsdata['goods_id'] = $goods_data->id;
  2038. $ordergoodsdata['goods_type_id'] = $type_id;
  2039. $ordergoodsdata['goods_type_name'] = $good_type_name;
  2040. $ordergoodsdata['subject_names'] = $goods_spec_data->name;
  2041. $ordergoodsdata['grade'] = $goods_data->apply_class;
  2042. $ordergoodsdata['thumbnail'] = $goods_data->thumbnail;
  2043. if($goods_data->classify!=0){//商品是以有效期结算
  2044. $ordergoodsdata['classify'] = $goods_data->classify;
  2045. $ordergoodsdata['effective_date'] = $goods_data->effective_date;
  2046. }
  2047. $order_goods_odj->updateAll($ordergoodsdata,"order_id=:id",array(":id"=>$order_id));
  2048. if($goods_term_data){
  2049. foreach($goods_term_data as $v)
  2050. {
  2051. $order_good_sem=new CMSOrderGoodsSemester();
  2052. $order_good_sem_data['goods_id']=$v->goods_id;
  2053. $order_good_sem_data['code']=$v->code;
  2054. $order_good_sem_data['name']=$v->name;
  2055. $order_good_sem->updateAll($order_good_sem_data,"order_id=:id",array(":id"=>$order_id));
  2056. }
  2057. }
  2058. foreach($goods_spec_realtion_data as $v)
  2059. {
  2060. $order_good_sub=new CMSOrderGoodsSubject();
  2061. $order_good_sub_data['subject_id']=$v->subject_id;
  2062. $order_good_sub_data['subject_name']=$spec_array[$v->subject_id];
  2063. $order_good_sub_data['goods_id']=$goods_data->id;
  2064. $order_good_sub->updateAll($order_good_sub_data,"order_id=:id",array(":id"=>$order_id));
  2065. }
  2066. $order_operate_log_odj = new CMSOrderOperateLog();
  2067. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2068. if(!$orders_id){
  2069. Yii::app()->jump->error('接口错误');
  2070. }
  2071. $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2072. if($orderlogid=="-1"){
  2073. Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!');
  2074. }
  2075. $order_operate_log_odj->id =$orderlogid;
  2076. $order_operate_log_odj->role_name = '学管';
  2077. $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name'];
  2078. $order_operate_log_odj->info = '修改了订单并重新提交审核';
  2079. $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time());
  2080. $order_operate_log_odj->order_id = $order_id;
  2081. $order_operate_log_odj->save();
  2082. $order_stu=new CMSOrderStudent();
  2083. $order_student_sql='INSERT INTO `order_student`
  2084. (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name`
  2085. )VALUES ';
  2086. if($classify!=2){
  2087. // if($classify==0){
  2088. // $newstunum=0;
  2089. // if($student_ids!=Yii::app()->request->getPost('old_stu_ids')){
  2090. // $order_stu->deleteAll("order_id=:oid and not student_id in ($student_ids)",array(":oid"=>$order_id));
  2091. //
  2092. // $old_stu_ids=Yii::app()->request->getPost('old_stu_ids');
  2093. //
  2094. // $old_stu_id_arr= explode(",", $old_stu_ids);
  2095. //
  2096. // foreach($student_id_array as $v)
  2097. // {
  2098. // if(!in_array($v, $old_stu_id_arr)){
  2099. // $newstunum++;
  2100. // $orders_id= json_decode(file_get_contents(Yii::app()->params['orders_id']));
  2101. // $ordergoodstudentid=$orders_id->errCode=="00"?sprintf("%1.0f", $orders_id->data->id):"-1";
  2102. // if($ordergoodstudentid=="-1"){
  2103. // Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  2104. // }
  2105. // $order_student_sql.='('.$ordergoodstudentid.','.$order_id.',"'.$class_id.'","'.$v.'","'.(isset($student_array[$v])?$student_array[$v]:'').'","'.$class_name.'"),';
  2106. // }
  2107. // }
  2108. // }
  2109. // }else{
  2110. $newstunum=0;
  2111. if($student_ids!=Yii::app()->request->getPost('old_stu_ids')){
  2112. $order_stu->deleteAll("order_id=:oid ",array(":oid"=>$order_id));
  2113. foreach($student_id_array as $k=>$v)
  2114. {
  2115. $class_id=$v->classid;
  2116. $class_name=$v->classname;
  2117. $idarr=array();
  2118. foreach($v->stus as $s){
  2119. $newstunum++;
  2120. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2121. if(!$orders_id){
  2122. Yii::app()->jump->error('接口错误');
  2123. }
  2124. $ordergoodstudentid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2125. if($ordergoodstudentid=="-1"){
  2126. Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  2127. }
  2128. if(isset($idarr[$ordergoodstudentid])){
  2129. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2130. if(!$orders_id){
  2131. Yii::app()->jump->error('接口错误');
  2132. }
  2133. $ordergoodstudentid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2134. if($ordergoodstudentid=="-1"){
  2135. Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  2136. }
  2137. }
  2138. $order_student_sql.='('.$ordergoodstudentid.','.$order_id.',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'"),';
  2139. $idarr[$ordergoodstudentid]=$ordergoodstudentid;
  2140. }
  2141. unset($idarr);
  2142. }
  2143. }
  2144. // }
  2145. CMSGoods::model()->updateAll(array('buyer_num'=>($goods_data->buyer_num+$student_num)),'id=:id',array(':id'=>$goods_id));
  2146. $order_student_sql = substr($order_student_sql,0,-1);
  2147. if($newstunum>0){
  2148. Yii::app()->db251->createCommand($order_student_sql)->execute();
  2149. }
  2150. }else{
  2151. $student_class_relation=new SStudentClassRelation();
  2152. $orderclazz=new CMSOrderClazz();
  2153. $orderclazz->deleteAll("order_id=:oid ",array(":oid"=>$order_id));
  2154. $idarr=array();
  2155. foreach($classarr as $k=>$v){
  2156. $orderclazz=new CMSOrderClazz();
  2157. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2158. if(!$orders_id){
  2159. Yii::app()->jump->error('接口错误');
  2160. }
  2161. $orderclazzid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2162. if($orderclazzid=="-1"){
  2163. Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  2164. }
  2165. if(isset($idarr[$orderclazzid])){
  2166. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2167. if(!$orders_id){
  2168. Yii::app()->jump->error('接口错误');
  2169. }
  2170. $orderclazzid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2171. if($orderclazzid=="-1"){
  2172. Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!');
  2173. }
  2174. }
  2175. $stunum=$student_class_relation->getRelationsByClassId_Status_0_count($k);
  2176. $orderclazz->id=$orderclazzid;
  2177. $orderclazz->order_id=$order_id;
  2178. $orderclazz->clazz_id=$k;
  2179. $orderclazz->clazz_name=$v;
  2180. $orderclazz->students=$stunum;
  2181. $orderclazz->save();
  2182. $idarr[$orderclazzid]=$orderclazzid;
  2183. unset($orderclazz);
  2184. }
  2185. unset($idarr);
  2186. }
  2187. Yii::app()->db251->createCommand("COMMIT")->execute();
  2188. $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$order_id));
  2189. // $path=Yii::getPathOfAlias('webroot')."/assets/order_interface_log.txt";
  2190. // $myfile = fopen($path, "a");
  2191. // $txt = "编辑操作,请求".Yii::app()->params['order_interface'].$order_id."接口 orderid:".$order_id." 返回errCode:".$check_order->errCode." \n";
  2192. // fwrite($myfile, $txt);
  2193. // fclose($myfile);
  2194. if($check_order){
  2195. if($check_order->errCode!="00"){
  2196. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2197. Yii::app()->jump->error('添加失败,'.$check_order->errMsg);
  2198. }
  2199. }else{
  2200. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2201. Yii::app()->jump->error('添加失败,接口错误');
  2202. }
  2203. }
  2204. catch(CException $e)
  2205. {
  2206. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2207. // $transaction->rollBack();
  2208. Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/add'));
  2209. }
  2210. // Yii::app()->db251->createCommand("END")->execute();
  2211. $this->redirect($this->createUrl('order/index'."?type=".$ordertype));
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. }
  2218. Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/add'));
  2219. }
  2220. public function actionpay(){
  2221. $order_id = Yii::app()->request->getParam('order_id');
  2222. $order_classify= CMSOrder::model()->find("id=:id",array(":id"=>$order_id));
  2223. if($order_classify['classify']!=1){
  2224. Yii::app()->jump->error('不是统订订单不能续费',Yii::app()->createUrl('order/index'));
  2225. }
  2226. $paymoney= CMSPayment::model()->findAll("order_id=:id and status=1",array(":id"=>$order_id));
  2227. $paymoneys=0;
  2228. foreach($paymoney as $k=>$v){
  2229. $paymoneys+=$v['pay_money'];
  2230. }
  2231. $this->render("pay",array("order_id"=>$order_id,"paymoneys"=>$paymoneys,"order_classify"=>$order_classify));
  2232. }
  2233. public function actiondopay(){
  2234. $pay_account = Yii::app()->request->getPost('pay_account');
  2235. $pay_money = Yii::app()->request->getPost('pay_money');
  2236. $order_id = Yii::app()->request->getPost('order_id');
  2237. $pay_time = Yii::app()->request->getPost('pay_time');
  2238. if($pay_time){
  2239. if(!$pay_time=$this->checktime($pay_time)){
  2240. Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index'));
  2241. }
  2242. }
  2243. $next_pay_time = Yii::app()->request->getPost('next_pay_time');
  2244. if($next_pay_time){
  2245. if(!$next_pay_time=$this->checktime($next_pay_time)){
  2246. Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index'));
  2247. }
  2248. }
  2249. //验证图片
  2250. $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1));
  2251. $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
  2252. if(!in_array($type, $allow_type))
  2253. {
  2254. Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add'));
  2255. }
  2256. //图片上传
  2257. $f_file_tmp = $_FILES['pic']['tmp_name'];
  2258. $f_real_name = $_FILES['pic']['name'];
  2259. $f_file_name = dirname($f_file_tmp)."/".$f_real_name;
  2260. @copy($f_file_tmp, $f_file_name);
  2261. @rename($f_file_tmp, $f_file_name);
  2262. if(Yii::app()->params["fdfs_open"]){
  2263. ///////////////////////////////////////////////////////////////////////////////////////
  2264. $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']);
  2265. $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type);
  2266. if(!$file_info)
  2267. {
  2268. Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add'));
  2269. }
  2270. @unlink($f_file_name);
  2271. $file_name = $file_info;
  2272. }else{
  2273. /////////////////////////////////////////////////////////////////////////////////////////
  2274. $file_name='aa.jpg';
  2275. }
  2276. /*$fdfs_obj = new FDFS(Yii::app()->params['fastdfs']);
  2277. $file_info = $fdfs_obj->fdfs_upload("pic");
  2278. if(!$file_info)
  2279. {
  2280. Yii::app()->jump->error('上传图片失败,请重新上传!');
  2281. }
  2282. $file_name = '/'.$file_info['1'].'/'.$file_info['0'];*/
  2283. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2284. if(!$orders_id){
  2285. Yii::app()->jump->error('接口错误');
  2286. }
  2287. $orderpayid=$orders_id->errCode=="00"? $orders_id->data->id:"-1";
  2288. if($orderpayid=="-1"){
  2289. Yii::app()->jump->error('orderpayid获取失败,添加失败!');
  2290. }
  2291. Yii::app()->db251->createCommand("START TRANSACTION")->execute();
  2292. $payment=new CMSPayment();
  2293. $payment->id=$orderpayid;
  2294. $payment->order_id=$order_id;
  2295. $payment->pay_money=$pay_money;
  2296. if($pay_time){
  2297. $payment->pay_time=$pay_time;
  2298. }
  2299. $payment->pay_account=$pay_account;
  2300. $payment->pay_cert=$file_name;
  2301. $payment->status=0;
  2302. if($next_pay_time){
  2303. $payment->next_pay_time=$next_pay_time;
  2304. }
  2305. $payment->save();
  2306. $payment_status= CMSOrder::model()->find("id=:id",array(":id"=>$order_id));
  2307. $paymentstatus= explode("_", $payment_status['payment_status']);
  2308. // var_dump(array("payment_status"=>((int)$paymentstatus[0]+1)."_0"));exit;
  2309. CMSOrder::model()->updateAll(array("payment_status"=>((int)$paymentstatus[0]+1)."_0"),'id='.$order_id);
  2310. $order_operate_log_odj = new CMSOrderOperateLog();
  2311. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2312. if(!$orders_id){
  2313. Yii::app()->jump->error('接口错误');
  2314. }
  2315. $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2316. if($orderlogid=="-1"){
  2317. Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!');
  2318. }
  2319. $order_operate_log_odj->id =$orderlogid;
  2320. $order_operate_log_odj->role_name = '学管';
  2321. $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name'];
  2322. $order_operate_log_odj->info = '第'.((int)$paymentstatus[0]+1) ."期缴费申请提交申请";
  2323. $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time());
  2324. $order_operate_log_odj->order_id = $order_id;
  2325. $order_operate_log_odj->save();
  2326. Yii::app()->db251->createCommand("COMMIT")->execute();
  2327. $check_order= json_decode($this->curlpost(Yii::app()->params['payment_interface'].$orderpayid));
  2328. if($check_order){
  2329. if($check_order->errCode!="00"){
  2330. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2331. Yii::app()->jump->error('添加失败!');
  2332. }
  2333. }else{
  2334. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2335. Yii::app()->jump->error('添加失败,接口错误');
  2336. }
  2337. $this->redirect(Yii::app()->createUrl('order/index',array('type'=>"all")));
  2338. }
  2339. public function actiondoeditpay(){
  2340. $pay_account = Yii::app()->request->getPost('pay_account');
  2341. $id = Yii::app()->request->getPost('id');
  2342. $pay_money = Yii::app()->request->getPost('pay_money');
  2343. $order_id = Yii::app()->request->getPost('orderid');
  2344. $pay_time = Yii::app()->request->getPost('pay_time');
  2345. if($pay_time){
  2346. if(!$pay_time=$this->checktime($pay_time)){
  2347. Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index'));
  2348. }
  2349. }
  2350. $next_pay_time = Yii::app()->request->getPost('next_pay_time');
  2351. if($next_pay_time){
  2352. if(!$next_pay_time=$this->checktime($next_pay_time)){
  2353. Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index'));
  2354. }
  2355. }
  2356. if($_FILES['pic']['name']!=""){
  2357. //验证图片
  2358. $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1));
  2359. $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
  2360. if(!in_array($type, $allow_type))
  2361. {
  2362. Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add'));
  2363. }
  2364. //图片上传
  2365. $f_file_tmp = $_FILES['pic']['tmp_name'];
  2366. $f_real_name = $_FILES['pic']['name'];
  2367. $f_file_name = dirname($f_file_tmp)."/".$f_real_name;
  2368. @copy($f_file_tmp, $f_file_name);
  2369. @rename($f_file_tmp, $f_file_name);
  2370. if(Yii::app()->params["fdfs_open"]){
  2371. ///////////////////////////////////////////////////////////////////////////////////////
  2372. $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']);
  2373. $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type);
  2374. if(!$file_info)
  2375. {
  2376. Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add'));
  2377. }
  2378. @unlink($f_file_name);
  2379. $file_name = $file_info;
  2380. }else{
  2381. /////////////////////////////////////////////////////////////////////////////////////////
  2382. $file_name='aa.jpg';
  2383. }
  2384. /*$fdfs_obj = new FDFS(Yii::app()->params['fastdfs']);
  2385. $file_info = $fdfs_obj->fdfs_upload("pic");
  2386. if(!$file_info)
  2387. {
  2388. Yii::app()->jump->error('上传图片失败,请重新上传!');
  2389. }
  2390. $file_name = '/'.$file_info['1'].'/'.$file_info['0'];*/
  2391. }
  2392. Yii::app()->db251->createCommand("START TRANSACTION")->execute();
  2393. $payment=new CMSPayment();
  2394. $paymentdata['order_id']=$order_id;
  2395. $paymentdata['pay_money']=$pay_money;
  2396. if($pay_time){
  2397. $paymentdata['pay_time']=$pay_time;
  2398. }
  2399. $paymentdata['pay_account']=$pay_account;
  2400. if(@$file_name){
  2401. $paymentdata['pay_cert']=$file_name;
  2402. }
  2403. $paymentdata['status']=0;
  2404. if($next_pay_time){
  2405. $paymentdata['next_pay_time']=$next_pay_time;
  2406. }
  2407. // var_dump($paymentdata);echo $id;exit;
  2408. $payment->updateAll($paymentdata,"id=:id",array(":id"=>$id));
  2409. $payment_status= CMSOrder::model()->find("id=:id",array(":id"=>$order_id));
  2410. $paymentstatus= explode("_", $payment_status['payment_status']);
  2411. CMSOrder::model()->updateAll(array("payment_status"=>((int)$paymentstatus[0])."_0"),'id=:id',array(":id"=>$order_id));
  2412. $order_operate_log_odj = new CMSOrderOperateLog();
  2413. $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']));
  2414. if(!$orders_id){
  2415. Yii::app()->jump->error('接口错误');
  2416. }
  2417. $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1";
  2418. if($orderlogid=="-1"){
  2419. Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!');
  2420. }
  2421. $order_operate_log_odj->id =$orderlogid;
  2422. $order_operate_log_odj->role_name = '学管';
  2423. $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name'];
  2424. $order_operate_log_odj->info = '第'.((int)$paymentstatus[0]) ."期缴费申请重新提交申请";
  2425. $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time());
  2426. $order_operate_log_odj->order_id = $order_id;
  2427. $order_operate_log_odj->save();
  2428. Yii::app()->db251->createCommand("COMMIT")->execute();
  2429. $check_order= json_decode($this->curlpost(Yii::app()->params['payment_interface'].$id));
  2430. if($check_order){
  2431. if($check_order->errCode!="00"){
  2432. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2433. Yii::app()->jump->error('缴费失败!');
  2434. }
  2435. }else{
  2436. Yii::app()->db251->createCommand("ROLLBACK")->execute();
  2437. Yii::app()->jump->error('添加失败,接口错误');
  2438. }
  2439. $this->redirect(Yii::app()->createUrl('order/index',array('type'=>"all")));
  2440. }
  2441. public function actionpayedit(){
  2442. $id=Yii::app()->request->getParam('id');
  2443. $data['pay']=CMSPayment::model()->find("id=:id",array(":id"=>$id));
  2444. $data['id']=$id;
  2445. $order=$data['pay']['order_id'];
  2446. $order_classify= CMSOrder::model()->find("id=:id",array(":id"=>$order));
  2447. if($order_classify['classify']!=1){
  2448. Yii::app()->jump->error('不是统订订单不能续费',Yii::app()->createUrl('order/index'));
  2449. }
  2450. $data['order_classify']=$order_classify;
  2451. $paymoney= CMSPayment::model()->findAll("order_id=:id and status=1",array(":id"=>$order));
  2452. $paymoneys=0;
  2453. foreach($paymoney as $k=>$v){
  2454. $paymoneys+=$v['pay_money'];
  2455. }
  2456. $data['paymoneys']=$paymoneys;
  2457. $this->render("payedit",$data);
  2458. }
  2459. public function actionInfo()
  2460. {
  2461. $ordertype= Yii::app()->request->getParam("type")?Yii::app()->request->getParam("type"):"ordinary";
  2462. if($ordertype!=="test"&&$ordertype!=="all"&&$ordertype!=="ordinary"){
  2463. Yii::app()->jump->error('参数不正确');
  2464. }
  2465. $data = array();
  2466. $typeclassfly=array("1"=>"ordinary","2"=>"test",'3'=>"all");
  2467. $order_id = Yii::app()->request->getParam('order_id');
  2468. $data['order_id']=$order_id;
  2469. $order_data = CMSOrder::model()->find('id=:id',array(':id'=>$order_id));
  2470. if($order_data)
  2471. {
  2472. //
  2473. $order_operate_log_data = CMSOrderOperateLog::model()->findAll('order_id=:order_id',array('order_id'=>$order_id));
  2474. $order_goods_data = CMSOrderGoods::model()->find('order_id=:order_id',array('order_id'=>$order_id));
  2475. $order_goods_se_data = CMSOrderGoodsSemester::model()->findAll('order_id=:order_id',array('order_id'=>$order_id));
  2476. $order_goods_subject_data = CMSOrderGoodsSubject::model()->find('order_id=:order_id',array('order_id'=>$order_id));
  2477. if($order_data->classify!=2){
  2478. if($ordertype=="ordinary"){
  2479. $data['orderpay'] = CMSOrderPay::model()->find('order_id=:id',array(':id'=>$order_id));
  2480. }else{
  2481. $data['orderpay'] = CMSPayment::model()->findAll('order_id=:id',array(':id'=>$order_id));
  2482. }
  2483. $criteria = new CDbCriteria();
  2484. $criteria->select="clazz_id";
  2485. $criteria->addCondition('order_id=:order_id');
  2486. $criteria->params[':order_id'] = $order_id;
  2487. $criteria->group="clazz_id";
  2488. $classids = CMSOrderStudent::model()->findAll($criteria);
  2489. $classidarr=array();
  2490. foreach($classids as $v){
  2491. $classidarr[]=$v['clazz_id'];
  2492. }
  2493. $stu=Yii::app()->db251->createCommand("select clazz_id,count(id) as num from order_student where clazz_id in (". implode(",", $classidarr).") and order_id=$order_id GROUP BY clazz_id")->queryAll();
  2494. $criteria = new CDbCriteria();
  2495. $criteria->select="class_id,class_name";
  2496. $criteria->addInCondition("class_id", $classidarr);
  2497. $classes= ClassModel::model()->findAll($criteria);
  2498. $stutotal=0;
  2499. $classinfo=array();
  2500. foreach($classes as $k=>$v){
  2501. $classinfo[$k]['class_id']=$v->class_id;
  2502. $classinfo[$k]['class_name']=$v->class_name;
  2503. foreach($stu as $sk=>$sv){
  2504. if((string)$v['class_id']===(string)$sv['clazz_id']){
  2505. $stutotal+=$sv['num'];
  2506. $classinfo[$k]['stunum']=$sv['num'];
  2507. }
  2508. }
  2509. }
  2510. $data['stutotal']=$stutotal;
  2511. $data['classes']=$classinfo;
  2512. }else{
  2513. $classes= CMSOrderClazz::model()->findAll("order_id=:order_id",array(":order_id"=>$order_id));
  2514. if($classes){
  2515. foreach($classes as $k=>$v){
  2516. $data['classes'][$k]['class_id']=$v['clazz_id'];
  2517. $data['classes'][$k]['class_name']=$v['clazz_name'];
  2518. $data['classes'][$k]['stunum']=$v['students'];
  2519. }
  2520. }else{
  2521. Yii::app()->jump->error('订单信息不完整!',Yii::app()->createUrl('order/index',array("type"=>$typeclassfly[$order_data->classify])));
  2522. }
  2523. }
  2524. if(!$order_goods_data || !$order_goods_subject_data || !$order_operate_log_data )
  2525. {
  2526. Yii::app()->jump->error('订单信息不完整!',Yii::app()->createUrl('order/index',array("type"=>$typeclassfly[$order_data->classify])));
  2527. }
  2528. }else
  2529. {
  2530. Yii::app()->jump->error('无订单信息!',Yii::app()->createUrl('order/index',array("type"=>$typeclassfly[$order_data->classify])));
  2531. }
  2532. $data['order'] = $order_data;
  2533. $sql="SELECT
  2534. o.id,
  2535. count(os.id) AS stunum,
  2536. os.clazz_name,
  2537. os.clazz_id,
  2538. o.total_price,
  2539. o.`status`,
  2540. ob.money,
  2541. o.apply_time,
  2542. o.original_order_id,
  2543. o.create_time
  2544. FROM
  2545. `order` AS o
  2546. LEFT JOIN order_student AS os ON o.id = os.order_id
  2547. LEFT JOIN `order_back` AS ob ON o.id = ob.order_id
  2548. WHERE
  2549. o.original_order_id = {$order_id}
  2550. AND o.school_id
  2551. GROUP BY
  2552. os.order_id,
  2553. os.clazz_id
  2554. ORDER BY
  2555. o.create_time DESC";
  2556. $orderinfo = Yii::app()->db251->createCommand($sql)->queryAll();
  2557. // var_dump($orderinfo);exit;
  2558. $data['back_order']=array();
  2559. foreach($orderinfo as $k=>$v){
  2560. if(!isset($data['back_order'][$v['id']])){
  2561. $data['back_order'][$v['id']]=$v;
  2562. }
  2563. $data['back_order'][$v['id']]['class'][$k]['clazz_name']=$v['clazz_name'];
  2564. $data['back_order'][$v['id']]['class'][$k]['clazz_id']=$v['clazz_id'];
  2565. $data['back_order'][$v['id']]['class'][$k]['stunum']=$v['stunum'];
  2566. }
  2567. $data['is_hava_back']=false;
  2568. foreach($data['back_order'] as $v){
  2569. if($v['status']==0){
  2570. $data['is_hava_back']=true;
  2571. }
  2572. }
  2573. if($data['order']['status']==2){
  2574. $work_flow_id=$order_data['work_flow_id'];
  2575. $wid= CMSWorkflowuserDetail::model()->find(array(
  2576. 'select' =>array('id'),
  2577. 'condition' => 'work_flow_id='.$work_flow_id." and status=2",
  2578. "order"=>"id desc",
  2579. "limit"=>"1"
  2580. ));
  2581. $data['orderaudit']= CMSWorkflowuserAudit::model()->find(array(
  2582. 'select' =>array('remark'),
  2583. 'condition' => 'work_flow_detail_id='.$wid['id'],
  2584. "order"=>"id desc",
  2585. "limit"=>"1"
  2586. ));
  2587. }
  2588. $sql="SELECT
  2589. gt.`code`,
  2590. og.classify,
  2591. o.trial_end_time
  2592. FROM
  2593. `order` AS o
  2594. LEFT JOIN `order_goods` AS og ON og.order_id = o.id
  2595. LEFT JOIN `goods_term` AS gt ON gt.goods_id = og.goods_id
  2596. WHERE
  2597. o.id = {$order_id}
  2598. AND o.school_id
  2599. ";
  2600. $good_code=Yii::app()->db251->createCommand($sql)->queryAll();
  2601. $semmodel=new SSemester();
  2602. $now_code= $semmodel->getSemester($this->semesterId);
  2603. if($good_code[0]['classify']==0){
  2604. if(isset($good_code[0])){
  2605. if($now_code['refer_code']>$good_code[0]['code'])
  2606. $data['is_time_over']=true;
  2607. else
  2608. $data['is_time_over']=false;
  2609. }else{
  2610. $data['is_time_over']=false;
  2611. }
  2612. }else{
  2613. if(time()> strtotime($good_code[0]['trial_end_time'])){
  2614. $data['is_time_over']=true;
  2615. }else{
  2616. $data['is_time_over']=false;
  2617. }
  2618. }
  2619. $sql="select id from order_student where order_id={$order_id} and chargeback=0";
  2620. $ishava_stu=Yii::app()->db251->createCommand($sql)->queryAll();
  2621. if(empty($ishava_stu))
  2622. $data['ishava_stu']=false;
  2623. else
  2624. $data['ishava_stu']=true;
  2625. if($order_data->chargeback==2){
  2626. $apply_time=CMSOrder::model()->find(array(
  2627. 'select' =>array('apply_time'),
  2628. 'condition' => 'original_order_id='.$order_id." and status=1",
  2629. "order"=>"id desc",
  2630. "limit"=>"1"
  2631. ));
  2632. $data['apply_time']=$apply_time['apply_time'];
  2633. }
  2634. $data['goods'] = $order_goods_data;
  2635. $data['goods_se'] = $order_goods_se_data;
  2636. $data['subject'] = $order_goods_subject_data;
  2637. $data['log'] = $order_operate_log_data;
  2638. $data['ordertype'] = $ordertype;
  2639. $this->render('info',$data);
  2640. }
  2641. private function _getMillisecond()
  2642. {
  2643. list($t1, $t2) = explode(' ', microtime());
  2644. return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
  2645. }
  2646. public function actionMorestudent()
  2647. {
  2648. $data = array();
  2649. $order_id = Yii::app()->request->getPost('order_id');
  2650. $pages = Yii::app()->request->getPost('pages');
  2651. $criteria = new CDbCriteria();
  2652. $criteria->addCondition('order_id=:order_id');
  2653. $criteria->params[':order_id'] = $order_id;
  2654. $criteria->limit = 2*$pages;
  2655. $criteria->order = 'id DESC' ;
  2656. $order_student_data = CMSOrderStudent::model()->findAll($criteria);
  2657. if($order_student_data)
  2658. {
  2659. foreach($order_student_data as $v)
  2660. {
  2661. $data[] = $v->attributes;
  2662. }
  2663. echo json_encode(array('status'=>0,'result'=>$data));exit;
  2664. }
  2665. echo json_encode(array('status'=>0,'result'=>''));exit;
  2666. }
  2667. public function actionstudent(){
  2668. $page= Yii::app()->request->getParam("page")>0?Yii::app()->request->getParam("page"):1;
  2669. $data['realname']=$realname= Yii::app()->request->getParam("realname");
  2670. $today=date("Y-m-d H:i:s");
  2671. $goodtype= CMSGoodsType::model()->findAll();
  2672. $data['goodtype']=$goodtype;
  2673. $limit=20;
  2674. $data['page']=$page;
  2675. $start=($page-1)*$limit;
  2676. $where="";
  2677. if($realname){
  2678. $where=" and os.student_name like '%{$realname}%'";
  2679. }
  2680. $semester=new SSemester();
  2681. $nowsem=$semester->getCurrentSemester();
  2682. $sql="SELECT
  2683. student_id,
  2684. student_name,
  2685. group_concat(trial_begin_time) AS trial_begin_time,
  2686. group_concat(trial_end_time) AS trial_end_time,
  2687. group_concat(type_id) AS type_id,
  2688. group_concat(classify) AS classify,
  2689. group_concat(`code`) AS `code`
  2690. FROM
  2691. (
  2692. SELECT
  2693. o.id,
  2694. IFNULL(o.trial_begin_time, '') AS trial_begin_time,
  2695. IFNULL(o.trial_end_time,'') as trial_end_time,
  2696. g.type_id,
  2697. g.classify,
  2698. IFNULL(gt.`code`,0) as `code`,
  2699. os.student_name,
  2700. os.student_id
  2701. FROM
  2702. `order` AS o
  2703. JOIN order_goods AS og ON og.order_id = o.id
  2704. JOIN goods AS g ON g.id = og.goods_id
  2705. left JOIN goods_term AS gt ON g.id = gt.goods_id
  2706. left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id
  2707. JOIN order_student AS os ON os.order_id = o.id
  2708. WHERE
  2709. (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}')
  2710. and o.status=1
  2711. AND o.school_id ={$this->schoolId}
  2712. {$where}
  2713. AND os.chargeback = 0
  2714. ORDER BY
  2715. g.type_id
  2716. ) t
  2717. GROUP BY
  2718. student_name limit {$start},{$limit}";
  2719. $stu_order=Yii::app()->db251->createCommand($sql)->queryAll();
  2720. $termcodes=array();
  2721. foreach($stu_order as $v){
  2722. $classify= explode(",", $v['classify']);
  2723. $code= explode(",", $v['code']);
  2724. foreach($classify as $k=>$cv){
  2725. if($cv==0){
  2726. $termcodes[]=$code[$k];
  2727. }
  2728. }
  2729. }
  2730. $sem=Semester::model()->findAll(array(
  2731. 'select' => 'refer_code,end_time,start_time',
  2732. 'condition' => 'refer_code in (:termcodes)',
  2733. 'params' => array(':termcodes'=> implode(",", $termcodes))
  2734. ));
  2735. $semtime=array();
  2736. foreach($sem as $v){
  2737. $semtime[$v['refer_code']]['end_time']=date("Y-m-d",$v['end_time']);
  2738. $semtime[$v['refer_code']]['start_time']=date("Y-m-d",$v['start_time']);
  2739. }
  2740. $data['semtime']=$semtime;
  2741. if($stu_order){
  2742. $stuids=array();
  2743. foreach($stu_order as $v){
  2744. $stuids[]=$v['student_id'];
  2745. }
  2746. $stuids= implode(",", $stuids);
  2747. $sql="select student_id,student_card from student where student_id in ({$stuids})";
  2748. $student_card=Yii::app()->businessDb->createCommand($sql)->queryAll();
  2749. foreach($stu_order as $k=>$v){
  2750. foreach($student_card as $vv){
  2751. if((string)$vv['student_id']===(string)$v['student_id']){
  2752. $stu_order[$k]['student_card']=$vv['student_card'];
  2753. }
  2754. }
  2755. }
  2756. }
  2757. $data['stu_order']=$stu_order;
  2758. $sql="SELECT
  2759. count(DISTINCT student_id) AS count
  2760. FROM
  2761. (
  2762. SELECT
  2763. o.school_id,
  2764. o.trial_end_time,
  2765. g.type_id,
  2766. os.student_name,
  2767. os.student_id
  2768. FROM
  2769. `order` AS o
  2770. JOIN order_goods AS og ON og.order_id = o.id
  2771. JOIN goods AS g ON g.id = og.goods_id
  2772. JOIN order_student AS os ON os.order_id = o.id
  2773. left JOIN goods_term AS gt ON g.id = gt.goods_id
  2774. left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id
  2775. WHERE
  2776. (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}')
  2777. and o.status=1
  2778. AND o.school_id = {$this->schoolId}
  2779. {$where}
  2780. AND os.chargeback = 0
  2781. ORDER BY
  2782. g.type_id
  2783. ) t";
  2784. $count=Yii::app()->db251->createCommand($sql)->queryRow();
  2785. $data['count']=$count['count'];
  2786. $data['totalpage']= ceil($count['count']/$limit);
  2787. $this->render("student",$data);
  2788. }
  2789. public function actiondelorder(){
  2790. $order_id = safe_replace(Yii::app()->request->getParam('order_id'));
  2791. $type = safe_replace(Yii::app()->request->getParam('type'));
  2792. CMSOrder_back::model()->deleteAll("order_id={$order_id}");
  2793. CMSOrder::model()->deleteAll("id={$order_id}");
  2794. CMSOrderClazz::model()->deleteAll("order_id={$order_id}");
  2795. CMSOrderGoods::model()->deleteAll("order_id={$order_id}");
  2796. CMSOrderGoodsSemester::model()->deleteAll("order_id={$order_id}");
  2797. CMSOrderGoodsSubject::model()->deleteAll("order_id={$order_id}");
  2798. CMSOrderStudent::model()->deleteAll("order_id={$order_id}");
  2799. CMSOrderPay::model()->deleteAll("order_id={$order_id}");
  2800. CMSOrderStudent::model()->deleteAll("order_id={$order_id}");
  2801. CMSOrderOperateLog::model()->deleteAll("order_id={$order_id}");
  2802. $this->redirect($this->createUrl("order/index",array('type'=>$type)));
  2803. }
  2804. }
  2805. //