params["order_open"]){ echo "该模块尚未开放,敬请期待"; exit; } parent::init(); } public function xiaoshu($num){ if(is_numeric($num)){ $num= explode(".", $num); if(!isset($num[1])){ return $num[0].".00"; }else{ if(strlen($num[1])==1){ return $num[0].".".$num[1]."0"; }else{ return $num[0].".".$num[1]; } } } } public function actionIndex(){ $class_id = safe_replace(Yii::app()->request->getParam('class_id')); $student_id = safe_replace(Yii::app()->request->getParam('student_id')); $status_old=$status = safe_replace(Yii::app()->request->getParam('status')); $semester_id = safe_replace(Yii::app()->request->getParam('semester_id'))?safe_replace(Yii::app()->request->getParam('semester_id')):$this->semesterId; $nianji = safe_replace(Yii::app()->request->getParam('nianji'))?safe_replace(Yii::app()->request->getParam('nianji')):-1; $from = safe_replace(Yii::app()->request->getParam('from')); $classify=0; $type= Yii::app()->request->getParam("type")?Yii::app()->request->getParam("type"):"ordinary"; if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){ Yii::app()->jump->error('参数不正确'); }else{ switch ($type){ case "test": $classify=array(2,20); break; case "all": $classify=1; break; default : $classify=0; break; } } $data = array(); $data['ordertype'] = $type; $order_ids = array(); $class_array = array(); 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'))) { if($semester_id!=="-1"&&($class_id=="-1"||$class_id=="0")){//选了年级并且没选班级 if($nianji=="-1"){ $classs= ClassModel::model()->getClassBySemester($semester_id); }else{ $classs= ClassModel::model()->getClassBySemesternianji($semester_id,$nianji); } if(!empty($classs)){ $class_id=array(); foreach($classs as $v){ $class_id[]=$v['class_id']; } }else{ $class_id=false; } } if($nianji!="-1"&&$class_id==="-1"){ $classarr= ClassModel::model()->findAll("grade=:grade",array(":grade"=>$nianji)); $class_id=array(); foreach($classarr as $v){ $class_id[]=$v['class_id']; } } if($class_id==="-1") { if($status==2) { $status ="0"; }if($status==3) { $status ="2"; } if($status==4) { $status ="3"; } if($classify==0){ $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,array(),$status,$from); }else{ $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,array(),$status,-1); } if($order_data){ foreach($order_data['result'] as $v) { $order_ids[$v['id']] = $v['id']; } } } else { // if(!is_array($class_id)&&$class_id){ // if($type!="test"){ // $order_student_data = CMSOrderStudent::model()->getOrderIDByClassId($class_id,$student_id); // }else{ // $order_student_data = CMSOrderClazz::model()->getOrderIDByClassId($class_id); // } // }else if($class_id){ if($class_id){ if(!is_array($class_id)){ $class_id=array($class_id); } if($type!="test"){ $order_student_data = CMSOrderStudent::model()->getOrderIDInClassId($class_id,$student_id); }else{ $class_ids=""; foreach($class_id as $v){ $class_ids.="'".$v."',"; } $class_ids=substr($class_ids,0,strlen($class_ids)-1); $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.")"; $order_student_data_1=Yii::app()->db251->createCommand($sql)->queryAll(); $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.")"; $order_student_data=Yii::app()->db251->createCommand($sql)->queryAll(); if($order_student_data_1){ $order_student_data= array_merge($order_student_data_1,$order_student_data); } } }else{ $order_student_data=false; } if($order_student_data) { foreach($order_student_data as $v) { $v=(object)$v; $order_ids[$v->order_id] = $v->order_id; } } if($status=="2") { $status ="0"; }if($status=="3") { $status ="2"; }if($status==4) { $status ="3"; } $student_data = StudentInfo::model()->getStudentInClassId($class_id); if($student_data) { $data['class_student'] = $student_data; } if($order_ids) { if($classify==0){ $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,$order_ids,$status,$from); }else{ $order_data = CMSOrder::model()->getPageByOrderIdList($this->schoolId,$classify,$order_ids,$status,-1); } }else { $order_data = array(); } } if($status==2){ $status=3; } $data['search'] = array( 'class_id' => Yii::app()->request->getParam('class_id'), 'student_id' => Yii::app()->request->getParam('student_id'), 'status' => $status_old, 'semester_id' => Yii::app()->request->getParam('semester_id'), 'nianji' => Yii::app()->request->getParam('nianji'), 'from' => Yii::app()->request->getParam('from'), ); $data['student_name'] = StudentInfo::model()->getRealname(Yii::app()->request->getParam('student_id')); }else { $order_data = CMSOrder::model()->getPageList($this->schoolId,$classify); if($order_data) { foreach($order_data['result'] as $v) { $order_ids[$v->id] = $v->id; } } $data['search'] = array(); } $work_flow_id=""; if(isset($order_data['result'])){ foreach($order_data['result'] as $v) { if($v->work_flow_id){ $work_flow_id.=$v->work_flow_id.","; } } $work_flow_id=substr($work_flow_id,0,strlen($work_flow_id)-1); } if($work_flow_id){ $sql="SELECT id FROM `order` WHERE work_flow_id IN ( SELECT work_flow_id FROM work_flow_detail WHERE id IN ( SELECT work_flow_detail_id FROM work_flow_user WHERE work_flow_detail_id IN ( SELECT id FROM work_flow_detail WHERE work_flow_id IN ($work_flow_id) ) ) )"; $isdel= Yii::app()->db251->createCommand($sql)->queryAll(); $data['isdel'] =$isdel; } $data['return'] = $order_data; $order_goods_data = CMSOrderGoods::model()->getGoodsByOrderId($order_ids); if($order_goods_data) { foreach($order_goods_data as $v) { $data['goods'][$v->order_id]['gname'] = $v->goods_name; $data['goods'][$v->order_id]['grade'] = $v->grade; } }else { $data['goods'] = ''; } if($type=="all"){ $orderpay= CMSPayment::model()->getOrderPay($order_ids); foreach($orderpay as $k=>$v){ $data['pay'][$v['order_id']][]=$v; } // var_dump($data['pay']);exit; $orderpay= CMSPayment::model()->getOrderPay($order_ids,-1); foreach($orderpay as $k=>$v){ $data['paystatus'][$v['order_id']][]=$v; } }elseif($type=="test"){ if($order_ids){ $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(); $stunum=array(); $classnum=array(); if($arr){ foreach($arr as $k=>$v){ $classnum[$v['order_id']]=$v['num']; $stunum[$v['order_id']]=$v['stunum']; } } $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"; $arr= Yii::app()->db251->createCommand($sql)->queryAll(); if($arr){ foreach($arr as $k=>$v){ $classnum[$v['order_id']]=$v['num']; $stunum[$v['order_id']]=$v['stunum']; } } $data['classnum']=$classnum; $data['stunum']=$stunum; } }else{ $orderpay= CMSOrderPay::model()->getOrderPay($order_ids); foreach($orderpay as $k=>$v){ $data['pay'][$v['order_id']]=$v; } } $data['semester']=array(); $semester= Semester::model()->findAll(); foreach($semester as $k=>$v){ $data['semester'][$v['semester_id']]=$v; } //获取班级 $class_data = ClassModel::model()->getClassBySemesternianji($semester_id,$nianji); $data['nowsemesterId']=$this->semesterId; if($class_data) { $data['classes'] = $class_data; foreach($class_data as $v) { $class_array[$v->class_id] = $v->class_name; } $data['class_name'] = $class_array; } if($type=='ordinary'){ $this->render("index",$data); }elseif($type=="test"){ $this->render("indextest",$data); }else{ $this->render("indexall",$data); } } public function actionDelete(){ $order_id = Yii::app()->request->getParam('order_id'); $orderinfo=CMSOrder::model()->find("id=:id",array(":id"=>$order_id)); if($orderinfo->type==0){ Yii::app()->jump->error('非学管订单不能取消'); } $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"; $arr=Yii::app()->db251->createCommand($sql)->queryRow(); if(empty($arr)){ if($orderinfo->classify!=1){ $num=CMSOrder::model()->updateAll(array("status"=>3),"id=:id",array(":id"=>$order_id)); }else{ $payarr= CMSPayment::model()->findAll("order_id=:id",array(":id"=>$order_id)); if(count($payarr)>1){ Yii::app()->jump->error('已有'.count($payarr)."期缴费,不能取消订单"); }else{ $payment_status="1_3"; $num=CMSOrder::model()->updateAll(array("status"=>3,"payment_status"=>$payment_status),"id=:id",array(":id"=>$order_id)); CMSPayment::model()->updateAll(array("status"=>3),"id=:id",array(":id"=>$payarr[0]->id)); } } if($num>0){ $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderlogid=="-1"){ Yii::app()->jump->error('logid获取失败,添加失败!'); } $order_operate_log_odj = new CMSOrderOperateLog(); $order_operate_log_odj->id =$orderlogid; $order_operate_log_odj->role_name = '学管'; $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name']; $order_operate_log_odj->info = '取消了订单'; $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time()); $order_operate_log_odj->order_id = $order_id; $order_operate_log_odj->save(); $this->redirect(Yii::app()->request->urlReferrer); }else{ Yii::app()->jump->error('取消失败,系统错误'); } }else{ Yii::app()->jump->error('此订单已开始审核,不能取消'); } } public function actionGetstudent_test(){ $class_id = safe_replace(Yii::app()->request->getPost('class_id')); $goods_id = safe_replace(Yii::app()->request->getPost('goods_id')); $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_id)); $good_type = $goods_data->type_id; if($class_id&&$good_type){ $sql="SELECT oc.clazz_id FROM order_clazz AS oc JOIN `order` AS o ON o.id = oc.order_id JOIN order_goods AS og ON o.id = og.order_id WHERE oc.clazz_id = {$class_id} and og.goods_type_id={$good_type} and o.classify=2 and o.status=1 GROUP BY oc.clazz_id"; $class=Yii::app()->db251->createCommand($sql)->queryAll(); }else{ echo json_encode(array('status'=>3));exit; } if(empty($class)){ $oldclass=array(); $sql="SELECT class_id FROM student_class_relation WHERE class_id != {$class_id} AND student_id IN ( SELECT student_id FROM student_class_relation WHERE class_id = {$class_id} AND STATUS = 0 ) GROUP BY class_id"; $oldclass=SStudentInfo::model()->findAllBySql($sql); //学生如果有转班的话获取转班前的班级 $class_ids=array(); foreach($oldclass as $v){ $class_ids[]=$v['class_id']; } $class_ids[]=$class_id; if(count($class_ids)>1){ $class_ids= implode(",", $class_ids); }else{ $class_ids=$class_ids[0]; } /** * 1、修改: * 背景 以前的试用订单的下单条件是每个学科每个商品每个学校的每个人只可以试用一次,由于2017~2018学年的销售策略变更,改为每个学期可以试用一次(每个学科每个商品每个学校每个人)。 * 需求描述 * 修改学管端下试用订单选择学生时的条件,如果本学期已经试用过则无法加入试用订单。 * 开发时间:20180228 * 作者:刘红伟 * 2、再修改: * * 根据订单开始时间 * 2018-03-06 * * 3、再修改: * 增加多个赛时。 *2018-03-06 */ //查当前班级所在学期 $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id)); if(!$class_data) { echo json_encode(array('status'=>3));exit; } //获取学期 $semester_data = Semester::model()->find('semester_id=:semester_id',array(':semester_id'=>$class_data->semester_id)); if(!$semester_data) { echo json_encode(array('status'=>3));exit; } $start_time = date('Y-m-d H:i:s',$semester_data->start_time); $end_time = date('Y-m-d H:i:s',$semester_data->end_time); if(Yii::app()->crm_login_cache->getValue('zsy_season_time_key')){ $time = time(); $season_time = json_decode(Yii::app()->crm_login_cache->getValue('zsy_season_time_key'),1);//获取redis赛时时间 if($season_time) { foreach ($season_time as $v) { if($time>$v['startTime'] && $time<$v['endTime'])//比对赛时的时间 { $start_time = date('Y-m-d H:i:s',$v['startTime']); $end_time = date('Y-m-d H:i:s',$v['endTime']); } } } } //查试用订单:根据学期的开始时间与结束时间 $sql="SELECT os.clazz_id, os.student_id FROM order_student AS os left JOIN `order` AS o ON o.id = os.order_id left JOIN order_goods AS og ON o.id = og.order_id WHERE os.clazz_id in ({$class_ids}) and og.goods_type_id={$good_type} and o.classify=20 and o.status in (0,1) and o.trial_begin_time >= '".$start_time."' and o.trial_begin_time <= '".$end_time."' GROUP BY os.student_id";//去除转班来的学生....... $orderstu=Yii::app()->db251->createCommand($sql)->queryAll(); $orderstuids=array(); foreach($orderstu as $v){ $orderstuids[$v['student_id']]=$v['student_id']; } $sql="SELECT s.realname, s.student_id FROM student_info AS s JOIN student_class_relation AS scr ON s.student_id = scr.student_id WHERE scr.class_id = {$class_id} and scr.`status`=0"; $stu=SStudentInfo::model()->findAllBySql($sql); $student_ids=array(); foreach($stu as $v) { $student_ids[$v->student_id] = $v->student_id; } $BStudent_model=new BusinessStudent(); $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId); $stu=array(); if($student_ids){ $sql="SELECT s.realname, s.student_id FROM student_info AS s JOIN student_class_relation AS scr ON s.student_id = scr.student_id WHERE scr.class_id = {$class_id} and s.student_id in (". implode(",", $student_ids).") and scr.`status`=0"; $stu=SStudentInfo::model()->findAllBySql($sql); } $stuinfo=array(); $orderstu=array(); foreach($stu as $k=>$v){ $student_ids[]=$v['student_id']; } $BStudent_model=new BusinessStudent(); $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId); if($student_ids){ $sql="SELECT s.realname, s.student_id FROM student_info AS s JOIN student_class_relation AS scr ON s.student_id = scr.student_id WHERE scr.class_id = {$class_id} and scr.student_id in (". implode(",", $student_ids).") and scr.`status`=0"; $stuinfo=array(); $orderstu=array(); foreach($stu as $k=>$v){ if(!isset($orderstuids[$v->student_id])){ $stuinfo[$k]['student_id']=$v['student_id']; $stuinfo[$k]['realname']=$v['realname']; }else{ $orderstu[$k]['student_id']=$v['student_id']; $orderstu[$k]['realname']=$v['realname']; } } echo json_encode(array('status'=>0,'result'=>$stuinfo,"orderstu"=>array()));exit; }else{ echo json_encode(array('status'=>3));exit; } }else{ $stu= SStudentInfo::model()->findAll("class_id=:class_id ",array(":class_id"=>$class_id)); $student_ids=array(); foreach($stu as $k=>$v){ $student_ids[]=$v['student_id']; } $BStudent_model=new BusinessStudent(); $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId); $student_id=array(); foreach($student_ids as $v){ $student_id[$v]=$v; } $orderstu=array(); foreach($stu as $k=>$v){ if(isset($student_id[$v->student_id])){ $orderstu[$k]['student_id']=$v->student_id; $orderstu[$k]['realname']=$v->realname; } } echo json_encode(array('status'=>0,'result'=>array(),"orderstu"=>array()));exit; } } public function actionGetstudent() { $data = array(); $orderid = safe_replace(Yii::app()->request->getPost('orderid')); $class_id = safe_replace(Yii::app()->request->getPost('class_id')); $goods_id = safe_replace(Yii::app()->request->getPost('goods_id')); $student_ids = array(); $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id)); $student_data = array(); $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>0)); if($student_class_data) { foreach($student_class_data as $v) { $student_ids[$v->student_id] = $v->student_id; } } $where=""; if($student_ids){ $where =" and os.student_id in (".implode(",", $student_ids).")"; $student_ids=array(); } $today=date("Y-m-d H:i:s"); $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $sql="SELECT os.student_name, os.student_id FROM `order` AS o JOIN order_goods AS og ON o.id = og.order_id JOIN order_student AS os ON o.id = os.order_id left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id WHERE og.goods_id={$goods_id} and o.status in (0,1) {$where} and os.chargeback=0 AND ( ( o.trial_end_time > '{$today}' OR ogs.`code` = '{$nowsem['refer_code']}' ) AND o.id NOT IN ( SELECT business_key FROM zsy_service WHERE STATUS = 1 ) )"; $order_stuid=Yii::app()->db251->createCommand($sql)->queryAll(); $order_stuids=array(); foreach($order_stuid as $v){ $order_stuids[]=$v['student_id']; } if(!empty($order_stuids)){ $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)); }else{ $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>0)); } if($student_class_data) { foreach($student_class_data as $v) { $student_ids[$v->student_id] = $v->student_id; } $BStudent_model=new BusinessStudent(); $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId); $BStudent_model=new BusinessStudent(); $student_ids=$BStudent_model->getStatus1ByStudentIds($student_ids,$this->schoolId); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $student_data = SStudentInfo::model()->findAll($criteria); unset($criteria); } $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_id)); $orderstu=array(); if($orderid){ $orderstus= CMSOrderStudent::model()->findAll("order_id=:oid and clazz_id=:cid",array(":oid"=>$orderid,":cid"=>$class_id)); foreach($orderstus as $v) { $orderstu[] = $v->attributes; } } if($student_data && $class_data) { if($goods_data) { if($goods_data->apply_class==-1 || $goods_data->apply_class >= $class_data->grade) { foreach($student_data as $v) { $data[] = $v->attributes; } echo json_encode(array('status'=>1,'result'=>$data,"orderstu"=>$orderstu));exit; } // else // { // echo json_encode(array('status'=>2,'result'=>'',"orderstu"=>$orderstu));exit; // } }else { foreach($student_data as $v) { $data[] = $v->attributes; } echo json_encode(array('status'=>1,'result'=>$data,"orderstu"=>$orderstu));exit; } } echo json_encode(array('status'=>0,'result'=>'',"orderstu"=>$orderstu));exit; } public function actionGetstudents() { $data = array(); $class_id = safe_replace(Yii::app()->request->getPost('class_id')); $student_data = StudentInfo::model()->getStudentByClassId($class_id); if($student_data ) { foreach($student_data as $v) { $data[] = $v->attributes; } echo json_encode(array('status'=>1,'result'=>$data));exit; } echo json_encode(array('status'=>0,'result'=>''));exit; } public function actionGetclass() { $data = array(); $semester_id = safe_replace(Yii::app()->request->getPost('semester_id')); $nianji = safe_replace(Yii::app()->request->getPost('nianji')); if(!$nianji){ $clss_data = ClassModel::model()->getClassBySemester($semester_id); }else{ $clss_data = ClassModel::model()->getClassBySemesternianji($semester_id,$nianji); } if($clss_data ) { foreach($clss_data as $v) { $data[] = $v->attributes; } echo json_encode(array('status'=>1,'result'=>$data));exit; } echo json_encode(array('status'=>0,'result'=>''));exit; } public function actionEditOrderback(){ $data = array(); $order_id = Yii::app()->request->getParam('order_id'); $data['old_order_id']=$old_order_id = Yii::app()->request->getParam('old_order_id'); $data['type']= Yii::app()->request->getParam('type'); if(!$order_id){ Yii::app()->jump->error('参数不正确!'); } $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}"; $orderinfo= Yii::app()->db251->createCommand($sql)->queryAll(); $orderinfo=$orderinfo[0]; if($orderinfo['status']!=2&&$orderinfo['status']!=3){ Yii::app()->jump->error('审核不通过订单才能编辑!'); }else{ $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"; $data['classes']=Yii::app()->db251->createCommand($sql)->queryAll(); $data['stu']= CMSOrderStudent::model()->findAll("order_id=:id order by clazz_id asc",array(":id"=>$order_id)); $data['action']="edit"; $data['orderid']=$order_id; $data['orderinfo']=$orderinfo; $this->render('back_add',$data); } } public function actionEditOrder(){ $order_id = Yii::app()->request->getParam('order_id'); if(!$order_id){ Yii::app()->jump->error('参数不正确!'); } $type= isset($_GET['type'])?$_GET['type']:"ordinary"; if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){ Yii::app()->jump->error('参数不正确'); }else{ switch ($type){ case "test": $classify=2; break; case "all": $classify=1; break; default : $classify=0; break; } } $data['type']=$type; $criteria = new CDbCriteria(); $criteria->select="*"; $criteria->addCondition('id=:id'); $criteria->params[':id'] = $order_id; $orderinfo= CMSOrder::model()->find($criteria); if($orderinfo['status']!=2&&$orderinfo['status']!=3){ Yii::app()->jump->error('审核不通过订单才能编辑!'); } $data = array(); $type= isset($_GET['type'])?$_GET['type']:"ordinary"; if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){ Yii::app()->jump->error('参数不正确'); } $data['type']=$type; //获取商品 $goods_type_data = CMSGoodsType::model()->findAll('is_delete=:is_delete',array('is_delete'=>0)); if($goods_type_data) { $data['goods_type'] = $goods_type_data; } if($type=="all"||$type=="test"){ $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' . ' `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 ' . 'left join goods on goods.id=g.goods_id where o.id='.$order_id)->queryRow(); $data['goods_sem']= CMSOrderGoodsSemester::model()->find("order_id=:id",array(":id"=>$order_id)); if($type=="all"){ $data['pay']= Yii::app()->db251->createCommand("select * from payment where order_id=$order_id order by id asc")->queryRow(); $data['payok']= Yii::app()->db251->createCommand("select sum(pay_money) as summoney from payment where order_id=$order_id and status=1")->queryRow(); $data['orderinfo']= array_merge($data['orderinfo'],$data['pay'],$data['payok']); } }elseif($type=="ordinary"){ $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' . ' `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 ' . '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(); } $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)); if($goods_data) { $data['goods_data'] = $goods_data; } //班级 $class_data = ClassModel::model()->getClassBySemesternianji($this->semesterId,$data['orderinfo']['apply_class']); if($class_data) { $data['classes'] = $class_data; } $data['goods_spec_data'] = CMSGoodsSpec::model()->findAll('goods_id=:goods_id ',array(':goods_id'=>$data['orderinfo']['goods_id'])); if($type!="test"){ $data['stu']= CMSOrderStudent::model()->findAll("order_id=:id order by clazz_id asc",array(":id"=>$order_id)); }else{ $criteria = new CDbCriteria(); $criteria->select="*"; $criteria->addCondition('order_id=:orderid'); $criteria->params[':orderid'] = $order_id; $data['class']= CMSOrderClazz::model()->findAll($criteria); $classid=array(); foreach($data['class'] as $v){ $classid[]=$v['clazz_id']; } $criteria = new CDbCriteria(); $criteria->select="*"; $criteria->addNotInCondition('class_id', $classid);//去掉订单里的班级 if($data['orderinfo']['grade']!=-1){ $criteria->addCondition('grade=:grade'); $criteria->params[':grade'] = $data['orderinfo']['grade']; } $data['classes']= ClassModel::model()->findAll($criteria); } if($type!="ordinary"){ $data['sem']= Semester::model()->find(array( 'select' =>array('semester_name'), 'condition' => 'status=1', )); } $data['action']="edit"; $data['orderid']=$order_id; $this->render('add',$data); } public function actionAdd(){ $data = array(); $type= isset($_GET['type'])?$_GET['type']:"ordinary"; if($type!=="test"&&$type!=="all"&&$type!=="ordinary"){ Yii::app()->jump->error('参数不正确'); } $data['type']=$type; if($type!="all"){ $data['sem']= Semester::model()->find(array( 'select' =>array('semester_name'), 'condition' => 'status=1', )); } //获取商品 $goods_type_data = CMSGoodsType::model()->findAll('is_delete=:is_delete',array('is_delete'=>0)); if($goods_type_data) { $data['goods_type'] = $goods_type_data; } //班级 $class_data = ClassModel::model()->getClassBySemester($this->semesterId); if($class_data) { $data['classes'] = $class_data; } //商品规格 /** * 1、修改: *开发者:刘红伟 * 时间:2018-03-06 * 限定订单开始时间与结束时间 * * 修改学管端下试用订单选择学生时的条件,如果本赛季已经试用过则无法加入试用订单; * . 试用订单属于哪个赛季按照试用订单的开始时间计算; * 时间:2018-03-06 * 开发者:刘红伟 */ //获取学期 $semester_data = Semester::model()->find('semester_id=:semester_id',array(':semester_id'=>$this->semesterId)); if(!$semester_data) { echo json_encode(array('status'=>3));exit; } $start_time = date('Y-m-d',$semester_data->start_time); $end_time = date('Y-m-d',$semester_data->end_time); $time = time(); $season_time = json_decode(Yii::app()->crm_login_cache->getValue('zsy_season_time_key'),1);//获取redis赛时时间 if($season_time) { foreach ($season_time as $v) { if($time>$v['startTime'] && $time<$v['endTime'])//比对赛时的时间 { $start_time = date('Y-m-d',$v['startTime']); $end_time = date('Y-m-d',$v['endTime']); } } } //商品关联学科 $data['action']="add"; $data['start_time']=$start_time; $data['end_time']=$end_time; $this->render('add',$data); } public function actionBack_add(){ $data['orderid']=$order_id = Yii::app()->request->getParam('order_id'); $data['type']= Yii::app()->request->getParam('type'); if(!$order_id){ Yii::app()->jump->error('参数不正确!'); } $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"; $data['classes']=Yii::app()->db251->createCommand($sql)->queryAll(); $data['price']=0; if($data['classes']){ $data['price']=$data['classes'][0]['total_price']/$data['classes'][0]['quantity']; } $this->render('back_add',$data); } public function actionget_back_student(){ $class_id = Yii::app()->request->getPost('class_id'); $orderid = Yii::app()->request->getPost('orderid'); $old_order_id = Yii::app()->request->getPost('old_order_id'); if(!$old_order_id){ $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"; }else{ $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"; } $stus=Yii::app()->db251->createCommand($sql)->queryAll(); if($stus){ echo json_encode(array('status'=>1,'result'=>$stus));exit; }else{ echo json_encode(array('status'=>0,'result'=>''));exit; } } public function actionEdit() { $data = array(); //获取商品 $goods_type_data = CMSGoodsType::model()->findAll('is_delete=:is_delete',array('is_delete'=>0)); if($goods_type_data) { $data['goods_type'] = $goods_type_data; } //班级 $class_data = ClassModel::model()->getClassBySemester($this->semesterId); if($class_data) { $data['classes'] = $class_data; } //商品规格 //商品关联学科 $this->render('add',$data); } public function actionGetgoods() { $type_id = Yii::app()->request->getPost('type_id'); $sem= new SSemester(); $nowsem=$sem->getCurrentSemester(); $goods_array = array(); if($type_id){ $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(); if($goods_data) { foreach($goods_data as $v) { $goods_array[] = $v; } echo json_encode(array('status'=>1,'result'=>$goods_array));exit; } } echo json_encode(array('status'=>0,'result'=>''));exit; } public function actionGetsubject() { $goods_id = Yii::app()->request->getPost('goods_id'); $type = Yii::app()->request->getPost('type'); $goods_array = array(); $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_id)); if($goods_data) { $goods_spec_data = CMSGoodsSpec::model()->findAll('goods_id=:goods_id ',array(':goods_id'=>$goods_id)); $goods_tem=CMSGoodsTerm::model()->find('goods_id=:goods_id ',array(':goods_id'=>$goods_id)); $sem= Semester::model()->find('status=1 '); if($goods_spec_data) { foreach($goods_spec_data as $v) { $goods_array[] = $v->attributes; } // if($type!="test"){ // echo json_encode(array('status'=>1,'result'=>$goods_array,'apply_class'=>$goods_data->apply_class));exit; // }else{ $classarr=array(); // if($type=="test"){//找到该学校开过试用订单的班级 // $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"; // // $test_class_id=Yii::app()->db251->createCommand($sql)->queryAll(); // $test_class_ids=array(); // foreach($test_class_id as $v){ // $test_class_ids[]=$v['clazz_id']; // } // } if($goods_data->apply_class!=-1){ if($type=="test"){//去除试用过的班级 $class= ClassModel::model()->findAll("grade=".$goods_data->apply_class." and semester_id=".$sem['semester_id']); }else{ $class= ClassModel::model()->findAll("grade=".$goods_data->apply_class." and semester_id=".$sem['semester_id']); } }else{ if($type=="test"){//去除试用过的班级 $class= ClassModel::model()->findAll("semester_id=".$sem['semester_id']); }else{ $class= ClassModel::model()->findAll("semester_id=".$sem['semester_id']); } } if($class){ foreach($class as $v) { $classarr[] = $v->attributes; } } echo json_encode(array('status'=>1,'result'=>$goods_array,'apply_class'=>$goods_data->apply_class,'class'=>$classarr));exit; // } } } echo json_encode(array('status'=>0,'result'=>'','apply_class'=>''));exit; } public function actionGetsubject_one() { $goods_spec_id = Yii::app()->request->getPost('goods_spec_id'); $goods_spec_data = CMSGoodsSpec::model()->find('id=:id ',array(':id'=>$goods_spec_id))->attributes; if($goods_spec_data) { if($goods_spec_data['promotion_price']) { $goods_spec_data['price'] = $goods_spec_data['promotion_price']; } $goods= CMSGoods::model()->find("id=:id",array(":id"=>$goods_spec_data['goods_id'])); $sem= Semester::model()->find("status=1"); echo json_encode(array('status'=>1,'result'=>$goods_spec_data,"semname"=>$sem['semester_name'],"classify"=>$goods['classify'],"effective_date"=>$goods['effective_date']));exit; } echo json_encode(array('status'=>0,'result'=>''));exit; } public function checktime($paytime){ $time= strtotime($paytime); if(!$time){ $paytime= explode(" ", $paytime); if(count($paytime)!=2){ return false; } $date=$paytime[0]; $time=$paytime[1]; $time= explode(":", $time); if(count($time)!=3){ return false; } if($time[1]=="60"){ $time[1]="59"; }else{ return false; } return $date." ".$time[0].":".$time[1].":".$time[2]; } return $paytime; } public function actionInsert() { $type_id = Yii::app()->request->getPost('type_id'); $goods_id = Yii::app()->request->getPost('goods_id'); $goods_spec_id = Yii::app()->request->getPost('goods_spec_id'); $class_id = Yii::app()->request->getPost('class_id'); $pay_account = Yii::app()->request->getPost('pay_account'); $pay_money = Yii::app()->request->getPost('pay_money'); $pay_time = Yii::app()->request->getPost('pay_time'); if($pay_time){ if(!$pay_time=$this->checktime($pay_time)){ Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index')); } } $apply_class_hide = Yii::app()->request->getPost('apply_class_hide'); $select_grade = Yii::app()->request->getPost('select_grade'); $student_ids = Yii::app()->request->getPost('student_ids'); $class_name = Yii::app()->request->getPost('class_name'); $good_type_name = Yii::app()->request->getPost('good_type_name'); $next_pay_time = Yii::app()->request->getPost('next_pay_time'); $trial_begin_time = Yii::app()->request->getPost('trial_begin_time'); $trial_begin_time_test = Yii::app()->request->getPost('trial_begin_time_test'); $ordertype=Yii::app()->request->getPost('type'); if($apply_class_hide==-1){ $apply_class_hide=$select_grade; } if($ordertype=="ordinary"){ $classify=0; }elseif($ordertype=="all"){ $classify=1; }else{ $classify=20; } if(!$class_id) { Yii::app()->jump->error('请选择班级'); } $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id)); if($class_data) { $apply_class_hide = $class_data->grade; $select_grade = $class_data->grade; } if($classify!=20){//不是试用订单的话 if(!$type_id || !$goods_id || !$goods_spec_id || !$class_id ||$trial_begin_time=="0000-00-00 00:00:00" ) { Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add')); } //图片上传 if(Yii::app()->params["fdfs_open"]){ if($_FILES['pic']['name']!=""&&$_FILES['pic']['type']!=""){ //验证图片 $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1)); $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型 if(!in_array($type, $allow_type)) { Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add')); } $f_file_tmp = $_FILES['pic']['tmp_name']; $f_real_name = $_FILES['pic']['name']; $f_file_name = dirname($f_file_tmp)."/".$f_real_name; @copy($f_file_tmp, $f_file_name); @rename($f_file_tmp, $f_file_name); $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']); $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add')); } @unlink($f_file_name); $file_name = $file_info; }else{ $file_name=""; } }else{ $file_name='aa.jpg'; } }else{//试用订单 if(!$type_id || !$goods_id || !$goods_spec_id ||$trial_begin_time=="0000-00-00 00:00:00" ) { Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add')); } } $student_array = array(); $student_id_array = array(); $spec_id = array(); $spec_array = array(); $student_num = 0; $order_no = $this->_getMillisecond().rand(1,9).rand(1,9).rand(1,9); //订单编号 if($class_id||$classify==20) { $stujson=json_decode($student_ids); $class_ids=array(); foreach($stujson as $k=>$v){ $class_ids[]=$v->classid; } $student_data = StudentInfo::model()->getStudentInClassId($class_ids); $_class_id = 0; if($student_data) { foreach($student_data as $v) { $student_array[$v->student_id] = $v->realname; $student_id_array[$v->student_id] = $v->student_id; $_class_id = $v->class_id; } } $_class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$_class_id)); if($_class_data){ $apply_class_hide = $_class_data->grade; } if(!$student_ids) { Yii::app()->jump->error('请选择学生,重新上传!',Yii::app()->createUrl('order/add')); } $student_num=Yii::app()->request->getPost('stusum'); $student_id_array= json_decode($student_ids); if($goods_spec_id) { $goods_spec_data = CMSGoodsSpec::model()->find('id=:id ',array(':id'=>$goods_spec_id)); if($goods_spec_data) { if($goods_spec_data->promotion_price) { $goods_spec_data->price = $goods_spec_data->promotion_price; } $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_spec_data->goods_id)); $goods_term_data = CMSGoodsTerm::model()->findAll('goods_id=:goods_id',array(':goods_id'=>$goods_spec_data->goods_id)); if($goods_data ) { //$term_data = CMSTerm::model()->find('id=:id',array(':id'=>$goods_data->term_id)); $goods_spec_realtion_data = CMSGoodsSpecRealtion::model()->findAll('goods_spec_id=:goods_spec_id',array(':goods_spec_id'=>$goods_spec_id)); if($goods_spec_realtion_data) { foreach($goods_spec_realtion_data as $v) { $spec_id[$v->subject_id] = $v->subject_id; } } if($spec_id) { $Criteria = new CDbCriteria(); $Criteria->addInCondition('id',$spec_id); $subject_data = CMSSubject::model()->findAll($Criteria); if($subject_data) { foreach($subject_data as $v) { $spec_array[$v->id] = $v->name; } Yii::app()->db251->active = false; //取出商品信息 // $transaction= Yii::app()->db251->beginTransaction();//建立事务 Yii::app()->db251->createCommand("START TRANSACTION")->execute(); try { $order_odj = new CMSOrder(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ throw new CException('接口错误'); } $orderid=$orders_id->errCode=="00"? $orders_id->data->id:"-1"; if($orderid=="-1"){ throw new CException('orderid获取失败,添加失败!'); } $order_odj->id = $orderid; $order_odj->order_no = $order_no; if($classify!=20){ $order_odj->total_price = $student_num*$goods_spec_data->price; }else{ $order_odj->total_price = 0; } // $order_odj->pay_money = $pay_money; $order_odj->openid = $this->coachId; $order_odj->create_time = date('Y-m-d H:i:s',time()); // $order_odj->pay_time = $pay_time; $order_odj->status = 0; // $order_odj->prepay_id = null; $order_odj->type = 1; $order_odj->classify = $classify; $order_odj->grade = $apply_class_hide; $order_odj->school_id = $this->schoolId; $order_odj->school_name = Yii::app()->session['session_school_name']; // $order_odj->pay_account = $pay_account; // $order_odj->pay_cert = $file_name; $order_odj->apply_time = null; if($classify==1){ $order_odj->payment_status ="1_0"; } $order_odj->create_user = Yii::app()->session['coachInfo']['real_name']; $order_odj->quantity = $student_num; if($classify==20){ $order_odj->trial_begin_time = $trial_begin_time_test; }else{ if($goods_data->classify!=0){//不是试用订单但是商品是以有效期结算 if(strtotime($trial_begin_time)== strtotime(date("Y-m-d"))){ $trial_begin_time=date("Y-m-d H:i:s"); $trial_end_time=date("Y-m-d H:i:s",(strtotime($trial_begin_time) + 3600*24*$goods_data->effective_date)); }else{ $trial_end_time=date("Y-m-d",(strtotime($trial_begin_time) + 3600*24*($goods_data->effective_date)-1))." 23:59:59"; } $order_odj->trial_begin_time = $trial_begin_time; $order_odj->trial_end_time = $trial_end_time; } } $order_odj->save(); $order_ids = $order_odj->getOldPrimaryKey(); if($classify!=20){//不是试用订单才有支付信息 $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ throw new CException('接口错误'); } $orderpayid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderpayid=="-1"){ throw new CException('orderpayid获取失败,添加失败!'); } if($ordertype!="all"){ $order_pay=new CMSOrderPay(); $order_pay->id=$orderpayid; $order_pay->order_id=$orderid; if($classify!=20){ $order_pay->pay_money=$pay_money; }else{ $order_pay->pay_money=0; } if($pay_time){ $order_pay->pay_time=$pay_time; } $order_pay->pay_account=$pay_account; $order_pay->pay_cert=$file_name; $order_pay->save(); }else{ $payment=new CMSPayment(); $payment->id=$orderpayid; $payment->order_id=$orderid; $payment->pay_money=$pay_money; if($pay_time){ $payment->pay_time=$pay_time; } $payment->pay_account=$pay_account; $payment->pay_cert=$file_name; $payment->status=0; if($next_pay_time){ $payment->next_pay_time=$next_pay_time; } $payment->save(); } } if($order_ids) { $order_goods_odj = new CMSOrderGoods(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ throw new CException('接口错误!'); } $ordergoodid=$orders_id->errCode=="00"? $orders_id->data->id:"-1"; if($ordergoodid=="-1"){ throw new CException('orderpayid获取失败,添加失败!'); } $order_goods_odj->id = $ordergoodid; $order_goods_odj->goods_name = $goods_data->goods_name; if($classify!=20){ $order_goods_odj->price = $goods_spec_data->price; }else{ $order_goods_odj->price=0; } $order_goods_odj->order_id = $orderid; $order_goods_odj->goods_id = $goods_data->id; $order_goods_odj->goods_type_id = $type_id; $order_goods_odj->goods_type_name = $good_type_name; $order_goods_odj->subject_names = $goods_spec_data->name; $order_goods_odj->grade = $goods_data->apply_class; $order_goods_odj->thumbnail = $goods_data->thumbnail; if($goods_data->classify!=0){ $order_goods_odj->classify = $goods_data->classify; $order_goods_odj->effective_date = $goods_data->effective_date; } $order_goods_odj->save(); if($goods_term_data){ $sql=''; $sqlArr=array(); $i=0; $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id'].(count($goods_term_data)))); if(!$orders_ids||$orders_ids->errCode!="00"){ throw new CException('接口错误4!'); }else{ $orders_ids=$orders_ids->data; } foreach($goods_term_data as $v) { if ($i == 0) { $sql .= "INSERT INTO `order_goods_semester` (`id`,`order_id`,`goods_id`,`code`,`name`)VALUES "; } else { $sql .= ", "; } $ordergoodsemesterid= isset($orders_ids[0])?$orders_ids[0]:-1; array_splice($orders_ids,0,1); if(!$ordergoodsemesterid){ throw new CException('ordergoodsemesterid获取失败,添加失败!'); } $sql.='('.$ordergoodsemesterid.','.$order_ids['id'].','.$v->goods_id.',"'.$v->code.'","'.$v->name.'")'; $i++; if ($i == 200) { $i = 0; $sql.= ";"; $sqlArr[] = $sql; $sql = ""; } } if ($sql) { $sqlArr[] = $sql; } foreach ($sqlArr as $v) { Yii::app()->db251->createCommand($v)->execute(); } } $sql=''; $sqlArr=array(); $i=0; $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id'].(count($goods_spec_realtion_data)>0?count($goods_spec_realtion_data):1))); if(!$orders_ids||$orders_ids->errCode!="00"){ throw new CException('接口错误5!'); }else{ $orders_ids=$orders_ids->data; } foreach($goods_spec_realtion_data as $v) { if ($i == 0) { $sql='INSERT INTO `order_goods_subject` (`id`,`subject_id` ,`subject_name` ,`order_id` ,`goods_id`) VALUES '; } else { $sql .= ", "; } $ordergoodsubjectid= isset($orders_ids[0])?$orders_ids[0]:-1; array_splice($orders_ids,0,1); if(!$ordergoodsubjectid){ throw new CException('ordergoodsubjectid获取失败,添加失败!'); } $sql.='('.$ordergoodsubjectid.','.$v->subject_id.',"'.$spec_array[$v->subject_id].'","'.$order_ids['id'].'","'.$goods_data->id.'")'; $i++; if ($i == 200) { $i = 0; $sql.= ";"; $sqlArr[] = $sql; $sql = ""; } } // $sql = substr($sql,0,-1); if ($sql) { $sqlArr[] = $sql; } foreach ($sqlArr as $v) { Yii::app()->db251->createCommand($v)->execute(); } $order_operate_log_odj = new CMSOrderOperateLog(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ throw new CException('接口错误!'); } $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderlogid=="-1"){ throw new CException('ordergoodsubjectid获取失败,添加失败!'); } $order_operate_log_odj->id =$orderlogid; $order_operate_log_odj->role_name = '学管'; $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name']; if($classify!=20){ $order_operate_log_odj->info = '创建了订单,付款'.$this->xiaoshu($pay_money).'(元)'; }else{ $order_operate_log_odj->info = '创建了试用订单并提交审核'; } $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time()); $order_operate_log_odj->order_id = $order_ids['id']; $order_operate_log_odj->save(); $order_student_sql=''; $insertnum=0; $sqlArr=array(); $i=0; $stu_num=0; foreach($student_id_array as $k=>$v) { $stu_num+=count($v->stus); } $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id'].($stu_num>0?$stu_num:1))); if(!$orders_ids||$orders_ids->errCode!="00"){ throw new CException('接口错误'); }else{ $orders_ids=$orders_ids->data; } $insert_stu=array(); foreach($student_id_array as $k=>$v) { $class_id=$v->classid; $class_name=$v->classname; foreach($v->stus as $s){ if(!isset($insert_stu[$s])){ $insert_stu[$s]=$s; if ($i == 0) { $order_student_sql='INSERT INTO `order_student` (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name`) VALUES '; } else { $order_student_sql .= ", "; } $insertnum++; $ordergoodstudentid= isset($orders_ids[0])?$orders_ids[0]:-1; array_splice($orders_ids,0,1); if(!$ordergoodstudentid){ throw new CException('ordergoodstudentid获取失败,添加失败!'); } $order_student_sql.='('.$ordergoodstudentid.','.$order_ids['id'].',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'")'; $i++; if ($i == 200) { $i = 0; $order_student_sql.= ";"; $sqlArr[] = $order_student_sql; $order_student_sql = ""; } }else{ throw new CException('学生重复,请重新添加!'); } } } } CMSGoods::model()->updateAll(array('buyer_num'=>($goods_data->buyer_num+$student_num)),'id=:id',array(':id'=>$goods_id)); if($insertnum>0){ if ($order_student_sql) { $sqlArr[] = $order_student_sql; } foreach ($sqlArr as $v) { Yii::app()->db251->createCommand($v)->execute(); } } Yii::app()->db251->createCommand("COMMIT")->execute(); $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$orderid)); if($check_order){ if($check_order->errCode!="00"){ throw new CException('添加失败,'.$check_order->errMsg); } }else{ throw new CException('添加失败,接口错误'); } }catch(Exception $e) { Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error($e->getMessage(),Yii::app()->createUrl('order/add')); } $this->redirect($this->createUrl('order/index'."?type=".$ordertype)); } } } } } } Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/add')); } public function actionInsert_back() { $back_account = Yii::app()->request->getPost('back_account'); $back_money = Yii::app()->request->getPost('back_money'); $student_ids = Yii::app()->request->getPost('student_ids'); $old_order_id = Yii::app()->request->getPost('old_order_id'); $type = Yii::app()->request->getPost('type'); if(!$student_ids ) { Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/index')); } $student_array = array(); $student_id_array = array(); $spec_id = array(); $spec_array = array(); $student_num = 0; $order_no = $this->_getMillisecond().rand(1,9).rand(1,9).rand(1,9); //订单编号 $student_id_array= json_decode($student_ids,true); if(!$student_ids) { Yii::app()->jump->error('请选择学生,重新上传!',Yii::app()->createUrl('order/add')); } $class_ids=array(); $stu_num=0; foreach($student_id_array as $k=>$v) { $stu_num+=count($v['stus']); } $orders_ids= json_decode($this->curlget(Yii::app()->params['batch_orders_id']. ($stu_num))); if(!$orders_ids||$orders_ids->errCode!="00"){ Yii::app()->jump->error('接口错误'); }else{ $orders_ids=$orders_ids->data; } foreach($student_id_array as $k=>$v){ $class_ids[]=$v['classid']; } $student_data = StudentInfo::model()->getStudentInClassId($class_ids); if($student_data) { foreach($student_data as $v) { $student_array[$v->student_id] = $v->realname; } } $student_num=Yii::app()->request->getPost('stusum'); Yii::app()->db251->active = false; // 关闭连接 close(); Yii::app()->db251->createCommand("START TRANSACTION")->execute(); try { $order_odj = new CMSOrder(); $old_order_info=$order_odj->getOrderInfo($old_order_id); $back_parice=$old_order_info->total_price/$old_order_info->quantity*$student_num; $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderid=$orders_id->errCode=="00"? $orders_id->data->id:"-1"; if($orderid=="-1"){ Yii::app()->jump->error('orderid获取失败,添加失败!'); } $order_odj->id = $orderid; $order_odj->order_no = $order_no; $order_odj->total_price = $back_parice; $order_odj->openid = $this->coachId; $order_odj->create_time = date('Y-m-d H:i:s',time()); $order_odj->status = 0; $order_odj->type = 1; $order_odj->classify = 3; $order_odj->school_id = $this->schoolId; $order_odj->school_name = Yii::app()->session['session_school_name']; $order_odj->apply_time = null; $order_odj->create_user = Yii::app()->session['coachInfo']['real_name']; $order_odj->quantity = $student_num; $order_odj->original_order_id = $old_order_id; $order_odj->save(); $order_ids = $order_odj->getOldPrimaryKey(); if($order_ids) { $order_back_odj = new CMSOrder_back(); $order_back_odj->order_id=$order_ids['id']; $order_back_odj->account=$back_account; $order_back_odj->money=$back_money; $order_back_odj->save(); $order_student_sql='INSERT INTO `order_student` (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name` )VALUES '; $insertnum=0; foreach($student_id_array as $k=>$v) { $class_id=$v['classid']; $class_name=$v['classname']; foreach($v['stus'] as $s){ $insertnum++; $ordergoodstudentid= isset($orders_ids[0])?$orders_ids[0]:-1; array_splice($orders_ids,0,1); if(!$ordergoodstudentid){ Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); } $order_student_sql.='('.$ordergoodstudentid.','.$order_ids['id'].',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'"),'; } } } if($insertnum>0){ $order_student_sql = substr($order_student_sql,0,-1); Yii::app()->db251->createCommand($order_student_sql)->execute(); } $order_operate_log_odj = new CMSOrderOperateLog(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderlogid=="-1"){ Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!'); } $order_operate_log_odj->id =$orderlogid; $order_operate_log_odj->role_name = '学管'; $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name']; $order_operate_log_odj->info = '创建了退单并提交审核'; $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time()); $order_operate_log_odj->order_id = $order_ids['id']; $order_operate_log_odj->save(); Yii::app()->db251->createCommand("COMMIT")->execute(); $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$orderid)); // $path=Yii::getPathOfAlias('webroot')."/assets/order_interface_log.txt"; // $myfile = fopen($path, "a"); // // $txt = "退单操作,请求".Yii::app()->params['order_interface'].$orderid."接口 orderid:".$orderid." 返回errCode:".$check_order->errCode." \n"; // fwrite($myfile, $txt); // fclose($myfile); if($check_order){ if($check_order->errCode!="00"){ $this->deletedata($orderid); Yii::app()->jump->error('添加失败,'.$check_order->errMsg,Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id)); } }else{ $this->deletedata($orderid); Yii::app()->jump->error('添加失败,接口错误',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id)); } }catch(Exception $e) { Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id)); } $this->redirect($this->createUrl('order/info',array("order_id"=>$old_order_id,"type"=>$type))); Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id)); } public function deletedata($orderid=null){ if($orderid!=NULL){ $orderclazz=new CMSOrderClazz(); $orderclazz->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $order_student=new CMSOrderStudent(); $order_student->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $ordergoodssubject=new CMSOrderGoodsSubject(); $ordergoodssubject->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $ordergoodssemester=new CMSOrderGoodsSemester(); $ordergoodssemester->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $order_operate_log_odj = new CMSOrderOperateLog(); $order_operate_log_odj->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $order_goods_odj = new CMSOrderGoods(); $order_goods_odj->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $payment=new CMSPayment(); $payment->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $order_pay=new CMSOrderPay(); $order_pay->deleteAll("order_id=:oid ",array(":oid"=>$orderid)); $order_odj = new CMSOrder(); $order_odj->deleteAll("id=:oid ",array(":oid"=>$orderid)); } } public function checkid($idarr){ $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id']."?_t=".rand(100000000,999999999))); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orders_id=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orders_id=="-1"){ Yii::app()->jump->error('ID接口错误,返回:'.$orders_id->errCode); } if(isset($idarr[$orders_id])){ $this->checkid($idarr); }else{ return $orders_id; } } public function actionUpdate_back() { $order_id = Yii::app()->request->getPost('orderid'); $type = Yii::app()->request->getPost('type'); $old_order_id = Yii::app()->request->getPost('old_order_id'); $pay_account = Yii::app()->request->getPost('back_account'); $pay_money = Yii::app()->request->getPost('back_money'); $student_ids = Yii::app()->request->getPost('student_ids'); $stusum=Yii::app()->request->getPost('stusum'); Yii::app()->db251->createCommand("START TRANSACTION")->execute(); try { $order_obj=new CMSOrder(); $orderinfo=$order_obj->getOrderInfo($order_id); $total_price=$orderinfo['total_price']/$orderinfo['quantity']*$stusum; $orderdata=array( "total_price"=>$total_price, "quantity"=>$stusum // "status"=>0 ); $order_obj->updateAll($orderdata,"id=:id",array(":id"=>$order_id)); $order_back_obj=new CMSOrder_back(); $orderdata=array(); $orderdata['account']=$pay_account; $orderdata['money']=$pay_money; $order_back_obj->updateAll($orderdata,"order_id=:id",array(":id"=>$order_id)); if($student_ids!=Yii::app()->request->getPost('old_stu_ids')){ $stujson=json_decode($student_ids); $class_ids=array(); $student_array=array(); $student_id_array=array(); foreach($stujson as $k=>$v){ $class_ids[]=$v->classid; } $student_data = StudentInfo::model()->getStudentInClassId($class_ids); if($student_data) { foreach($student_data as $v) { $student_array[$v->student_id] = $v->realname; $student_id_array[$v->student_id] = $v->student_id; } } $order_stu=new CMSOrderStudent(); $order_stu->deleteAll("order_id=:oid ",array(":oid"=>$order_id)); foreach($stujson as $k=>$v) { $class_id=$v->classid; $class_name=$v->classname; $idarr=array(); $newstunum=0; $order_student_sql='INSERT INTO `order_student` (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name` )VALUES '; foreach($v->stus as $s){ $newstunum++; $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $ordergoodstudentid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($ordergoodstudentid=="-1"){ Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); } $order_student_sql.='('.$ordergoodstudentid.','.$order_id.',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'"),'; } $order_student_sql = substr($order_student_sql,0,-1); if($newstunum>0){ Yii::app()->db251->createCommand($order_student_sql)->execute(); } } } Yii::app()->db251->createCommand("COMMIT")->execute(); $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$order_id)); // $path=Yii::getPathOfAlias('webroot')."/assets/order_interface_log.txt"; // $myfile = fopen($path, "a"); // // $txt = "退单操作,请求".Yii::app()->params['order_interface'].$order_id."接口 orderid:".$order_id." 返回errCode:".$check_order->errCode." \n"; // fwrite($myfile, $txt); // fclose($myfile); if($check_order){ if($check_order->errCode!="00"){ // $this->deletedata($order_id); Yii::app()->jump->error('添加失败,'.$check_order->errMsg,Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id)); } }else{ // $this->deletedata($order_id); Yii::app()->jump->error('添加失败,接口错误',Yii::app()->createUrl('order/back_add'."?order_id=".$old_order_id)); } } catch(CException $e) { Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/index')); } $this->redirect($this->createUrl('order/info',array("order_id"=>$old_order_id,"type"=>$type))); } public function actionUpdate() { $order_id = Yii::app()->request->getPost('orderid'); $type_id = Yii::app()->request->getPost('type_id'); $goods_id = Yii::app()->request->getPost('goods_id'); $goods_spec_id = Yii::app()->request->getPost('goods_spec_id'); $class_id = Yii::app()->request->getPost('class_id'); //$students = Yii::app()->request->getPost('students'); $apply_class_hide = Yii::app()->request->getPost('apply_class_hide'); $pay_account = Yii::app()->request->getPost('pay_account'); $pay_money = Yii::app()->request->getPost('pay_money'); $pay_time = Yii::app()->request->getPost('pay_time'); if($pay_time){ if(!$pay_time=$this->checktime($pay_time)){ Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index')); } } $student_ids = Yii::app()->request->getPost('student_ids'); $class_name = Yii::app()->request->getPost('class_name'); $good_type_name = Yii::app()->request->getPost('good_type_name'); $trial_begin_time=Yii::app()->request->getPost('trial_begin_time'); $trial_begin_time_test=Yii::app()->request->getPost('trial_begin_time_test'); $next_pay_time=Yii::app()->request->getPost('next_pay_time'); $ordertype=Yii::app()->request->getPost('type'); if($ordertype=="ordinary"){ $classify=0; }elseif($ordertype=="all"){ $classify=1; }else{ $classify=2; } if($classify!=2){//不是试用订单的话 if(!$type_id || !$goods_id || !$goods_spec_id || !$class_id ||$trial_begin_time=="0000-00-00 00:00:00") { Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add')); } if(!empty($_FILES['pic']['name'])){ //验证图片 $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1)); $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型 if(!in_array($type, $allow_type)) { Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add')); } //图片上传 if(Yii::app()->params["fdfs_open"]){ $f_file_tmp = $_FILES['pic']['tmp_name']; $f_real_name = $_FILES['pic']['name']; $f_file_name = dirname($f_file_tmp)."/".$f_real_name; @copy($f_file_tmp, $f_file_name); @rename($f_file_tmp, $f_file_name); /////////////////////////////////////////////////////////////////////////////////////// $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']); $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add')); } @unlink($f_file_name); $file_name = $file_info; ///////////////////////////////////////////////////////////////////////////////////////// }else{ $file_name='aa.jpg'; } /*$fdfs_obj = new FDFS(Yii::app()->params['fastdfs']); $file_info = $fdfs_obj->fdfs_upload("pic"); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!'); } $file_name = '/'.$file_info['1'].'/'.$file_info['0'];*/ } }else{//试用订单 if(!$type_id || !$goods_id || !$goods_spec_id ||$trial_begin_time=="0000-00-00 00:00:00" ) { Yii::app()->jump->error('填写信息不完整,请填写完整!',Yii::app()->createUrl('order/add')); } } if(!$class_id) { Yii::app()->jump->error('请选择班级'); } $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id)); if($class_data) { $apply_class_hide = $class_data->grade; $select_grade = $class_data->grade; } $student_array = array(); $student_id_array = array(); $spec_id = array(); $spec_array = array(); $student_num = 0; $order_no = $this->_getMillisecond().rand(1,9).rand(1,9).rand(1,9); //订单编号 if($class_id||$classify==2) { if($classify!=2){ // if($classify==0){ // $student_data = StudentInfo::model()->getStudentByClassId($class_id); // if($student_data) // { // foreach($student_data as $v) // { // $student_array[$v->student_id] = $v->realname; // $student_id_array[$v->student_id] = $v->student_id; // } // } // }else{ $stujson=json_decode($student_ids); $class_ids=array(); foreach($stujson as $k=>$v){ $class_ids[]=$v->classid; } $student_data = StudentInfo::model()->getStudentInClassId($class_ids); if($student_data) { foreach($student_data as $v) { $student_array[$v->student_id] = $v->realname; $student_id_array[$v->student_id] = $v->student_id; } } // } }else{ $classinfo = ClassModel::model()->findAll("class_id in ($student_ids)"); $classarr=array(); foreach($classinfo as $k=>$v){ $classarr[$v['class_id']]=$v['class_name']; } } if(!$student_ids) { Yii::app()->jump->error('请选择学生,重新上传!',Yii::app()->createUrl('order/add')); } //if($classify!=1){//普通和试用订单 if($classify==2){//试用订单 $student_id_array = explode(',',$student_ids); $student_num = count($student_id_array); }else{//统订和普通订单 $student_num=Yii::app()->request->getPost('stusum'); $student_id_array= json_decode($student_ids); } if($goods_spec_id) { $goods_spec_data = CMSGoodsSpec::model()->find('id=:id ',array(':id'=>$goods_spec_id)); if($goods_spec_data) { if($goods_spec_data->promotion_price) { $goods_spec_data->price = $goods_spec_data->promotion_price; } $goods_data = CMSGoods::model()->find('id=:id',array(':id'=>$goods_spec_data->goods_id)); $goods_term_data = CMSGoodsTerm::model()->findAll('goods_id=:goods_id',array(':goods_id'=>$goods_spec_data->goods_id)); if($goods_data) { //$term_data = CMSTerm::model()->find('id=:id',array(':id'=>$goods_data->term_id)); $goods_spec_realtion_data = CMSGoodsSpecRealtion::model()->findAll('goods_spec_id=:goods_spec_id',array(':goods_spec_id'=>$goods_spec_id)); if($goods_spec_realtion_data) { foreach($goods_spec_realtion_data as $v) { $spec_id[$v->subject_id] = $v->subject_id; } } if($spec_id) { $Criteria = new CDbCriteria(); $Criteria->addInCondition('id',$spec_id); $subject_data = CMSSubject::model()->findAll($Criteria); if($subject_data) { foreach($subject_data as $v) { $spec_array[$v->id] = $v->name; } //取出商品信息 // $transaction= Yii::app()->db251->beginTransaction();//建立事务 Yii::app()->db251->createCommand("START TRANSACTION")->execute(); try { $order_odj = new CMSOrder(); $orderdata['rder_no'] = $order_no; if($classify!=2){ $orderdata['total_price'] = $student_num*$goods_spec_data->price; }else{ $orderdata['total_price'] = 0; } // $order_odj->pay_money = $pay_money; $orderdata['openid'] = $this->coachId; $orderdata['create_time'] = date('Y-m-d H:i:s',time()); // $order_odj->pay_time = $pay_time; $orderdata['grade'] = $apply_class_hide; // $order_odj->prepay_id = null; $orderdata['type'] = 1; $orderdata['school_id'] = $this->schoolId; $orderdata['school_name'] = Yii::app()->session['session_school_name']; // $order_odj->pay_account = $pay_account; // $order_odj->pay_cert = $file_name; $orderdata['classify'] =$classify; $orderdata['apply_time'] = null; $orderdata['create_user'] = Yii::app()->session['coachInfo']['real_name']; $orderdata['quantity'] = $student_num; if($classify==1){ $orderdata['payment_status'] ="1_0"; } if($classify==2){ $orderdata['trial_begin_time'] = $trial_begin_time_test; }else{ if($goods_data->classify!=0){//商品是以有效期结算 if(strtotime($trial_begin_time)== strtotime(date("Y-m-d"))){ $trial_begin_time=date("Y-m-d H:i:s"); $trial_end_time=date("Y-m-d H:i:s",(strtotime($trial_begin_time) + 3600*24*$goods_data->effective_date)); }else{ $trial_end_time=date("Y-m-d",(strtotime($trial_begin_time) + 3600*24*($goods_data->effective_date)-1))." 23:59:59"; } $orderdata['trial_begin_time'] = $trial_begin_time; $orderdata['trial_end_time'] = $trial_end_time; } } $order_odj->updateAll($orderdata,"id=:id",array(":id"=>$order_id)); if($classify!=2){//不是试用订单才有支付信息 if($classify==0){ $order_pay=new CMSOrderPay(); $orderpaydata['order_id']=$order_id; $orderpaydata['pay_money']=$pay_money; if($pay_time){ $orderpaydata['pay_time']=$pay_time; } $orderpaydata['pay_account']=$pay_account; if(@$file_name){ $orderpaydata['pay_cert']=$file_name; } $order_pay->updateAll($orderpaydata,"order_id=:id",array(":id"=>$order_id)); }else{ $order_pay=new CMSPayment(); $orderpaydata['order_id']=$order_id; $orderpaydata['pay_money']=$pay_money; if($pay_time){ $orderpaydata['pay_time']=$pay_time; } $orderpaydata['pay_account']=$pay_account; if(@$file_name){ $orderpaydata['pay_cert']=$file_name; }if(@$next_pay_time){ $orderpaydata['next_pay_time']=$next_pay_time; } $order_pay->updateAll($orderpaydata,"order_id=:id",array(":id"=>$order_id)); // $paymentid=$order_pay->find("order_id=:id",array(":id"=>$order_id)); } } $order_goods_odj = new CMSOrderGoods(); $ordergoodsdata['goods_name'] = $goods_data->goods_name; if($classify!=2){ $ordergoodsdata['price'] = $goods_spec_data->price; }else{ $ordergoodsdata['price'] = 0; } $ordergoodsdata['order_id'] = $order_id; $ordergoodsdata['goods_id'] = $goods_data->id; $ordergoodsdata['goods_type_id'] = $type_id; $ordergoodsdata['goods_type_name'] = $good_type_name; $ordergoodsdata['subject_names'] = $goods_spec_data->name; $ordergoodsdata['grade'] = $goods_data->apply_class; $ordergoodsdata['thumbnail'] = $goods_data->thumbnail; if($goods_data->classify!=0){//商品是以有效期结算 $ordergoodsdata['classify'] = $goods_data->classify; $ordergoodsdata['effective_date'] = $goods_data->effective_date; } $order_goods_odj->updateAll($ordergoodsdata,"order_id=:id",array(":id"=>$order_id)); if($goods_term_data){ foreach($goods_term_data as $v) { $order_good_sem=new CMSOrderGoodsSemester(); $order_good_sem_data['goods_id']=$v->goods_id; $order_good_sem_data['code']=$v->code; $order_good_sem_data['name']=$v->name; $order_good_sem->updateAll($order_good_sem_data,"order_id=:id",array(":id"=>$order_id)); } } foreach($goods_spec_realtion_data as $v) { $order_good_sub=new CMSOrderGoodsSubject(); $order_good_sub_data['subject_id']=$v->subject_id; $order_good_sub_data['subject_name']=$spec_array[$v->subject_id]; $order_good_sub_data['goods_id']=$goods_data->id; $order_good_sub->updateAll($order_good_sub_data,"order_id=:id",array(":id"=>$order_id)); } $order_operate_log_odj = new CMSOrderOperateLog(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderlogid=="-1"){ Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!'); } $order_operate_log_odj->id =$orderlogid; $order_operate_log_odj->role_name = '学管'; $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name']; $order_operate_log_odj->info = '修改了订单并重新提交审核'; $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time()); $order_operate_log_odj->order_id = $order_id; $order_operate_log_odj->save(); $order_stu=new CMSOrderStudent(); $order_student_sql='INSERT INTO `order_student` (`id`,`order_id` ,`clazz_id` ,`student_id` ,`student_name`,`clazz_name` )VALUES '; if($classify!=2){ // if($classify==0){ // $newstunum=0; // if($student_ids!=Yii::app()->request->getPost('old_stu_ids')){ // $order_stu->deleteAll("order_id=:oid and not student_id in ($student_ids)",array(":oid"=>$order_id)); // // $old_stu_ids=Yii::app()->request->getPost('old_stu_ids'); // // $old_stu_id_arr= explode(",", $old_stu_ids); // // foreach($student_id_array as $v) // { // if(!in_array($v, $old_stu_id_arr)){ // $newstunum++; // $orders_id= json_decode(file_get_contents(Yii::app()->params['orders_id'])); // $ordergoodstudentid=$orders_id->errCode=="00"?sprintf("%1.0f", $orders_id->data->id):"-1"; // if($ordergoodstudentid=="-1"){ // Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); // } // $order_student_sql.='('.$ordergoodstudentid.','.$order_id.',"'.$class_id.'","'.$v.'","'.(isset($student_array[$v])?$student_array[$v]:'').'","'.$class_name.'"),'; // } // } // } // }else{ $newstunum=0; if($student_ids!=Yii::app()->request->getPost('old_stu_ids')){ $order_stu->deleteAll("order_id=:oid ",array(":oid"=>$order_id)); foreach($student_id_array as $k=>$v) { $class_id=$v->classid; $class_name=$v->classname; $idarr=array(); foreach($v->stus as $s){ $newstunum++; $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $ordergoodstudentid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($ordergoodstudentid=="-1"){ Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); } if(isset($idarr[$ordergoodstudentid])){ $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $ordergoodstudentid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($ordergoodstudentid=="-1"){ Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); } } $order_student_sql.='('.$ordergoodstudentid.','.$order_id.',"'.$class_id.'","'.$s.'","'.(isset($student_array[$s])?$student_array[$s]:'').'","'.$class_name.'"),'; $idarr[$ordergoodstudentid]=$ordergoodstudentid; } unset($idarr); } } // } CMSGoods::model()->updateAll(array('buyer_num'=>($goods_data->buyer_num+$student_num)),'id=:id',array(':id'=>$goods_id)); $order_student_sql = substr($order_student_sql,0,-1); if($newstunum>0){ Yii::app()->db251->createCommand($order_student_sql)->execute(); } }else{ $student_class_relation=new SStudentClassRelation(); $orderclazz=new CMSOrderClazz(); $orderclazz->deleteAll("order_id=:oid ",array(":oid"=>$order_id)); $idarr=array(); foreach($classarr as $k=>$v){ $orderclazz=new CMSOrderClazz(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderclazzid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderclazzid=="-1"){ Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); } if(isset($idarr[$orderclazzid])){ $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderclazzid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderclazzid=="-1"){ Yii::app()->jump->error('ordergoodstudentid获取失败,添加失败!'); } } $stunum=$student_class_relation->getRelationsByClassId_Status_0_count($k); $orderclazz->id=$orderclazzid; $orderclazz->order_id=$order_id; $orderclazz->clazz_id=$k; $orderclazz->clazz_name=$v; $orderclazz->students=$stunum; $orderclazz->save(); $idarr[$orderclazzid]=$orderclazzid; unset($orderclazz); } unset($idarr); } Yii::app()->db251->createCommand("COMMIT")->execute(); $check_order= json_decode($this->curlpost(Yii::app()->params['order_interface'].$order_id)); // $path=Yii::getPathOfAlias('webroot')."/assets/order_interface_log.txt"; // $myfile = fopen($path, "a"); // $txt = "编辑操作,请求".Yii::app()->params['order_interface'].$order_id."接口 orderid:".$order_id." 返回errCode:".$check_order->errCode." \n"; // fwrite($myfile, $txt); // fclose($myfile); if($check_order){ if($check_order->errCode!="00"){ Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败,'.$check_order->errMsg); } }else{ Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败,接口错误'); } } catch(CException $e) { Yii::app()->db251->createCommand("ROLLBACK")->execute(); // $transaction->rollBack(); Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/add')); } // Yii::app()->db251->createCommand("END")->execute(); $this->redirect($this->createUrl('order/index'."?type=".$ordertype)); } } } } } } Yii::app()->jump->error('添加失败,重新添加!',Yii::app()->createUrl('order/add')); } public function actionpay(){ $order_id = Yii::app()->request->getParam('order_id'); $order_classify= CMSOrder::model()->find("id=:id",array(":id"=>$order_id)); if($order_classify['classify']!=1){ Yii::app()->jump->error('不是统订订单不能续费',Yii::app()->createUrl('order/index')); } $paymoney= CMSPayment::model()->findAll("order_id=:id and status=1",array(":id"=>$order_id)); $paymoneys=0; foreach($paymoney as $k=>$v){ $paymoneys+=$v['pay_money']; } $this->render("pay",array("order_id"=>$order_id,"paymoneys"=>$paymoneys,"order_classify"=>$order_classify)); } public function actiondopay(){ $pay_account = Yii::app()->request->getPost('pay_account'); $pay_money = Yii::app()->request->getPost('pay_money'); $order_id = Yii::app()->request->getPost('order_id'); $pay_time = Yii::app()->request->getPost('pay_time'); if($pay_time){ if(!$pay_time=$this->checktime($pay_time)){ Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index')); } } $next_pay_time = Yii::app()->request->getPost('next_pay_time'); if($next_pay_time){ if(!$next_pay_time=$this->checktime($next_pay_time)){ Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index')); } } //验证图片 $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1)); $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型 if(!in_array($type, $allow_type)) { Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add')); } //图片上传 $f_file_tmp = $_FILES['pic']['tmp_name']; $f_real_name = $_FILES['pic']['name']; $f_file_name = dirname($f_file_tmp)."/".$f_real_name; @copy($f_file_tmp, $f_file_name); @rename($f_file_tmp, $f_file_name); if(Yii::app()->params["fdfs_open"]){ /////////////////////////////////////////////////////////////////////////////////////// $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']); $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add')); } @unlink($f_file_name); $file_name = $file_info; }else{ ///////////////////////////////////////////////////////////////////////////////////////// $file_name='aa.jpg'; } /*$fdfs_obj = new FDFS(Yii::app()->params['fastdfs']); $file_info = $fdfs_obj->fdfs_upload("pic"); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!'); } $file_name = '/'.$file_info['1'].'/'.$file_info['0'];*/ $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderpayid=$orders_id->errCode=="00"? $orders_id->data->id:"-1"; if($orderpayid=="-1"){ Yii::app()->jump->error('orderpayid获取失败,添加失败!'); } Yii::app()->db251->createCommand("START TRANSACTION")->execute(); $payment=new CMSPayment(); $payment->id=$orderpayid; $payment->order_id=$order_id; $payment->pay_money=$pay_money; if($pay_time){ $payment->pay_time=$pay_time; } $payment->pay_account=$pay_account; $payment->pay_cert=$file_name; $payment->status=0; if($next_pay_time){ $payment->next_pay_time=$next_pay_time; } $payment->save(); $payment_status= CMSOrder::model()->find("id=:id",array(":id"=>$order_id)); $paymentstatus= explode("_", $payment_status['payment_status']); // var_dump(array("payment_status"=>((int)$paymentstatus[0]+1)."_0"));exit; CMSOrder::model()->updateAll(array("payment_status"=>((int)$paymentstatus[0]+1)."_0"),'id='.$order_id); $order_operate_log_odj = new CMSOrderOperateLog(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderlogid=="-1"){ Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!'); } $order_operate_log_odj->id =$orderlogid; $order_operate_log_odj->role_name = '学管'; $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name']; $order_operate_log_odj->info = '第'.((int)$paymentstatus[0]+1) ."期缴费申请提交申请"; $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time()); $order_operate_log_odj->order_id = $order_id; $order_operate_log_odj->save(); Yii::app()->db251->createCommand("COMMIT")->execute(); $check_order= json_decode($this->curlpost(Yii::app()->params['payment_interface'].$orderpayid)); if($check_order){ if($check_order->errCode!="00"){ Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败!'); } }else{ Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败,接口错误'); } $this->redirect(Yii::app()->createUrl('order/index',array('type'=>"all"))); } public function actiondoeditpay(){ $pay_account = Yii::app()->request->getPost('pay_account'); $id = Yii::app()->request->getPost('id'); $pay_money = Yii::app()->request->getPost('pay_money'); $order_id = Yii::app()->request->getPost('orderid'); $pay_time = Yii::app()->request->getPost('pay_time'); if($pay_time){ if(!$pay_time=$this->checktime($pay_time)){ Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index')); } } $next_pay_time = Yii::app()->request->getPost('next_pay_time'); if($next_pay_time){ if(!$next_pay_time=$this->checktime($next_pay_time)){ Yii::app()->jump->error('时间格式错误!',Yii::app()->createUrl('order/index')); } } if($_FILES['pic']['name']!=""){ //验证图片 $type = strtolower(substr($_FILES['pic']['name'],strrpos($_FILES['pic']['name'],'.')+1)); $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型 if(!in_array($type, $allow_type)) { Yii::app()->jump->error('上传图片类型不对,请重新上传!',Yii::app()->createUrl('order/add')); } //图片上传 $f_file_tmp = $_FILES['pic']['tmp_name']; $f_real_name = $_FILES['pic']['name']; $f_file_name = dirname($f_file_tmp)."/".$f_real_name; @copy($f_file_tmp, $f_file_name); @rename($f_file_tmp, $f_file_name); if(Yii::app()->params["fdfs_open"]){ /////////////////////////////////////////////////////////////////////////////////////// $fdfs_odj = FDFS::getInstance(Yii::app()->params['fastdfs']); $file_info = $fdfs_odj->upload_filename1($f_file_name,'',$type); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!',Yii::app()->createUrl('order/add')); } @unlink($f_file_name); $file_name = $file_info; }else{ ///////////////////////////////////////////////////////////////////////////////////////// $file_name='aa.jpg'; } /*$fdfs_obj = new FDFS(Yii::app()->params['fastdfs']); $file_info = $fdfs_obj->fdfs_upload("pic"); if(!$file_info) { Yii::app()->jump->error('上传图片失败,请重新上传!'); } $file_name = '/'.$file_info['1'].'/'.$file_info['0'];*/ } Yii::app()->db251->createCommand("START TRANSACTION")->execute(); $payment=new CMSPayment(); $paymentdata['order_id']=$order_id; $paymentdata['pay_money']=$pay_money; if($pay_time){ $paymentdata['pay_time']=$pay_time; } $paymentdata['pay_account']=$pay_account; if(@$file_name){ $paymentdata['pay_cert']=$file_name; } $paymentdata['status']=0; if($next_pay_time){ $paymentdata['next_pay_time']=$next_pay_time; } // var_dump($paymentdata);echo $id;exit; $payment->updateAll($paymentdata,"id=:id",array(":id"=>$id)); $payment_status= CMSOrder::model()->find("id=:id",array(":id"=>$order_id)); $paymentstatus= explode("_", $payment_status['payment_status']); CMSOrder::model()->updateAll(array("payment_status"=>((int)$paymentstatus[0])."_0"),'id=:id',array(":id"=>$order_id)); $order_operate_log_odj = new CMSOrderOperateLog(); $orders_id= json_decode($this->curlget(Yii::app()->params['orders_id'])); if(!$orders_id){ Yii::app()->jump->error('接口错误'); } $orderlogid=$orders_id->errCode=="00"?$orders_id->data->id:"-1"; if($orderlogid=="-1"){ Yii::app()->jump->error('ordergoodsubjectid获取失败,添加失败!'); } $order_operate_log_odj->id =$orderlogid; $order_operate_log_odj->role_name = '学管'; $order_operate_log_odj->user_name = Yii::app()->session['coachInfo']['real_name']; $order_operate_log_odj->info = '第'.((int)$paymentstatus[0]) ."期缴费申请重新提交申请"; $order_operate_log_odj->create_time = date('Y-m-d H:i:s',time()); $order_operate_log_odj->order_id = $order_id; $order_operate_log_odj->save(); Yii::app()->db251->createCommand("COMMIT")->execute(); $check_order= json_decode($this->curlpost(Yii::app()->params['payment_interface'].$id)); if($check_order){ if($check_order->errCode!="00"){ Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('缴费失败!'); } }else{ Yii::app()->db251->createCommand("ROLLBACK")->execute(); Yii::app()->jump->error('添加失败,接口错误'); } $this->redirect(Yii::app()->createUrl('order/index',array('type'=>"all"))); } public function actionpayedit(){ $id=Yii::app()->request->getParam('id'); $data['pay']=CMSPayment::model()->find("id=:id",array(":id"=>$id)); $data['id']=$id; $order=$data['pay']['order_id']; $order_classify= CMSOrder::model()->find("id=:id",array(":id"=>$order)); if($order_classify['classify']!=1){ Yii::app()->jump->error('不是统订订单不能续费',Yii::app()->createUrl('order/index')); } $data['order_classify']=$order_classify; $paymoney= CMSPayment::model()->findAll("order_id=:id and status=1",array(":id"=>$order)); $paymoneys=0; foreach($paymoney as $k=>$v){ $paymoneys+=$v['pay_money']; } $data['paymoneys']=$paymoneys; $this->render("payedit",$data); } public function actionInfo() { $ordertype= Yii::app()->request->getParam("type")?Yii::app()->request->getParam("type"):"ordinary"; if($ordertype!=="test"&&$ordertype!=="all"&&$ordertype!=="ordinary"){ Yii::app()->jump->error('参数不正确'); } $data = array(); $typeclassfly=array("1"=>"ordinary","2"=>"test",'3'=>"all"); $order_id = Yii::app()->request->getParam('order_id'); $data['order_id']=$order_id; $order_data = CMSOrder::model()->find('id=:id',array(':id'=>$order_id)); if($order_data) { // $order_operate_log_data = CMSOrderOperateLog::model()->findAll('order_id=:order_id',array('order_id'=>$order_id)); $order_goods_data = CMSOrderGoods::model()->find('order_id=:order_id',array('order_id'=>$order_id)); $order_goods_se_data = CMSOrderGoodsSemester::model()->findAll('order_id=:order_id',array('order_id'=>$order_id)); $order_goods_subject_data = CMSOrderGoodsSubject::model()->find('order_id=:order_id',array('order_id'=>$order_id)); if($order_data->classify!=2){ if($ordertype=="ordinary"){ $data['orderpay'] = CMSOrderPay::model()->find('order_id=:id',array(':id'=>$order_id)); }else{ $data['orderpay'] = CMSPayment::model()->findAll('order_id=:id',array(':id'=>$order_id)); } $criteria = new CDbCriteria(); $criteria->select="clazz_id"; $criteria->addCondition('order_id=:order_id'); $criteria->params[':order_id'] = $order_id; $criteria->group="clazz_id"; $classids = CMSOrderStudent::model()->findAll($criteria); $classidarr=array(); foreach($classids as $v){ $classidarr[]=$v['clazz_id']; } $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(); $criteria = new CDbCriteria(); $criteria->select="class_id,class_name"; $criteria->addInCondition("class_id", $classidarr); $classes= ClassModel::model()->findAll($criteria); $stutotal=0; $classinfo=array(); foreach($classes as $k=>$v){ $classinfo[$k]['class_id']=$v->class_id; $classinfo[$k]['class_name']=$v->class_name; foreach($stu as $sk=>$sv){ if((string)$v['class_id']===(string)$sv['clazz_id']){ $stutotal+=$sv['num']; $classinfo[$k]['stunum']=$sv['num']; } } } $data['stutotal']=$stutotal; $data['classes']=$classinfo; }else{ $classes= CMSOrderClazz::model()->findAll("order_id=:order_id",array(":order_id"=>$order_id)); if($classes){ foreach($classes as $k=>$v){ $data['classes'][$k]['class_id']=$v['clazz_id']; $data['classes'][$k]['class_name']=$v['clazz_name']; $data['classes'][$k]['stunum']=$v['students']; } }else{ Yii::app()->jump->error('订单信息不完整!',Yii::app()->createUrl('order/index',array("type"=>$typeclassfly[$order_data->classify]))); } } if(!$order_goods_data || !$order_goods_subject_data || !$order_operate_log_data ) { Yii::app()->jump->error('订单信息不完整!',Yii::app()->createUrl('order/index',array("type"=>$typeclassfly[$order_data->classify]))); } }else { Yii::app()->jump->error('无订单信息!',Yii::app()->createUrl('order/index',array("type"=>$typeclassfly[$order_data->classify]))); } $data['order'] = $order_data; $sql="SELECT o.id, count(os.id) AS stunum, os.clazz_name, os.clazz_id, o.total_price, o.`status`, ob.money, o.apply_time, o.original_order_id, o.create_time FROM `order` AS o LEFT JOIN order_student AS os ON o.id = os.order_id LEFT JOIN `order_back` AS ob ON o.id = ob.order_id WHERE o.original_order_id = {$order_id} AND o.school_id GROUP BY os.order_id, os.clazz_id ORDER BY o.create_time DESC"; $orderinfo = Yii::app()->db251->createCommand($sql)->queryAll(); // var_dump($orderinfo);exit; $data['back_order']=array(); foreach($orderinfo as $k=>$v){ if(!isset($data['back_order'][$v['id']])){ $data['back_order'][$v['id']]=$v; } $data['back_order'][$v['id']]['class'][$k]['clazz_name']=$v['clazz_name']; $data['back_order'][$v['id']]['class'][$k]['clazz_id']=$v['clazz_id']; $data['back_order'][$v['id']]['class'][$k]['stunum']=$v['stunum']; } $data['is_hava_back']=false; foreach($data['back_order'] as $v){ if($v['status']==0){ $data['is_hava_back']=true; } } if($data['order']['status']==2){ $work_flow_id=$order_data['work_flow_id']; $wid= CMSWorkflowuserDetail::model()->find(array( 'select' =>array('id'), 'condition' => 'work_flow_id='.$work_flow_id." and status=2", "order"=>"id desc", "limit"=>"1" )); $data['orderaudit']= CMSWorkflowuserAudit::model()->find(array( 'select' =>array('remark'), 'condition' => 'work_flow_detail_id='.$wid['id'], "order"=>"id desc", "limit"=>"1" )); } $sql="SELECT gt.`code`, og.classify, o.trial_end_time FROM `order` AS o LEFT JOIN `order_goods` AS og ON og.order_id = o.id LEFT JOIN `goods_term` AS gt ON gt.goods_id = og.goods_id WHERE o.id = {$order_id} AND o.school_id "; $good_code=Yii::app()->db251->createCommand($sql)->queryAll(); $semmodel=new SSemester(); $now_code= $semmodel->getSemester($this->semesterId); if($good_code[0]['classify']==0){ if(isset($good_code[0])){ if($now_code['refer_code']>$good_code[0]['code']) $data['is_time_over']=true; else $data['is_time_over']=false; }else{ $data['is_time_over']=false; } }else{ if(time()> strtotime($good_code[0]['trial_end_time'])){ $data['is_time_over']=true; }else{ $data['is_time_over']=false; } } $sql="select id from order_student where order_id={$order_id} and chargeback=0"; $ishava_stu=Yii::app()->db251->createCommand($sql)->queryAll(); if(empty($ishava_stu)) $data['ishava_stu']=false; else $data['ishava_stu']=true; if($order_data->chargeback==2){ $apply_time=CMSOrder::model()->find(array( 'select' =>array('apply_time'), 'condition' => 'original_order_id='.$order_id." and status=1", "order"=>"id desc", "limit"=>"1" )); $data['apply_time']=$apply_time['apply_time']; } $data['goods'] = $order_goods_data; $data['goods_se'] = $order_goods_se_data; $data['subject'] = $order_goods_subject_data; $data['log'] = $order_operate_log_data; $data['ordertype'] = $ordertype; $this->render('info',$data); } private function _getMillisecond() { list($t1, $t2) = explode(' ', microtime()); return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); } public function actionMorestudent() { $data = array(); $order_id = Yii::app()->request->getPost('order_id'); $pages = Yii::app()->request->getPost('pages'); $criteria = new CDbCriteria(); $criteria->addCondition('order_id=:order_id'); $criteria->params[':order_id'] = $order_id; $criteria->limit = 2*$pages; $criteria->order = 'id DESC' ; $order_student_data = CMSOrderStudent::model()->findAll($criteria); if($order_student_data) { foreach($order_student_data as $v) { $data[] = $v->attributes; } echo json_encode(array('status'=>0,'result'=>$data));exit; } echo json_encode(array('status'=>0,'result'=>''));exit; } public function actionstudent(){ $page= Yii::app()->request->getParam("page")>0?Yii::app()->request->getParam("page"):1; $data['realname']=$realname= Yii::app()->request->getParam("realname"); $today=date("Y-m-d H:i:s"); $goodtype= CMSGoodsType::model()->findAll(); $data['goodtype']=$goodtype; $limit=20; $data['page']=$page; $start=($page-1)*$limit; $where=""; if($realname){ $where=" and os.student_name like '%{$realname}%'"; } $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $sql="SELECT student_id, student_name, group_concat(trial_begin_time) AS trial_begin_time, group_concat(trial_end_time) AS trial_end_time, group_concat(type_id) AS type_id, group_concat(classify) AS classify, group_concat(`code`) AS `code` FROM ( SELECT o.id, IFNULL(o.trial_begin_time, '') AS trial_begin_time, IFNULL(o.trial_end_time,'') as trial_end_time, g.type_id, g.classify, IFNULL(gt.`code`,0) as `code`, os.student_name, os.student_id FROM `order` AS o JOIN order_goods AS og ON og.order_id = o.id JOIN goods AS g ON g.id = og.goods_id left JOIN goods_term AS gt ON g.id = gt.goods_id left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id JOIN order_student AS os ON os.order_id = o.id WHERE (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}') and o.status=1 AND o.school_id ={$this->schoolId} {$where} AND os.chargeback = 0 ORDER BY g.type_id ) t GROUP BY student_name limit {$start},{$limit}"; $stu_order=Yii::app()->db251->createCommand($sql)->queryAll(); $termcodes=array(); foreach($stu_order as $v){ $classify= explode(",", $v['classify']); $code= explode(",", $v['code']); foreach($classify as $k=>$cv){ if($cv==0){ $termcodes[]=$code[$k]; } } } $sem=Semester::model()->findAll(array( 'select' => 'refer_code,end_time,start_time', 'condition' => 'refer_code in (:termcodes)', 'params' => array(':termcodes'=> implode(",", $termcodes)) )); $semtime=array(); foreach($sem as $v){ $semtime[$v['refer_code']]['end_time']=date("Y-m-d",$v['end_time']); $semtime[$v['refer_code']]['start_time']=date("Y-m-d",$v['start_time']); } $data['semtime']=$semtime; if($stu_order){ $stuids=array(); foreach($stu_order as $v){ $stuids[]=$v['student_id']; } $stuids= implode(",", $stuids); $sql="select student_id,student_card from student where student_id in ({$stuids})"; $student_card=Yii::app()->businessDb->createCommand($sql)->queryAll(); foreach($stu_order as $k=>$v){ foreach($student_card as $vv){ if((string)$vv['student_id']===(string)$v['student_id']){ $stu_order[$k]['student_card']=$vv['student_card']; } } } } $data['stu_order']=$stu_order; $sql="SELECT count(DISTINCT student_id) AS count FROM ( SELECT o.school_id, o.trial_end_time, g.type_id, os.student_name, os.student_id FROM `order` AS o JOIN order_goods AS og ON og.order_id = o.id JOIN goods AS g ON g.id = og.goods_id JOIN order_student AS os ON os.order_id = o.id left JOIN goods_term AS gt ON g.id = gt.goods_id left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id WHERE (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}') and o.status=1 AND o.school_id = {$this->schoolId} {$where} AND os.chargeback = 0 ORDER BY g.type_id ) t"; $count=Yii::app()->db251->createCommand($sql)->queryRow(); $data['count']=$count['count']; $data['totalpage']= ceil($count['count']/$limit); $this->render("student",$data); } public function actiondelorder(){ $order_id = safe_replace(Yii::app()->request->getParam('order_id')); $type = safe_replace(Yii::app()->request->getParam('type')); CMSOrder_back::model()->deleteAll("order_id={$order_id}"); CMSOrder::model()->deleteAll("id={$order_id}"); CMSOrderClazz::model()->deleteAll("order_id={$order_id}"); CMSOrderGoods::model()->deleteAll("order_id={$order_id}"); CMSOrderGoodsSemester::model()->deleteAll("order_id={$order_id}"); CMSOrderGoodsSubject::model()->deleteAll("order_id={$order_id}"); CMSOrderStudent::model()->deleteAll("order_id={$order_id}"); CMSOrderPay::model()->deleteAll("order_id={$order_id}"); CMSOrderStudent::model()->deleteAll("order_id={$order_id}"); CMSOrderOperateLog::model()->deleteAll("order_id={$order_id}"); $this->redirect($this->createUrl("order/index",array('type'=>$type))); } } //