/**
  * 将接收请求中的所有数据添加到数据库对应的表中
  * @param mixed|string $requestDate post请求发送过来的所有数据
  * @return bool|mixed
  */
 public function add($requestDate)
 {
     //调用父类add方法保存本表数据
     $id = parent::add();
     if ($id === false) {
         //提示错误信息
         $this->error = '添加数据失败!';
         return false;
     }
     //        $inputtime=time();
     //        $result_inputtime=parent::save(array('id'=>$id,'inputtime'=>$inputtime));
     //        if($result_inputtime===false){
     //            //提示错误信息
     //            $this->error = '添加时间失败!';
     //            return false;
     //        }
     //创建基础模型类操作article_content表
     $articleContentModel = M('ArticleContent');
     //添加数据
     $result = $articleContentModel->add(array('article_id' => $id, 'content' => $requestDate['content']));
     if ($result === false) {
         //提示错误信息
         $this->error = '添加文章内容失败!';
         return false;
     }
     return $id;
 }
Example #2
0
 public function add($resource)
 {
     //将多选框选中的值相或后保存起来(二进制办法)
     $this->startTrans();
     $this->data['goods_status'] = $this->handelGoodStatus($this->data['goods_status']);
     $id = parent::add();
     if (!$id) {
         $this->error = "添加商品失败!";
         $this->rollback();
         return false;
     }
     //计算出当前的货号,修改到数据库中
     $sn = date('Ymd') . str_pad($id, 9, '0', STR_PAD_LEFT);
     $res = parent::save(array('id' => $id, 'sn' => $sn));
     if (!$res) {
         $this->error = "添加货号失败!";
         $this->rollback();
         return false;
     }
     $intr['intro'] = $resource['intro'];
     $intr['goods_id'] = $id;
     //将数据保存到表goods_intro里面
     $goodsintro = M('goods_intro');
     $result = $goodsintro->add($intr);
     if (!$result) {
         $this->error = "添加商品简介失败!";
         $this->rollback();
         return false;
     }
     $this->commit();
     return $id;
 }
 /**
  * 将create收集到的请求中的数据保存到goods表中,
  * 同时也需要将post请求中的intro数据保存到goods_intro表
  */
 public function add($requestData)
 {
     /*
       requestData包含: 请求中的所有数据
       $this->data包含: 包含goods表中需要的数据
     */
     //>>因为多次操作数据库并同时操作多张表,因此开启事务机制
     $this->startTrans();
     //开启事务
     //>>调用this->handleGoodsStatus方法对商品状态goods_status复选框进行数据处理
     $this->handleGoodsStatus();
     //将create收集的this->data数据保存到goods表中,返回数据插入的id
     $id = parent::add();
     if ($id === false) {
         $this->rollback();
         //事务回滚
         return false;
     }
     //>>通过返回的id保存商品货号sn到goods数据表中,自定义的sn格式(年月日加上9位数字)str_pad — 使用另一个字符串填充字符串为指定长度
     $sn = date('Ymd') . str_pad($id, 9, '0', STR_PAD_LEFT);
     $result_sn = parent::save(array('id' => $id, 'sn' => $sn));
     if ($result_sn === false) {
         $this->error = "保存货号失败!";
         $this->rollback();
         //事务回滚
         return false;
     }
     //>>将intro简介描述保存到goods_intro表中
     $goodsIntroModel = M('GoodsIntro');
     $result = $goodsIntroModel->add(array('goods_id' => $id, 'intro' => $requestData['intro']));
     if ($result === false) {
         $this->error = "保存商品描述失败!";
         $this->rollback();
         //事务回滚
         return false;
     }
     //>>保存商品的会员价格
     $result = $this->handleMemberPrice($id, $requestData['memberPrices']);
     //添加数据失败返回false
     if ($result === false) {
         return false;
     }
     //>>保存商品相片到相册表
     $result = $this->handleGoodsPhoto($id, $requestData['goods_photo_paths']);
     //添加数据失败返回false
     if ($result === false) {
         return false;
     }
     //>>保存相关文章数据到相册表
     $result = $this->handleGoodsArticle($id, $requestData['article_ids']);
     //添加数据失败返回false
     if ($result === false) {
         return false;
     }
     //事务提交
     $this->commit();
     //返回添加商品的id
     return $id;
 }
 /**
  * @return bool|mixed
  * 添加
  */
 public function add($requestrows = '')
 {
     //开启事务
     $this->startTrans();
     //计算商品状态值并进行添加
     $this->handleGoodsStatus();
     $id = parent::add();
     if ($id === false) {
         $this->rollback();
         return false;
     }
     //生成货号并进行添加
     $sn = date('Ymd') . str_pad($id, 8, '0', STR_PAD_LEFT);
     $result = parent::save(array('sn' => $sn, 'id' => $id));
     if ($result === false) {
         $this->rollback();
         return false;
     }
     //对商品描述进行添加(单独的一张表)
     $result = M('goods_intro')->add(array('goods_id' => $id, 'intro' => $requestrows['intro']));
     if ($result === false) {
         $this->rollback();
         return false;
     }
     //对商品的相册进行添加(单独的一张表)
     $GoodsGallery = D('GoodsGallery');
     $arr = array();
     foreach ($requestrows['gallery_path'] as $value) {
         $arr[] = array('goods_id' => $id, 'path' => $value);
     }
     if (!empty($arr)) {
         $result = $GoodsGallery->addAll($arr);
     }
     if ($result === false) {
         $this->rollback();
         return false;
     }
     //对商品关联文章进行添加,添加到goods_article表中
     $arr = array();
     foreach ($requestrows['article_id'] as $row) {
         $arr[] = array('goods_id' => $id, 'article_id' => $row);
     }
     if (!empty($arr)) {
         $result = M('goods_article')->addALL($arr);
     }
     if ($result === false) {
         $this->rollback();
         return false;
     }
     //对会员价格进行添加
     $result = $this->handleGoodsMemberPrice($id, $requestrows);
     if ($result === false) {
         $this->rollback();
         return false;
     }
     $this->commit();
     return $id;
 }
Example #5
0
 public function add($requestData)
 {
     //        unset($requestData['id']);//添加时去掉隐藏域中提交过来的id
     //          dump($requestData);
     //           exit;
     //$requestData中包含了提交表单中所有请求数据  而create中值收集的this_data即对应表中的数据
     // 插入两个表数据 是一个整体工作 放事务里
     $this->startTrans();
     //开启事务
     // 1.整理goods_status中的数据 将$this->data中的数据保存到Goods表中 返回值为添加后id
     $this->handleGoodsStatus();
     $id = parent::add();
     if ($id === false) {
         $this->rollback();
         //回滚事务
         return false;
     }
     //2.计算出当前货号更行到数据表中 货号是根据生成id和日期自动生成
     $sn = date('Ymd') . str_pad($id, 9, "0", STR_PAD_LEFT);
     //此函数用于补全一个字符为多少位长度参数(原数,几位,用什么补,在那边补)
     //修改 货号在表中
     $rst = parent::save(array('id' => $id, 'sn' => $sn));
     if ($rst === false) {
         //保存不成功
         $this->error = '保存货号失败!!!';
         $this->rollback();
         //回滚事务
         return false;
     }
     //3.将商品描述保存到goods_Intro表中
     $goodsintromodel = M('GoodsIntro');
     $result1 = $goodsintromodel->add(array('goods_id' => $id, 'intro' => $requestData['intro']));
     if ($result1 === false) {
         $this->error = '保存商品描述失败';
         $this->rollback();
         //回滚事务
         return false;
     }
     //4.添加商品对应会员价格
     $result2 = $this->handleMemberprice($id, $requestData['memberlevelprice']);
     if ($result2 === false) {
         $this->rollback();
         return false;
     }
     //5. 添加商品相片
     $result3 = $this->handleGoodsPhoto($id, $requestData['goods_photo_paths']);
     //        dump($requestData['goods_photo_paths']);
     //            exit;
     if ($result3 === false) {
         $this->rollback();
         return false;
     }
     $this->commit();
     // 全部成功 提交事务
     return $id;
     //返回$id
 }
Example #6
0
 /**
  * 需求:请求的数据不仅能保存到goods表中,也能保存到其他表中
  * baseModel中的add方法只收集goods表中的数据,不满足需求,因此需要
  * 重写add()方法。
  */
 public function add($requestData)
 {
     //requestData包含:请求中的所有数据
     //$this->data包含:goods表中需要的数据,其他数据会过滤
     //        dump($requestData);
     //        exit;
     //        dump($this->data);
     //        exit;
     //请求中的商品状态
     $this->startTrans();
     //开启事务
     $this->handleGoodsStatus();
     //>>1.将this->data中的数据保存到goods表中
     $id = parent::add();
     if ($id == false) {
         return false;
     }
     //计算出当前商品的货号,将货号更新到当前商品中
     $sn = date('Ymd') . str_pad($id, 9, "0", STR_PAD_LEFT);
     $result = parent::save(array('id' => $id, 'sn' => $sn));
     if ($result === false) {
         $this->error = '保存货号失败';
         $this->rollback();
         //回滚事务
         return false;
     }
     //return;//检测事务是否开启
     //>>2.将商品描述保存到goods_intro中
     $goodsIntroModel = M('GoodsIntro');
     $result = $goodsIntroModel->add(array('goods_id' => $id, 'intro' => $requestData['intro']));
     if ($result === false) {
         $this->error = '保存商品描述失败';
         return false;
     }
     //>>3.保存商品的会员价格
     //        dump($requestData);
     //        exit;
     $result = $this->handleMemberPrice($id, $requestData['memberPrices']);
     if ($result === false) {
         $this->rollback();
         return false;
     }
     //>>4.处理商品照片
     $result = $this->handleGoodsPhoto($id, $requestData['goods_photo_paths']);
     if ($result === false) {
         return false;
     }
     //>>5.处理相关文章
     $result = $this->handleGoodsArticle($id, $requestData['article_ids']);
     if ($result === false) {
         return false;
     }
     $this->commit();
     //提交事务
     return $id;
 }
 public function add($gatherData)
 {
     //开启事物
     $this->startTrans();
     //开启事务
     //处理商品状态的数据  调用自己封装的status函数
     $this->goods_status_method($this->data['goods_status']);
     $id = parent::add();
     //一定要调用parent上的add,  因为先保存后才有id的值
     if ($id === false) {
         $this->rollback();
         //事物回滚
         return false;
     }
     //根据id生成货号
     //>>2.准备货号 并且将货号更新到数据库中       日期+八位的id   20151107000000id
     $sn = date('Ymd') . str_pad($id, 8, "0", STR_PAD_LEFT);
     $result = parent::save(array('sn' => $sn, 'id' => $id));
     if ($result === false) {
         $this->rollback();
         //事物回滚
         return false;
     }
     //保存会员的信息
     if (!empty($gatherData['memberprice']) && !empty($gatherData['member_level_id'])) {
         $resultMemberPrice = $this->memberPriceFunction($id, $gatherData['memberprice'], $gatherData['member_level_id']);
         if ($resultMemberPrice === false) {
             return false;
         }
     }
     //保存商品的描述信息
     if (!empty($gatherData['intro'])) {
         $resultIntro = $this->introFunction($id, $gatherData['intro']);
         if ($resultIntro === false) {
             return false;
         }
     }
     //保存上传相册的图片galler
     if (!empty($gatherData['path'])) {
         $resultGaller = $this->gallerFunction($id, $gatherData['path']);
         if ($resultGaller === false) {
             return false;
         }
     }
     //保存上传的文章
     if (!empty($gatherData['article_id'])) {
         $resultArticle = $this->articleFunction($id, $gatherData['article_id']);
         if ($resultArticle === false) {
             return false;
         }
     }
     $this->commit();
     return $id;
     //保存成功之后返回i
 }
 public function add($resquestdata)
 {
     //调用父类中的add方法将添加表中的数据插入进去(除了角色和权限的关系)
     $id = parent::add();
     if ($id === false) {
         return false;
     }
     //插入角色和权限的关系进出role_permission表
     $this->handle_role_permission($id, $resquestdata['permission_ids']);
     return $id;
 }
 /**
  * 添加商品信息
  * @param mixed|string $requestData
  * @return bool
  */
 public function add($requestData)
 {
     $this->startTrans();
     $this->handleGoodsStatus();
     $this->data['add_time'] = NOW_TIME;
     $id = parent::add();
     if ($id === false) {
         $this->rollback();
         return false;
     }
     //添加商品货号
     $sn = date('Ymd') . str_pad($id, 9, "0", STR_PAD_LEFT);
     $rst = parent::save(array('id' => $id, 'sn' => $sn));
     if ($rst === false) {
         $this->rollback();
         $this->error = '添加商品货号失败';
         return false;
     }
     //添加商品详细描述
     $goodsIntroModel = M('GoodsIntro');
     $rst = $goodsIntroModel->add(array('goods_id' => $id, 'intro' => $requestData['intro']));
     if ($rst === false) {
         $this->rollback();
         $this->error = '添加商品详细描述失败';
         return false;
     }
     //添加会员价格
     $rst = $this->handleGoodsMemberPrice($id, $requestData['goods_member_prices']);
     if ($rst === false) {
         return false;
     }
     //添加商品相册图片
     $rst = $this->handleGoodsPhoto($id, $requestData['goods_photo_paths']);
     if ($rst === false) {
         return false;
     }
     //添加相关文章
     $rst = $this->handleGoodsArticle($id, $requestData['article_ids']);
     if ($rst === false) {
         return false;
     }
     //处理商品属性
     $result = $this->addGoodsAttribute($id, $requestData['goodsAttribute']);
     if ($result === false) {
         return false;
     }
     //事务的提交
     $this->commit();
     return $id;
 }
Example #10
0
 public function add($requestData)
 {
     //开启事物
     $this->startTrans();
     //调用handleGoodsStatus计算状态
     $this->handleGoodsStatus();
     //调用父类add方法存储通用数据,并返回id
     $id = parent::add();
     //如果存储失败,则回滚
     if ($id === false) {
         $this->error = '保存数据失败';
         $this->rollback();
         return false;
     }
     //按照规则生成一个货号,并保存到数据表中
     $sn = date('Ymd') . str_pad($id, 9, '0', STR_PAD_LEFT);
     $result = parent::save(array('id' => $id, 'sn' => $sn));
     //存入失败,回滚
     if ($result === false) {
         $this->error = '保存货号失败';
         $this->rollback();
         return false;
     }
     //将商品描述保存到描述表中
     $goodsIntroModel = M('GoodsIntro');
     $result1 = $goodsIntroModel->add(array('goods_id' => $id, 'intro' => $requestData['intro']));
     if ($result1 === false) {
         $this->error = '保存商品描述失败';
         $this->rollback();
         return false;
     }
     //将会员价格保存到商品会员表中
     $memberPrice = $this->handMemberPrice($id, $requestData['memberPrices']);
     if ($memberPrice === false) {
         return false;
     }
     //将照片路径保存到表中
     $goodsPhtot = $this->handleGoodsPhoto($id, $requestData['goods_photo_paths']);
     if ($goodsPhtot === false) {
         return false;
     }
     //将文章保存到goods_article表中
     $goodsArticle = $this->handleGoodsArticle($id, $requestData['article_ids']);
     if ($goodsArticle === false) {
         return false;
     }
     //事务提交
     $this->commit();
     return $id;
 }
 /**
  * 文章的添加
  * @param mixed|string $requestData
  * @return bool|mixed
  */
 public function add($requestData)
 {
     $id = parent::add();
     if ($id === false) {
         $this->error = "添加文章失败";
         return false;
     }
     $articleContentModel = M('ArticleContent');
     $rst = $articleContentModel->where(array('article_id' => $id))->add(array('article_id' => $id, 'content' => $requestData['content']));
     if ($rst === false) {
         $this->error = "添加文章失败";
         return false;
     }
     return $id;
 }
Example #12
0
 public function add($requestData)
 {
     //>>1.将请求数据(除了内容)保存到article表中
     $id = parent::add();
     if ($id === false) {
         return false;
     }
     //>>2.将内容保存到article_content表中
     $articleContent = array('article_id' => $id, 'content' => $requestData['content']);
     $result = M('ArticleContent')->add($articleContent);
     if ($result === false) {
         return false;
     }
     return $id;
 }
Example #13
0
 /**
  * 新增文章
  * 将文章的基本信息添加到article表中,将文章的内容添加到article_content表中
  * @param mixed|string $requestData
  */
 public function add($requestData)
 {
     $article_id = parent::add();
     if ($article_id === false) {
         $this->error = '添加文章出错!';
         return false;
     }
     $articleContentModel = M('ArticleContent');
     $result = $articleContentModel->add(array('article_id' => $article_id, 'content' => $requestData['content']));
     if ($result === false) {
         $this->error = '添加文章内容时出错!';
         return false;
     }
     return $article_id;
 }
Example #14
0
 /**
  * 接收请求中的所有数据
  * @param mixed|string $requestData
  */
 public function add($requestData)
 {
     //>>1.需要将create收集到的数据保存到article表中
     $id = parent::add();
     if ($id === false) {
         return false;
     }
     //>>2.需要将请求中的content数据保存到article_content表中
     $articleContentModel = M('ArticleContent');
     $result = $articleContentModel->add(array('article_id' => $id, 'content' => $requestData['content']));
     if ($result === false) {
         return false;
     }
     return $id;
 }
 public function add($requestdata)
 {
     //对密码进行加盐加密
     $this->data['password'] = md5($this->data['password'] . $this->data['salt']);
     //添加对应admin表里的数据
     $id = parent::add();
     if ($id === false) {
         return false;
     }
     $result = $this->handleadminrelation($id, $requestdata);
     if ($result === false) {
         return false;
     }
     return $id;
 }
 public function add($requestData)
 {
     $id = parent::add();
     //create收集的数据保存在Article表中
     if ($id === false) {
         $this->error = "文章保存失败";
         return false;
     }
     $articleContentModel = D("ArticleContent");
     $rst = $articleContentModel->add(array("article_id" => $id, "content" => $requestData['content']));
     if ($rst == false) {
         return false;
     }
     return $id;
 }
 public function add($requestData)
 {
     //    dump($requestData);
     //    exit;
     //开启事物
     $this->startTrans();
     //不仅要将请求中的数据保存在goods表,还要讲简介保存到goods_intro表中
     $id = parent::add();
     //a调用父类的方法完成基本数据保存,返回id
     if ($id == false) {
         $this->rollback();
         //事物回滚
         return false;
     }
     //计算请求中的商品状态值
     $this->handleGoodsStatus();
     //    exit;
     //计算当前的商品货号 并将其更新到数据库中,
     $sn = date("Ymd") . str_pad($id, 9, "0", STR_PAD_LEFT);
     //用当前日期和id生成货号
     $rst = parent::save(array("id" => $id, "sn" => $sn));
     if ($rst == false) {
         $this->error = "保存货号失败..";
         $this->rollback();
         //事物回滚
         return false;
     }
     //再将请求中的intro数据保存到goodsintro表中
     $goodsintromodel = M("GoodsIntro");
     $rst = $goodsintromodel->add(array("goods_id" => $id, "intro" => $requestData["intro"]));
     //将请求中的intro信息保存在goods_intro表中
     if ($rst == false) {
         $this->error = "保存商品描述失败..";
         $this->rollback();
         //事物回滚
         return false;
     }
     //保存商品的会员价格到商品价格表中
     $rst = $this->handleMemberPrice($id, $requestData['memberPrice']);
     if ($rst === false) {
         $this->rollback();
         //失败则回滚
         return false;
     }
     $this->commit();
     //提交事物
     return $id;
 }
Example #18
0
 public function add($requestData)
 {
     //调用父类基础add,将基本内容储存到article表中
     $id = parent::add();
     if ($id === false) {
         $this->error = '保存失败';
         return false;
     }
     //将文章内容保存到article_content表中
     $articleContentModel = M('articleContent');
     $result = $articleContentModel->add(array('article_id' => $id, 'content' => $requestData['content']));
     if ($result === false) {
         $this->error = '保存内容失败';
         return false;
     }
     return $id;
 }
Example #19
0
 /**
  * @param mixed|string $requestAll 请求中的所有数据,由于this->data过滤掉了除本数据表之外的所有数据.用此参数获取其他关联表数据
  * @return bool|mixed
  */
 public function add($requestAll)
 {
     $this->startTrans();
     //开启事务
     //>>1.调用自己封装的handleGoodsStatus()处理商品状态的数据处理.
     $this->handleGoodsStatus();
     //>>2.一定要调用parent上的add,因为先保存后才有id的值
     $id = parent::add();
     if ($id === false) {
         $this->rollback();
         return false;
     }
     //>>3.准备货号 并且将货号更新到数据库中    日期+八位的id   20151107000000id
     $sn = date('Ymd') . str_pad($id, 8, "0", STR_PAD_LEFT);
     $result = parent::save(array('sn' => $sn, 'id' => $id));
     //        $result = parent::where('id='.$id)->save(array('sn'=>$sn));
     if ($result === false) {
         $this->error = '保存货号出错!';
         $this->rollback();
         return false;
     }
     //>>4.商品简介的保存处理
     $result = $this->handleGoodsIntro($id, $requestAll['intro']);
     if ($result === false) {
         return false;
     }
     //>>5.处理商品相册
     $result = $this->handleGoodsGallery($id, $requestAll['gallery_path']);
     //$requestData['gallery']
     if ($result === false) {
         return false;
     }
     //>>6.关联文章的保存处理
     $result = $this->handleGoodsArticle($id, $requestAll['article_id']);
     if ($result === false) {
         return false;
     }
     //        >>7.处理商品会员价格
     $result = $this->handleGoodsMemberPrice($id, $requestAll['memberPrice']);
     if ($result === false) {
         return false;
     }
     $this->commit();
     return $id;
     //add添加成功之后返回id
 }
Example #20
0
 /**
  * 重写方法
  * $requestData 接收使用post的参数
  */
 public function add($requestData)
 {
     $this->startTrans();
     //开始事物
     //处理商品状态,转换为一个整数
     $this->handleGoodsStatus();
     $id = parent::add();
     //调用父类的添加方法得到ID
     if ($id === false) {
         $this->rollback();
         //如果插入失败不提交事物
         return false;
     }
     //根据ID计算出货号 ,
     $sn = date('Ymd') . str_pad($id, 8, '0', STR_PAD_LEFT);
     $result = parent::save(array('sn' => $sn, 'id' => $id));
     if ($result === false) {
         $this->rollback();
         //如果插入失败不提交事物
         return false;
     }
     //处理商品描述
     $result = $this->handleGoodsIntro($id, $requestData['intro']);
     if ($result === false) {
         return false;
     }
     //处理相册
     $result = $this->handleGoodsGallery($id, $requestData['gallery_path']);
     if ($result === false) {
         return false;
     }
     //处理相关文章
     $result = $this->handleGoodsArticle($id, $requestData['article_id']);
     if ($result === false) {
         return false;
     }
     //准备添加会员价格的
     $this->handleGoodsMemberPrice($id, $requestData['memberPrice']);
     $this->commit();
     //保存成功提交事物
     return $id;
     //保存成功返回ID
 }
Example #21
0
 public function add($allPost)
 {
     //先判断数据库中有没有这个名称
     $nameRow = $this->where(array('name' => $this->data['name']))->select();
     if (!empty($nameRow)) {
         $this->error = '名称已经存在';
         return false;
     }
     //再调用父类的add方法添加
     $id = parent::add();
     if ($id === false) {
         $this->error = '添加失败';
         return false;
     }
     $result = $this->rolePermissionFunction($id, $allPost['permission_id']);
     if ($result === false) {
         return false;
     }
     return $id;
 }
Example #22
0
 public function add($requestAll)
 {
     //>>1.this->data是请求中的数据,并且已经处理过了
     $this->data['password'] = md5($this->data['password'] . $this->data['salt']);
     $id = parent::add();
     if ($id === false) {
         return false;
     }
     //>>2.需要将请求中的角色和用户的关系添加到admin_role中
     $result = $this->handleRole($id, $requestAll['role_ids']);
     if ($result === false) {
         return false;
     }
     //>>3.需要将请求中的用户和额外权限添加到 admin_permission表中
     $result = $this->handlePermission($id, $requestAll['permission_ids']);
     if ($result === false) {
         return false;
     }
     return $id;
 }
Example #23
0
 public function add($requestData)
 {
     $this->startTrans();
     //        $this->data; 是create收集的数据
     //        $requestData; 是请求中的所有数据
     //>>1.处理商品的状态
     $this->handlerGoodsStatus();
     //>>2.调用父类中的add方法将this->data(create收集到的请求数据) 保存到数据库中
     $id = parent::add();
     if ($id === false) {
         $this->rollback();
         return false;
     }
     //>>3.把商品描述的数据保存到goods_intro表中
     $result = $this->handleGoodsIntro($requestData, $id);
     if ($result === false) {
         return false;
     }
     //>>4.处理会员价格
     $result = $this->handleGoodsMemberPrice($requestData, $id);
     if ($result === false) {
         return false;
     }
     //>>5.处理商品相册
     $result = $this->handleGoodsGallery($requestData, $id);
     if ($result === false) {
         return false;
     }
     //>>6.处理商品相关文章
     $result = $this->handleGoodsArticle($requestData, $id);
     if ($result === false) {
         return false;
     }
     //>>7.处理商品属性
     $result = $this->handleGoodsAttribute($requestData, $id);
     if ($result === false) {
         return false;
     }
     $this->commit();
     return $id;
 }
Example #24
0
 public function add($uesrData)
 {
     //把密码进行加盐机密
     $this->data['password'] = md5($this->data['password'] . $this->data['salt']);
     //调用父类的方法添加的数据返回当前的id
     $id = parent::add();
     if ($id === false) {
         $this->error = '添加失败';
         return false;
     }
     //添加用户角色
     $result = $this->adminRoleFunction($id, $uesrData['role_ids']);
     if ($result === false) {
         $this->error = '添加失败';
         return false;
     }
     //添加额外权限
     $resultAdminPermission = $this->adminPermissionFunction($id, $uesrData['permission_id']);
     if ($resultAdminPermission === false) {
         $this->error = '添加失败';
         return false;
     }
 }
Example #25
0
 /**
  * 添加新商品,同时操作多张表,使用事务
  * 先向goods表中插入基本数据,在根据返回当前新增数据的id更新货号
  * 再将当前商品的id和简介写入goods_intro表中
  * @param mixed|string $requestData
  * @return bool|mixed
  */
 public function add($requestData)
 {
     $this->startTrans();
     //计算商品状态,
     $this->handleGoodsStatus();
     //添加商品基本信息,返回新增商品的id
     $id = parent::add();
     if ($id === false) {
         $this->error = ' 添加商品时出错!';
         $this->rollback();
         return false;
     }
     //计算商品货号,年月日加9位数的当前商品的id,id的位数不足用0填充
     $goods_sn = date('Ymd') . str_pad($id, 9, "0", STR_PAD_LEFT);
     $result = parent::save(array('id' => $id, 'sn' => $goods_sn));
     if ($result === false) {
         $this->error = ' 更新商品货号时出错!';
         $this->rollback();
         return false;
     }
     //保存商品到goods表的同时,将商品简介保存到goods_intro表中
     $goodsIntroModel = M('GoodsIntro');
     $result = $goodsIntroModel->add(array('goods_id' => $id, 'intro' => $requestData['intro']));
     if ($result === false) {
         $this->error = ' 保存商品简介时出错!';
         $this->rollback();
         return false;
     }
     //保存当前商品的各个会员等级的售价,是已键值对的形式传递的数据: 键表示会员级别的id,值是该级别对应的售价,
     //一个商品对应三个级别的会员,有3个不同的会员价格,添加一个商品对应就有三条数据写入到goods_member_price表中.
     /**
      * array(3) {
      * [1] => string(2) "99"
      * [2] => string(2) "88"
      * [3] => string(2) "77"
      * }
      */
     //生成要添加的商品会员价格的数据
     $data = $this->handleGoodsMemberPrice($requestData['price'], $id);
     $goodsMemberPriceModel = M('GoodsMemberPrice');
     $result = $goodsMemberPriceModel->addAll($data);
     if ($result === false) {
         $this->error = ' 保存商品会员价格时出错!';
         $this->rollback();
         return false;
     }
     //将商品相册上传成功后的图片路径保存到goods_gallery表中
     $goods_gallery_data = $this->handleGoodsGallery($requestData['path'], $id);
     $goodsGalleryModel = M('GoodsGallery');
     $result = $goodsGalleryModel->addAll($goods_gallery_data);
     if ($result === false) {
         //            $this->error = ' 保存商品相册时出错!';
         //            $this->rollback();
         //            return false;
     }
     //调用处理当前商品对应的文章的方法,获取数据添加到goods_article表中
     $data = $this->handleGoodsArticle($requestData['article_id'], $id);
     if (!empty($data)) {
         $goodsArticleModel = M('GoodsArticle');
         $result = $goodsArticleModel->addAll($data);
         if ($result === false) {
             $this->error = ' 保存商品文章时出错!';
             $this->rollback();
             return false;
         }
     }
     $this->commit();
     return $id;
 }