SProductTemplate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * 产品设置.
  4. * User: chenye
  5. * Date: 2017/11/22
  6. * Time: 11:10
  7. */
  8. class SProductTemplate extends MyActiveRecord {
  9. public static function model($className = __CLASS__)
  10. {
  11. return parent::model($className);
  12. }
  13. public function tableName()
  14. {
  15. return 'product_template';
  16. }
  17. /**
  18. * @return array|null
  19. * 获取所有默认设置数据
  20. */
  21. public function getDefaultPro(){
  22. $criteria = new CDbCriteria();
  23. $criteria->select = 'template_id,product_type';
  24. $criteria->addCondition('is_default=1');
  25. $result = $this->findAll($criteria);
  26. if($result){
  27. $info = getAttributes($result);
  28. }else{
  29. $info = array();
  30. }
  31. return $info;
  32. }
  33. /**
  34. * @return array|null
  35. * 获取产品设置列表
  36. */
  37. public function getProductList($subjectId=3){
  38. $criteria = new CDbCriteria();
  39. $criteria->select = 'template_id,template_name,product_type,target_type,is_default,subject_id';
  40. $criteria->addCondition('subject_id='.$subjectId);
  41. $criteria->order = 'product_type,template_id ASC';
  42. $result = getAttributes($this->findAll($criteria));
  43. return $result;
  44. }
  45. /**
  46. * @param int $id
  47. * @return static
  48. * 获取设置详情
  49. */
  50. public function getSetInfo($id=0,$subjectId=3){
  51. if($id>0 && $id!='NULL'){
  52. $result = $this->findByPk($id);
  53. }else{
  54. $criteria = new CDbCriteria();
  55. $criteria->addCondition('product_type=1 AND is_default=1 AND subject_id='.$subjectId);
  56. $result = $this->find($criteria);
  57. }
  58. return $result;
  59. }
  60. /**
  61. * @param $psType
  62. * @param $name
  63. * @return array
  64. * 添加新的产品
  65. */
  66. public function addNew($psType,$name,$subjectId=3){
  67. $criteria = new CDbCriteria();
  68. $criteria->select = 'ps_id';
  69. $criteria->addCondition("product_type={$psType} AND name='{$name}' AND subject_id='{$subjectId}'");
  70. $result = $this->find($criteria);
  71. if($result){
  72. //重名
  73. return array('status'=>0,'msg'=>"重名");
  74. }else{
  75. $criteria = new CDbCriteria();
  76. $criteria->addCondition("product_type={$psType} AND is_default=1");
  77. $oldResult = $this->find($criteria);
  78. $new = $oldResult->getAttributes();
  79. $ps = new SProductSetting();
  80. $ps->name = $name;
  81. $ps->product_type = $new['product_type'];
  82. $ps->show_map = $new['show_map'];
  83. $ps->show_kp = $new['show_kp'];
  84. $ps->show_top = $new['show_top'];
  85. $ps->show_wrg_origin = $new['show_wrg_origin'];
  86. $ps->show_wrg_analyze = $new['show_wrg_analyze'];
  87. $ps->show_guide = $new['show_guide'];
  88. $ps->st_tuozhan = $new['st_tuozhan'];
  89. $ps->st_wrong = $new['st_wrong'];
  90. $ps->st_reduce = $new['st_reduce'];
  91. $ps->show_level = $new['show_level'];
  92. $ps->create_time = time();
  93. $ps->is_default = 0;
  94. $ps->subject_id=$subjectId;
  95. $bool = $ps->save();
  96. if($bool){
  97. return array('status'=>1,'msg'=>$ps->primaryKey);
  98. }else{
  99. return array('status'=>0,'msg'=>"保存失败");
  100. }
  101. }
  102. }
  103. /**
  104. * @param $psType
  105. * @param $name
  106. * @return string
  107. * 重命名
  108. */
  109. public function rename($psType,$name){
  110. $ti = explode('_',$psType);
  111. $criteria = new CDbCriteria();
  112. $criteria->select = 'ps_id';
  113. $criteria->addCondition("product_type={$ti[0]} AND ps_id!={$ti[1]} AND name='{$name}'");
  114. $result = $this->find($criteria);
  115. if($result){
  116. //重名
  117. return '2';
  118. }else{
  119. //更新
  120. $bool = $this->updateByPk($ti[1],array('name'=>$name));
  121. if($bool!==false){
  122. return '1';
  123. }else{
  124. return '0';
  125. }
  126. }
  127. }
  128. }