Exemple #1
0
 /**
  * 单个删除列表中的数据
  */
 public function actionDelete()
 {
     if ($_GET['id']) {
         switch ($_GET['key']) {
             case 'emp':
                 $return = MakeEmpowerDealer::model()->deleteByPk($_GET['id']);
                 break;
             case 'tech':
                 $return = MakeTechniqueService::model()->deleteByPk($_GET['id']);
                 break;
             case 'cont':
                 $return = MakeContacts::model()->deleteByPk($_GET['id']);
                 break;
             case 'dis':
                 $return = MakeDistributionBusiness::model()->deleteByPk($_GET['id']);
                 break;
             case 'emca':
                 $return = MakeEmpowerCategory::model()->deleteByPk($_GET['id']);
                 MakeEmpowerCategoryRelation::model()->deleteAll("cate_id = {$_GET['id']}");
                 break;
             case 'stor':
                 $return = MakeStorageService::model()->deleteByPk($_GET['id']);
                 break;
         }
     }
     echo $return;
 }
 /**
  * 品类添加页面
  */
 public function actionAddempowercate()
 {
     $user_id = Commonmodel::getOrganID();
     $sql = Goods::GetGoodsByMakerID($user_id);
     $searchsql = $sql;
     if ($_POST['type']) {
         if ($_POST['type'] == 'query') {
             $search = $_POST['search'];
             if ($_GET['id']) {
                 $searchsql .= " and a.id not in (select goods_id from tbl_make_empower_category_relation where cate_id={$_GET['id']})";
             }
             //				if (!empty($search['num'])){
             //					switch ($search['radio']){
             //						case 'OE': $searchsql.=" and a.oe like '%{$search['num']}%'";break;
             //						case 'goods_num': $searchsql.=" and b.goodsno like '%{$search['num']}%'";break;
             //					}
             //				}
             if (!empty($search['cate'])) {
                 $searchsql .= " and a.category_id = '{$search['cate']}'";
             }
             //				$searchsql.="  group by a.id order by a.id desc";
             $result = Yii::app()->db->createCommand($searchsql)->queryAll();
             $post = $_POST['MakeEmpowerCategory'];
             $searchmodel = new MakeEmpowerCategory();
             $searchmodel->cateName = $post['cateName'];
             $searchmodel->remarks = $post['remarks'];
         } else {
             $post = $_POST['MakeEmpowerCategory'];
             $relation_ids = $_POST['goodscatesrelation'];
             if (!empty($relation_ids)) {
                 $inid = implode(',', $relation_ids);
             }
             if (!empty($post['cateName'])) {
                 $post['userID'] = $user_id;
                 if ($post['id']) {
                     $make = MakeEmpowerCategory::model()->findByPk($post['id']);
                     if (!empty($inid)) {
                         MakeEmpowerCategoryRelation::model()->deleteAll("cate_id={$_GET['id']} and goods_id not in ({$inid})");
                     } else {
                         MakeEmpowerCategoryRelation::model()->deleteAll("cate_id={$_GET['id']}");
                     }
                 }
                 if (empty($make)) {
                     $make = new MakeEmpowerCategory();
                 }
                 $make->attributes = $post;
                 $make->save();
                 if (!empty($inid)) {
                     $resultsid = Yii::app()->db->createCommand("select goods_id from tbl_make_empower_category_relation where cate_id = {$make->id}")->queryAll();
                     foreach ($relation_ids as $relation_id) {
                         if (!in_array($relation_id, $resultsid)) {
                             $relamodel = new MakeEmpowerCategoryRelation();
                             $relamodel->goods_id = $relation_id;
                             $relamodel->cate_id = $make->id;
                             $relamodel->save();
                         }
                     }
                 }
                 $this->redirect(array('makemarketing/empowercate'));
             }
         }
     }
     if ($_GET['id']) {
         $model = MakeEmpowerCategory::model()->findByPk($_GET['id']);
         $bindingsql = $sql . " and a.id in (select goods_id from tbl_make_empower_category_relation where cate_id={$_GET['id']})";
         //			$bindingsql.="  group by a.id order by a.id desc";
         $bindingcates = Yii::app()->db->createCommand($bindingsql)->queryAll();
     } elseif ($_POST['type'] == 'query') {
         $model = $searchmodel;
     } else {
         $model = new MakeEmpowerCategory();
     }
     $cate = "select distinct name,id from tbl_goods_category where manufacturer_id={$user_id} group by name order by id desc";
     $cate_data = Yii::app()->db->createCommand($cate)->queryAll();
     $cates = CHtml::listData($cate_data, "id", "name");
     $this->render('addgoodscate', array('model' => $model, 'cates' => $cates, 'result' => $result, 'search' => $search, 'bindingcates' => $bindingcates));
 }