ProductDownload.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/11/17 0017
  6. * Time: 15:40
  7. */
  8. class ProductDownload extends MyActiveRecord
  9. {
  10. //产品类型
  11. const PRODUCT_TYPE_WB = 1; //错题本
  12. const PRODUCT_TYPE_ISP = 2; //二步个性化学习宝
  13. const PRODUCT_TYPE_WB_ISP = 3; //三步个性化学习宝
  14. const PRODUCT_TYPE_STAGE_REVIEW = 4; //阶段复习个性化学习宝
  15. const PRODUCT_TYPE_SECOND_RUN = 5; //二轮提分手册
  16. const PRODUCT_TYPE_HTB = 6; //好题本
  17. const PRODUCT_TYPE_MICRO = 7; //微产品
  18. const PRODUCT_TYPE_HOLIDAY_REPORT = 8; //假期报告
  19. const PRODUCT_TYPE_EN_MRV = 9; //晨读词汇
  20. const PRODUCT_TYPE_EN_READING = 10; //外刊
  21. const PRODUCT_TYPE_EN_MAGIC_WORD = 11; //魔法词汇宝
  22. const PRODUCT_TYPE_EN_INTEREST_WORD = 12; //趣味词汇宝
  23. const PRODUCT_TYPE_PERSONAL = 30; //个性化学习宝
  24. const PRODUCT_TYPE_METHOD = 31; //方法宝
  25. const PRODUCT_TYPE_SPECIAL = 29; //专题宝
  26. const PRODUCT_TYPE_WRITING = 32; //写作宝
  27. const PRODUCT_TYPE_HOLIDAY_HOMEWORK = 50; //假期作业
  28. const PRODUCT_TYPE_WRONG_REFINE = 56; //错题精练
  29. const PRODUCT_TYPE_CORRECT = 66; //校本纠错本
  30. const PACK_STATUS_DOING = 0;
  31. const PACK_STATUS_SUCCESS = 1;
  32. const PACK_STATUS_FAIL = 2;
  33. const PACK_STATUS_COPIED = 3;
  34. const PRODUCT_TYPE_EN_READING_JICHU = 57;
  35. const PRODUCT_TYPE_EN_READING_WAIKAN = 61;
  36. const PRODUCT_TYPE_EN_READING_REDIAN = 58;
  37. //ims产品订单类型
  38. public static $order_classify = array(
  39. self::PRODUCT_TYPE_WB => 1,
  40. self::PRODUCT_TYPE_ISP => 2,
  41. self::PRODUCT_TYPE_WB_ISP => 3,
  42. self::PRODUCT_TYPE_STAGE_REVIEW => array(1,2,3),
  43. self::PRODUCT_TYPE_SECOND_RUN => 5,
  44. self::PRODUCT_TYPE_HTB => 9,
  45. self::PRODUCT_TYPE_MICRO => array(1,2,3),
  46. self::PRODUCT_TYPE_HOLIDAY_REPORT => '',
  47. self::PRODUCT_TYPE_EN_MRV => array(3, 12),
  48. self::PRODUCT_TYPE_EN_READING => 6,
  49. self::PRODUCT_TYPE_EN_MAGIC_WORD => 11,
  50. self::PRODUCT_TYPE_EN_INTEREST_WORD => 11,
  51. self::PRODUCT_TYPE_PERSONAL => 30,
  52. self::PRODUCT_TYPE_METHOD => 31,
  53. self::PRODUCT_TYPE_SPECIAL => 31,
  54. self::PRODUCT_TYPE_WRITING => 32,
  55. self::PRODUCT_TYPE_HOLIDAY_HOMEWORK=>50,
  56. self::PRODUCT_TYPE_EN_READING_JICHU => 57,
  57. self::PRODUCT_TYPE_EN_READING_WAIKAN => 61,
  58. self::PRODUCT_TYPE_EN_READING_REDIAN => 58,
  59. self::PRODUCT_TYPE_WRONG_REFINE=>56,
  60. self::PRODUCT_TYPE_CORRECT=>66,
  61. );
  62. //打包状态
  63. public static $pack_status = array(
  64. self::PACK_STATUS_DOING => '打包中',
  65. self::PACK_STATUS_SUCCESS => '打包完成',
  66. self::PACK_STATUS_FAIL => '打包失败',
  67. self::PACK_STATUS_COPIED => '已复制',
  68. );
  69. public static $desc = array(
  70. 1 => '错题本',
  71. 30 => '个性化学习宝',
  72. 31 => '方法宝',
  73. 29 => '专题宝',
  74. 50 => '假期作业',
  75. 56 => '错题精练',
  76. 66=>'纠错本'
  77. );
  78. private $classify;
  79. public function __construct($product_type)
  80. {
  81. $classify_arr = self::$order_classify;
  82. $this->classify= isset($classify_arr[$product_type]) ? $classify_arr[$product_type] : '';
  83. }
  84. /**
  85. * 获取以生成产品的学生和产品路径
  86. * @param $table_name
  87. * @param $unique_column
  88. * @param $pdf_path_column
  89. * @param $is_generate_column
  90. * @param $unique_val
  91. * @param $studentsIds
  92. * @param $absentFilter
  93. * @param $condition
  94. * @return boolean|array
  95. */
  96. public function getGenerateStu($table_name, $unique_column, $pdf_path_column, $is_generate_column, $unique_val, $studentsIds, $absentFilter=false,$condition=array())
  97. {
  98. try {
  99. $studentsArr = array();
  100. $sql = "select student_id,{$pdf_path_column} from {$table_name} where {$unique_column} = '{$unique_val}' and {$is_generate_column} = 1";
  101. if($studentsIds){
  102. $studentsIds = is_array($studentsIds) ? implode(',',$studentsIds) : trim($studentsIds);
  103. $sql .= " and student_id in ({$studentsIds})";
  104. }elseif($table_name=='english_week_student'){
  105. $sql.=" and student_id>0 ";
  106. }
  107. if($absentFilter){
  108. $sql .= " and is_del=0";
  109. }
  110. if($condition){
  111. foreach ($condition as $key=>$item){
  112. $sql .= sprintf(' and %s=%s',$key,$item);
  113. }
  114. }
  115. $stuArr = $this->getDbConnection()->createCommand($sql)->queryAll();
  116. if ($stuArr) {
  117. foreach ($stuArr as $k => $v) {
  118. $studentsArr['studentIds'][] = $v['student_id'];
  119. $studentsArr['pathArr'][] = $v["$pdf_path_column"];
  120. }
  121. }
  122. if (!$studentsArr || empty($studentsArr)) {
  123. return false;
  124. //echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  125. }
  126. return $studentsArr;
  127. }catch (\Exception $e){
  128. return false;
  129. //echo json_encode(array("success" => 0, "message" => $e->getMessage()));exit();
  130. }
  131. }
  132. /**
  133. * 获取可以下载的学生
  134. * @param $students
  135. * @param $intarr
  136. * @param $schoolId
  137. * @return array
  138. */
  139. public function getCanDownloadStu($students, $intarr, $schoolId)
  140. {
  141. $classify = is_array($this->classify) ? $this->classify : array($this->classify);
  142. $canDownloadStu = array();
  143. $basic = imsBasicAuth($schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  144. foreach ($classify as $item){
  145. $intarr['students'] = $students;
  146. if(empty($item)){
  147. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url_gather"], json_encode($intarr),$basic));
  148. }else{
  149. $intarr['classify'] = $item;
  150. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  151. }
  152. if (!$rs) {
  153. echo json_encode(array("success" => 0, "message" => "接口错误"));exit();
  154. }
  155. if ($rs->errCode != "00") {
  156. echo json_encode(array("success" => 0, "message" => $rs->errMsg));exit();
  157. }
  158. if (!empty($rs->data)) {
  159. $canDownloadStu = array_merge($canDownloadStu,$rs->data);
  160. }
  161. }
  162. if(empty($canDownloadStu)){
  163. echo json_encode(array("success" => 0, "message" => "请先购买商品"));exit();
  164. }
  165. return array_unique($canDownloadStu);
  166. }
  167. }