예제 #1
0
 public function addToGoods()
 {
     $id = array_unique((array) I('id', 0));
     $id = is_array($id) ? implode(',', $id) : $id;
     if (empty($id)) {
         $this->error('请选择要操作的数据!');
     }
     $where['id'] = array('in', $id);
     $CollectGoodsModel = new CollectGoodsModel();
     $info = $this->lists('CollectGoods', $where);
     $GoodsModel = new GoodsModel();
     $add = 0;
     $err = 0;
     $exist = 0;
     foreach ($info as $row) {
         if ($GoodsModel->create($row)) {
             $res = $GoodsModel->addGoods();
             if ($res > 0) {
                 $where = array('id' => $row['id']);
                 $CollectGoodsModel->where($where)->delete();
                 $add++;
             } elseif ($res == -2) {
                 $exist++;
             } else {
                 $err++;
             }
         } else {
             $err++;
         }
     }
     if ($err > 0) {
         $this->error($err . '件商品上架失败,' . $add . '件商品上架成功', U('Collect/collect'));
     } else {
         $this->success($add . '件商品上架成功,' . $exist . '件重复商品未添加', U('Collect/index'));
     }
 }
예제 #2
0
 public function saveGoods()
 {
     if (I('id')) {
         $data = GoodsModel::instance()->findById(I('id'));
         $this->assign('data', $data);
     }
     if ($_POST) {
         if (I("post.id")) {
             // 编辑
             GoodsModel::instance()->edit($_POST);
         } else {
             // 添加
             $_POST['shop_id'] = $this->user->getShopId();
             GoodsModel::instance()->insert($_POST);
         }
         $this->_success('添加成功', U('goods'));
     }
     $list = GoodsCategoryModel::instance()->lists($this->user->getShopId());
     $this->assign('list', $list);
     //菜品分类
     $this->display();
 }
예제 #3
0
 public function status($status = 0)
 {
     $id = array_unique((array) I('id', 0));
     $id = is_array($id) ? implode(',', $id) : $id;
     if (empty($id)) {
         $this->error('请选择要操作的数据!');
     }
     $where['goods_id'] = array('in', $id);
     $goods = D('Goods')->getGoodsById($goodsId);
     $GoodsModel = new GoodsModel();
     $GoodsModel->where($where)->save(array('status' => $status ? 0 : 1));
     $this->success('操作成功', U('Goods/index'));
 }