Exemplo n.º 1
0
 /**
  * 根据衣服ID设置其绑定的多脚数据
  **/
 static function setClothesfootByClothesId($clothesid, $arr)
 {
     $ret = array('status' => 0, 'msg' => '');
     try {
         if (!is_numeric($clothesid) || intval($clothesid) != $clothesid || $clothesid <= 0) {
             throw new Exception('衣服编号有误!');
         }
         if (!isset($arr['high_foot']) || empty($arr['high_foot'])) {
             //如果高脚值不存在或为空就赋值为0
             $arr['high_foot'] = 0;
         }
         if (isset($arr['high_foot']) && (!is_numeric($arr['high_foot']) || intval($arr['high_foot']) != $arr['high_foot'] || $arr['high_foot'] < 0)) {
             //如果高脚值不为数字就去除其修改
             unset($arr['high_foot']);
         }
         if (!isset($arr['middle_foot']) || empty($arr['middle_foot'])) {
             //如果中脚值不存在或为空就赋值为0
             $arr['middle_foot'] = 0;
         }
         if (isset($arr['middle_foot']) && (!is_numeric($arr['middle_foot']) || intval($arr['middle_foot']) != $arr['middle_foot'] || $arr['middle_foot'] < 0)) {
             //如果中脚值不为数字就去除其修改
             unset($arr['middle_foot']);
         }
         if (!isset($arr['low_foot']) || empty($arr['low_foot'])) {
             //如果低脚值不存在或为空就赋值为0
             $arr['low_foot'] = 0;
         }
         if (isset($arr['low_foot']) && (!is_numeric($arr['low_foot']) || intval($arr['low_foot']) != $arr['low_foot'] || $arr['low_foot'] < 0)) {
             //如果低脚值不为数字就去除其修改
             unset($arr['low_foot']);
         }
         if (!isset($arr['def_foot']) || empty($arr['def_foot'])) {
             //如果默认脚值不存在或为空就赋值为0
             $arr['def_foot'] = 0;
         }
         if (isset($arr['def_foot']) && (!is_numeric($arr['def_foot']) || intval($arr['def_foot']) != $arr['def_foot'] || $arr['def_foot'] < 0)) {
             //如果低脚值不为数字就去除其修改
             unset($arr['def_foot']);
         }
         if (count($arr) == 0) {
             throw new Exception('数据有误不需要修改!');
         }
         $ret_foot = self::getClothesfootByClothesId($clothesid);
         //获取衣服的多脚数据
         if ($ret_foot['status'] == 0) {
             //如果未找到数据,就需要添加新数据
             if (empty($arr['high_foot']) && empty($arr['middle_foot']) && empty($arr['low_foot']) && empty($arr['def_foot'])) {
                 throw new Exception('单品未设置多脚数据,不需要添加新数据!');
             }
             //添加多脚数据
             $arr['clothesid'] = $clothesid;
             $set_str = Comm::join_sql_set($arr);
             //将数组转为sql语句
             //var_dump($set_str); exit();
             Yii::app()->db->createCommand("insert into beu_manyfoot set " . $set_str)->execute();
         } else {
             //修改多脚数据
             $set_str = Comm::join_sql_set($arr);
             //将数组转为sql语句
             Yii::app()->db->createCommand("update beu_manyfoot set " . $set_str . ' where id=' . $ret_foot['data']['id'])->execute();
         }
         $ret['status'] = 1;
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     return $ret;
 }