123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020/11/17 0017
- * Time: 15:40
- */
- class ProductDownload extends MyActiveRecord
- {
- //产品类型
- const PRODUCT_TYPE_WB = 1; //错题本
- const PRODUCT_TYPE_ISP = 2; //二步个性化学习宝
- const PRODUCT_TYPE_WB_ISP = 3; //三步个性化学习宝
- const PRODUCT_TYPE_STAGE_REVIEW = 4; //阶段复习个性化学习宝
- const PRODUCT_TYPE_SECOND_RUN = 5; //二轮提分手册
- const PRODUCT_TYPE_HTB = 6; //好题本
- const PRODUCT_TYPE_MICRO = 7; //微产品
- const PRODUCT_TYPE_HOLIDAY_REPORT = 8; //假期报告
- const PRODUCT_TYPE_EN_MRV = 9; //晨读词汇
- const PRODUCT_TYPE_EN_READING = 10; //外刊
- const PRODUCT_TYPE_EN_MAGIC_WORD = 11; //魔法词汇宝
- const PRODUCT_TYPE_EN_INTEREST_WORD = 12; //趣味词汇宝
- const PRODUCT_TYPE_PERSONAL = 30; //个性化学习宝
- const PRODUCT_TYPE_METHOD = 31; //方法宝
- const PRODUCT_TYPE_SPECIAL = 29; //专题宝
- const PRODUCT_TYPE_WRITING = 32; //写作宝
- const PRODUCT_TYPE_HOLIDAY_HOMEWORK = 50; //假期作业
- const PRODUCT_TYPE_WRONG_REFINE = 56; //错题精练
- const PRODUCT_TYPE_CORRECT = 66; //校本纠错本
- const PACK_STATUS_DOING = 0;
- const PACK_STATUS_SUCCESS = 1;
- const PACK_STATUS_FAIL = 2;
- const PACK_STATUS_COPIED = 3;
- const PRODUCT_TYPE_EN_READING_JICHU = 57;
- const PRODUCT_TYPE_EN_READING_WAIKAN = 61;
- const PRODUCT_TYPE_EN_READING_REDIAN = 58;
- //ims产品订单类型
- public static $order_classify = array(
- self::PRODUCT_TYPE_WB => 1,
- self::PRODUCT_TYPE_ISP => 2,
- self::PRODUCT_TYPE_WB_ISP => 3,
- self::PRODUCT_TYPE_STAGE_REVIEW => array(1,2,3),
- self::PRODUCT_TYPE_SECOND_RUN => 5,
- self::PRODUCT_TYPE_HTB => 9,
- self::PRODUCT_TYPE_MICRO => array(1,2,3),
- self::PRODUCT_TYPE_HOLIDAY_REPORT => '',
- self::PRODUCT_TYPE_EN_MRV => array(3, 12),
- self::PRODUCT_TYPE_EN_READING => 6,
- self::PRODUCT_TYPE_EN_MAGIC_WORD => 11,
- self::PRODUCT_TYPE_EN_INTEREST_WORD => 11,
- self::PRODUCT_TYPE_PERSONAL => 30,
- self::PRODUCT_TYPE_METHOD => 31,
- self::PRODUCT_TYPE_SPECIAL => 31,
- self::PRODUCT_TYPE_WRITING => 32,
- self::PRODUCT_TYPE_HOLIDAY_HOMEWORK=>50,
- self::PRODUCT_TYPE_EN_READING_JICHU => 57,
- self::PRODUCT_TYPE_EN_READING_WAIKAN => 61,
- self::PRODUCT_TYPE_EN_READING_REDIAN => 58,
- self::PRODUCT_TYPE_WRONG_REFINE=>56,
- self::PRODUCT_TYPE_CORRECT=>66,
- );
- //打包状态
- public static $pack_status = array(
- self::PACK_STATUS_DOING => '打包中',
- self::PACK_STATUS_SUCCESS => '打包完成',
- self::PACK_STATUS_FAIL => '打包失败',
- self::PACK_STATUS_COPIED => '已复制',
- );
- public static $desc = array(
- 1 => '错题本',
- 30 => '个性化学习宝',
- 31 => '方法宝',
- 29 => '专题宝',
- 50 => '假期作业',
- 56 => '错题精练',
- 66=>'纠错本'
- );
- private $classify;
- public function __construct($product_type)
- {
- $classify_arr = self::$order_classify;
- $this->classify= isset($classify_arr[$product_type]) ? $classify_arr[$product_type] : '';
- }
- /**
- * 获取以生成产品的学生和产品路径
- * @param $table_name
- * @param $unique_column
- * @param $pdf_path_column
- * @param $is_generate_column
- * @param $unique_val
- * @param $studentsIds
- * @param $absentFilter
- * @param $condition
- * @return boolean|array
- */
- public function getGenerateStu($table_name, $unique_column, $pdf_path_column, $is_generate_column, $unique_val, $studentsIds, $absentFilter=false,$condition=array())
- {
- try {
- $studentsArr = array();
- $sql = "select student_id,{$pdf_path_column} from {$table_name} where {$unique_column} = '{$unique_val}' and {$is_generate_column} = 1";
- if($studentsIds){
- $studentsIds = is_array($studentsIds) ? implode(',',$studentsIds) : trim($studentsIds);
- $sql .= " and student_id in ({$studentsIds})";
- }elseif($table_name=='english_week_student'){
- $sql.=" and student_id>0 ";
- }
- if($absentFilter){
- $sql .= " and is_del=0";
- }
- if($condition){
- foreach ($condition as $key=>$item){
- $sql .= sprintf(' and %s=%s',$key,$item);
- }
- }
- $stuArr = $this->getDbConnection()->createCommand($sql)->queryAll();
- if ($stuArr) {
- foreach ($stuArr as $k => $v) {
- $studentsArr['studentIds'][] = $v['student_id'];
- $studentsArr['pathArr'][] = $v["$pdf_path_column"];
- }
- }
- if (!$studentsArr || empty($studentsArr)) {
- return false;
- //echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
- }
- return $studentsArr;
- }catch (\Exception $e){
- return false;
- //echo json_encode(array("success" => 0, "message" => $e->getMessage()));exit();
- }
- }
- /**
- * 获取可以下载的学生
- * @param $students
- * @param $intarr
- * @param $schoolId
- * @return array
- */
- public function getCanDownloadStu($students, $intarr, $schoolId)
- {
- $classify = is_array($this->classify) ? $this->classify : array($this->classify);
- $canDownloadStu = array();
- $basic = imsBasicAuth($schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
- foreach ($classify as $item){
- $intarr['students'] = $students;
- if(empty($item)){
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url_gather"], json_encode($intarr),$basic));
- }else{
- $intarr['classify'] = $item;
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
- }
- if (!$rs) {
- echo json_encode(array("success" => 0, "message" => "接口错误"));exit();
- }
- if ($rs->errCode != "00") {
- echo json_encode(array("success" => 0, "message" => $rs->errMsg));exit();
- }
- if (!empty($rs->data)) {
- $canDownloadStu = array_merge($canDownloadStu,$rs->data);
- }
- }
- if(empty($canDownloadStu)){
- echo json_encode(array("success" => 0, "message" => "请先购买商品"));exit();
- }
- return array_unique($canDownloadStu);
- }
- }
|