Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

158 rindas
5.1 KiB

  1. <?php
  2. namespace common\models;
  3. use admin\util\AdminUtil;
  4. use Yii;
  5. use yii\base\Exception;
  6. /**
  7. * This is the model class for table "cms_category_prod".
  8. *
  9. * @property integer $id
  10. * @property integer $prod_cate_id
  11. * @property integer $cms_cate_id
  12. * @property integer $show_sort
  13. * @property integer $delete_flag
  14. * @property string $create_time
  15. * @property string $update_time
  16. * @property string $update_user
  17. */
  18. class CmsCategoryProd extends \yii\db\ActiveRecord
  19. {
  20. /**
  21. * @inheritdoc
  22. */
  23. public static function tableName()
  24. {
  25. return 'cms_category_prod';
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['prod_cate_id', 'cms_cate_id', 'show_sort', 'delete_flag'], 'integer'],
  34. [['cms_cate_id'], 'required'],
  35. [['create_time', 'update_time'], 'safe'],
  36. [['update_user'], 'string', 'max' => 50],
  37. ];
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'prod_cate_id' => 'Prod Cate ID',
  47. 'cms_cate_id' => 'Cms Cate ID',
  48. 'show_sort' => 'Show Sort',
  49. 'delete_flag' => 'Delete Flag',
  50. 'create_time' => 'Create Time',
  51. 'update_time' => 'Update Time',
  52. 'update_user' => 'Update User',
  53. ];
  54. }
  55. /**
  56. * Function Description:修改产品与左侧菜单绑定关系
  57. * Function Name: uptCmsAdmin
  58. * @param $param
  59. *
  60. * @return bool|int
  61. *
  62. * @author 娄梦宁
  63. */
  64. public function uptCmsAdmin($param){
  65. $transaction = Yii::$app->db->beginTransaction();
  66. if($param['cms_category_id']==-1){
  67. //产品下架
  68. $res=$this->deleteAll(['=','prod_cate_id',$param['pro_cate_id']]);
  69. if($res===false){
  70. $transaction->rollBack();
  71. return false;
  72. }
  73. }elseif($param['cms_category_id']==0){
  74. //新增左侧菜单
  75. $connection=Yii::$app->db;
  76. $istCount=$connection->createCommand()->insert('cms_category', [
  77. 'category_name'=>$param['cms_category_name'],
  78. 'create_time'=>date('Y-m-s H:i:s'),
  79. 'show_sort'=>6,
  80. 'update_user'=>1
  81. ])->execute();
  82. if($istCount!=1){
  83. $transaction->rollBack();
  84. return false;
  85. };
  86. $id=Yii::$app->db->getLastInsertID();
  87. $istCount=$connection->createCommand()->insert('cms_category_prod', [
  88. 'update_user' => AdminUtil::$uid,
  89. 'show_sort' => 1000,
  90. 'cms_cate_id'=>$id,
  91. 'create_time'=>date('Y-m-d H:i:s'),
  92. 'prod_cate_id'=>(int)$param['pro_cate_id'],
  93. ])->execute();
  94. if($istCount!=1){
  95. $transaction->rollBack();
  96. return false;
  97. }
  98. // $cms_category=new CmsCategory();
  99. // $value=[
  100. // 'category_name'=>$param['cms_category_name'],
  101. // 'create_time'=>date('Y-m-s H:i:s'),
  102. // 'show_sort'=>6,
  103. // 'update_user'=>1
  104. // ];
  105. // $cms_category->attributes=$value;
  106. // $res=$cms_category->insert();
  107. // if(!$res){
  108. // $transaction->rollBack();
  109. // return false;
  110. // }
  111. }else{
  112. //修改产品所属菜单
  113. $prod_cate_id=self::find()->select(['count(1) as cnt'])->from(self::tableName())->where(['prod_cate_id'=>$param['pro_cate_id']])->asArray()->one();
  114. if($prod_cate_id['cnt']!=0){//有则修改
  115. $count = self::updateAll(['cms_cate_id'=>$param['cms_category_id'],'update_user'=>AdminUtil::$uid], ['and',['=','prod_cate_id',$param['pro_cate_id']],['=','delete_flag',0]]);
  116. if($count===false){
  117. return false;
  118. };
  119. }else{//没有则新增
  120. $connection=Yii::$app->db;
  121. $istCount=$connection->createCommand()->insert('cms_category_prod', [
  122. 'update_user' => AdminUtil::$uid,
  123. 'show_sort' => 1000,
  124. 'cms_cate_id'=>(int)$param['cms_category_id'],
  125. 'create_time'=>date('Y-m-d H:i:s'),
  126. 'prod_cate_id'=>(int)$param['pro_cate_id'],
  127. ])->execute();
  128. if($istCount!=1){
  129. $transaction->rollBack();
  130. return false;
  131. }
  132. // $values=[
  133. // 'prod_cate_id'=>(int)$param['pro_cate_id'],
  134. // 'cms_cate_id'=>(int)$param['cms_category_id'],
  135. // 'show_sort'=>1000,
  136. // 'create_time'=>date('Y-m-d H:i:s'),
  137. // 'update_user'=>AdminUtil::$uid
  138. // ];
  139. // $this->attributes=$values;
  140. // $res=$this->insert();
  141. // if(!$res){
  142. // throw new Exception('添加出错');
  143. // return false;
  144. // }
  145. }
  146. }
  147. $transaction->commit();
  148. return true;
  149. }
  150. }