コード例 #1
0
 public function myUpdate($data)
 {
     $id = (int) $data['id'];
     if ($id <= 0) {
         $this->error = '请先选择要更新的分类';
         return false;
     }
     unset($data['id']);
     if ($id == $data['parent_id']) {
         $data['parent_id'] = 0;
     }
     //所属分类等于自己时, 更正为顶级分类
     //验证数据
     if (false === $this->create($data, self::MODEL_UPDATE)) {
         return false;
     }
     //验证 parent_id合法性
     if ($this->parent_id > 0) {
         $model = new Model('Category');
         //避免 model 混淆
         $parent = $model->find($this->parent_id);
         if (false === $parent || empty($parent)) {
             $this->error = '父级分类不存在';
             return false;
         }
         $orginfo = $model->find($id);
         if ($orginfo['store_id'] != $parent['store_id']) {
             $this->error = '父级分类不存在当前店铺';
             return false;
         }
     }
     return $this->where('`id`=' . $id)->save();
 }
コード例 #2
0
 public function comment($id)
 {
     $model = new Model('Article');
     $article = $model->find(array('articleId' => $id));
     if (empty($article)) {
         $this->error('文章不存在');
     }
     $key = get_client_ip() . '-view-article-' . $id;
     $cache = S($key);
     if (!empty($cache)) {
         $this->error('评论间隔必须大于1分钟');
     }
     $nickname = I('nickname');
     $content = I('content');
     if (empty($nickname)) {
         $this->error('昵称不能为空');
     }
     if (empty($content)) {
         $this->error('评论内容不能为空');
     }
     $data = array('nickname' => $nickname, 'content' => $content, 'createdAt' => time(), 'createdIp' => get_client_ip(), 'articleId' => $id);
     $commentModel = new Model('Comment');
     if (!$commentModel->data($data)->add()) {
         $this->error('评论失败');
     }
     S($key, 1, 60);
     $data['createdAt'] = date('m-d H:i', $data['createdAt']);
     $this->ajaxReturn($data);
 }
コード例 #3
0
 public function edit($id)
 {
     $model = new Model('Link');
     $data = $model->find($id);
     if (empty($data)) {
         $this->error('链接不存在');
     }
     if (IS_POST) {
         $name = I('name');
         $link = I('link');
         $status = I('status', 1);
         $sort = I('sort', 0);
         if (empty($name)) {
             $this->error('网站名称不能为空');
         }
         if (empty($link)) {
             $this->error('网站链接不能为空');
         }
         $data = array('name' => $name, 'link' => $link, 'status' => $status, 'sort' => $sort);
         if (false === $model->where(array('linkId' => $id))->save($data)) {
             $this->error('编辑失败');
         } else {
             $this->success('编辑成功', U('admin/link/index'));
         }
     } else {
         $this->assign('data', $data);
         $this->display('post');
     }
 }
コード例 #4
0
 public function cart($sid)
 {
     $store_M = new Model('Store');
     $storeinfo = $store_M->find($sid);
     $this->assign('storeinfo', $storeinfo);
     $this->display();
 }
コード例 #5
0
 /**
  * 指定店铺的 商品分类 树
  * @param number $sid		店铺ID
  * @param string $status	状态
  */
 public function tree($sid, $status = null)
 {
     $status_view = array('default' => '所有', 'del' => '已删除', 'forbid' => '禁用', 'allow' => '正常');
     //默认是 所有 未删除
     //店铺id必须有
     $map['store_id'] = (int) $sid;
     if ($map['store_id'] <= 0) {
         $this->error('参数非法');
     }
     $store_M = new Model('Store');
     $store_info = $store_M->find($map['store_id']);
     if (empty($store_info)) {
         $this->error('店铺不存在');
     }
     $this->assign('store_info', $store_info);
     $now_status = $status_view['default'];
     if (isset($status) && key_exists($status, CategoryModel::$mystat)) {
         //指定查询状态
         $map['status'] = CategoryModel::$mystat[$status];
         $now_status = $status_view[$status];
     } else {
         $map['status'] = array('EGT', 0);
         //默认查询状态为未删除的数据
     }
     $model = new CategoryModel();
     $cate_tree = $model->ztreeArr($map);
     $cate_tree = json_encode($cate_tree);
     $this->assign('tree_json', $cate_tree);
     //ztree json
     $this->assign('now_status', $now_status);
     //当前页面筛选的状态
     // 记录当前列表页的cookie
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
コード例 #6
0
 /**
  * 店主信息
  */
 public function onwerInfo()
 {
     $model = new Model('Store');
     $info = $model->find(STID);
     $this->assign('info', $info);
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
コード例 #7
0
ファイル: GoodsModel.class.php プロジェクト: qingsonge/php
 public function find($id)
 {
     //select  obj.*,b.name as brand_name  from goods as obj join brand as b on obj.brand_id = b.id where obj.id =
     $this->field('obj.*,b.name as brand_name');
     $this->alias('obj');
     $this->join('__BRAND__ as b on obj.brand_id = b.id');
     $this->where(array('obj.id' => $id));
     $row = parent::find();
     return $row;
 }
コード例 #8
0
ファイル: AddressModel.class.php プロジェクト: qingsonge/php
 /**
  * 根据id查询出一行数据
  * @param array|mixed $id
  * @return mixed
  */
 public function find($id)
 {
     $this->alias('obj');
     $this->field("obj.*,province.name as province_name,city.name as city_name,area.name as area_name");
     $this->join('__REGION__ as province on obj.province_id=province.region_code');
     $this->join('__REGION__ as city on obj.city_id=city.region_code');
     $this->join('__REGION__ as area on obj.area_id=area.region_code');
     $this->where(array('obj.id' => $id));
     return parent::find();
 }
コード例 #9
0
 public function delete($id)
 {
     $model = new Model('Comment');
     $data = $model->find($id);
     if (empty($data)) {
         $this->error('评论不存在');
     }
     if (!$model->delete($id)) {
         $this->error('删除失败');
     } else {
         $this->success('删除成功');
     }
 }
コード例 #10
0
 public function delete($id)
 {
     $model = new Model('Category');
     $category = $model->find($id);
     if (empty($category)) {
         $this->error('分类不存在');
     }
     if ($category['total'] > 0) {
         $this->error('该分类下有文章,不可删除');
     }
     if (!$model->delete($id)) {
         $this->error('删除失败');
     }
     $this->success('删除成功', U('admin/category/index'));
 }
コード例 #11
0
 /**
  * 添加新的属性值 替换add()方法
  * @param array $data 新增的数据库字段
  * @return $this->add()
  */
 public function myAdd($data)
 {
     //先create验证数据
     if (false === $this->create($data, self::MODEL_INSERT)) {
         return false;
     }
     //验证 所属属性是否存在
     $attr_M = new Model('Attr');
     $attr = $attr_M->find($this->attr_id);
     if (false === $attr || empty($attr)) {
         $this->error = '所属属性不存在';
         return false;
     }
     return $this->add();
 }
コード例 #12
0
 /**
  * 验证验证码
  * @param string $mobile 手机号
  * @param string $code 验证码
  * @return boolean 验证
  */
 public function verify($mobile, $code)
 {
     $this->where(array('mobile' => $mobile))->order('id desc');
     if (!($data = parent::find())) {
         $this->error = '验证码错误';
         return false;
     }
     if ($data['code'] != $code) {
         $this->error = '验证码错误';
         return false;
     }
     if ($data['status'] != '0') {
         $this->error = '验证码已过期';
         return false;
     }
     return parent::save($this->create($data));
 }
コード例 #13
0
 public function edit($id)
 {
     $model = new Model('Article');
     $article = $model->find($id);
     if (empty($article)) {
         $this->error('文章不存在');
     }
     if (IS_POST) {
         $title = I('title');
         $description = I('description');
         $content = I('content');
         $image = I('image');
         $status = I('status', 1);
         $sort = I('sort', 0);
         $categoryId = I('categoryId');
         if (empty($title)) {
             $this->error('文章标题不能为空');
         }
         if (empty($content)) {
             $this->error('文章内容不能为空');
         }
         if (empty($description)) {
             $description = trim(mb_substr(strip_tags(htmlspecialchars_decode($content)), 0, 100, 'UTF-8'));
         }
         if (empty($categoryId)) {
             $this->error('请选择分类');
         }
         $data = array('title' => $title, 'description' => $description, 'content' => $content, 'image' => $image, 'status' => $status, 'sort' => $sort, 'updateAt' => time(), 'categoryId' => $categoryId);
         if ($model->where(array('articleId' => $id))->save($data) === false) {
             $this->error('编辑失败');
         }
         if ($article['categoryId'] != $categoryId) {
             M('Category')->where(array('categoryId' => $categoryId))->setInc('total');
             M('Category')->where(array('categoryId' => $article['categoryId']))->setDec('total');
         }
         $this->success('编辑成功', U('admin/article/index'));
     } else {
         $categories = M('Category')->field('categoryId,name')->select();
         $this->assign('categories', $categories);
         $this->assign('data', $article);
         $this->display('post');
     }
 }
コード例 #14
0
 /**
  * 更新指定店铺筛选属性
  * @param int $store_id 店铺ID
  * @param array $attr_vals 属性值数组
  * @return boolean
  */
 public function update($store_id, $attr_vals)
 {
     //验证store_id合法性
     $store_M = new Model('Store');
     $store = $store_M->find($store_id);
     if (false === $store || empty($store)) {
         $this->error = '店铺不存在';
         return false;
     }
     //删除该店铺原有的属性, 再添加上新属性
     $this->startTrans();
     $this->where('`store_id`=' . $store_id)->delete();
     //验证attr_val_id合法性 , 不合法的忽略掉
     $AttrVal_M = new Model('AttrVal');
     $attr_vals = (array) $attr_vals;
     $tmpdata = array();
     foreach ($attr_vals as $valid) {
         $tmpid = (int) $valid;
         if ($tmpid > 0) {
             $AttrVal = $AttrVal_M->find($tmpid);
             if (false === $AttrVal || empty($AttrVal)) {
                 continue;
             }
             //不合法的忽略掉
             $tmpdata = array('store_id' => $store_id, 'attr_val_id' => $tmpid);
             if (false === $this->data($tmpdata)->add()) {
                 $this->error = '存在非法数据';
                 $this->rollback();
                 return false;
             }
         }
     }
     /* 允许清空店铺属性值
     		if (empty($tmpdata)) {
     			$this->error = '属性值不合法';
     			$this->rollback();
     			return false;
     		}
     		*/
     $this->commit();
     return true;
 }
コード例 #15
0
ファイル: GoodsModel.class.php プロジェクト: hcpzhe/foodorder
 public function myUpdate($data)
 {
     $id = (int) $data['id'];
     if ($id <= 0) {
         $this->error = '请先选择要更新的商品';
         return false;
     }
     unset($data['id']);
     $myold = $this->find($id);
     //先create验证数据
     if (false === $this->create($data, self::MODEL_UPDATE)) {
         return false;
     }
     if ($this->cate_id > 0) {
         //验证 所属分类是否存在
         $cate_M = new Model('Category');
         $cate = $cate_M->find($this->cate_id);
         if (false === $cate || empty($cate)) {
             $this->error = '所属商品分类不存在';
             return false;
         } elseif ($cate['store_id'] != $myold['store_id']) {
             $this->error = '所属商品分类不属于当前店铺';
             return false;
         }
     }
     //上传商品图片
     if (!empty($data['image'])) {
         $setting = C('PICTURE_UPLOAD');
         $Upload = new Upload($setting);
         $goods_image = $Upload->uploadOne($data['image']);
         if (!$goods_image) {
             $this->error = $Upload->getError();
             return false;
         }
         $goods_image['path'] = substr($setting['rootPath'], 1) . $goods_image['savepath'] . $goods_image['savename'];
         //在模板里的url路径
         $this->image = $goods_image['path'];
     } else {
         unset($this->image);
     }
     return $this->where('`id`=' . $id)->save();
 }
コード例 #16
0
 /**
  * 店铺商品
  * @param int $sid		店铺id
  */
 public function goods($sid)
 {
     $sid = (int) $sid;
     if ($sid <= 0) {
         $this->error('请选择正确的店铺');
     }
     //店铺名称
     $store_M = new Model('Store');
     $store_info = $store_M->find($sid);
     if (empty($store_info) || false === $store_info) {
         $this->error('店铺不存在, 请选择正确的店铺');
     }
     $this->assign('storeinfo', $store_info);
     //店铺信息
     //先取出所有分类, 然后把商品放进去
     $cate_M = new Model('Category');
     $cate_where = array('status' => '1', 'store_id' => $sid);
     $cate_list = $cate_M->where($cate_where)->order('sort ASC, id DESC')->select();
     $returnlist = array();
     $goods_M = new Model('Goods');
     //先取出无分类的商品
     $tmpmap = array('status' => '1', 'cate_id' => '0', 'store_id' => $sid);
     $nocate_goods = $goods_M->where($tmpmap)->order('sort ASC, id DESC')->select();
     if (!empty($nocate_goods)) {
         $returnlist[] = array('id' => '0', 'goods' => $nocate_goods, 'cate_name' => '默认分类');
     }
     foreach ($cate_list as $cate_row) {
         $tmpmap = array('status' => array('EGT', 0), 'cate_id' => $cate_row['id']);
         $tmp_goods = $goods_M->where($tmpmap)->order('sort ASC, id DESC')->select();
         if (!empty($tmp_goods)) {
             $tmp_cate = $cate_row;
             $tmp_cate['goods'] = $tmp_goods;
             $returnlist[] = $tmp_cate;
         }
     }
     $this->assign('list', $returnlist);
     //分类-商品 列表
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
コード例 #17
0
 /**
  * 更新订单商品 page
  * @param int $oid	订单id
  * @param int $gid	商品id
  */
 public function editGoods($oid, $gid)
 {
     $oid = (int) $oid;
     $gid = (int) $gid;
     if ($oid <= 0 || $gid <= 0) {
         $this->error('参数非法');
     }
     $goods_M = new Model('goods');
     $goods_info = $goods_M->find($gid);
     if (empty($goods_info)) {
         $this->error('此商品不存在');
     }
     $this->assign('goods_info', $goods_info);
     $where = array('order_id' => $oid, 'goods_id' => $gid);
     $og_M = new Model('OrderGoods');
     $info = $og_M->where($where)->find();
     if (empty($info)) {
         $this->error('订单内此商品不存在');
     }
     $this->assign('info', $info);
     $this->display();
 }
コード例 #18
0
 /**
  * 订单查看页面
  */
 public function read($id)
 {
     $map['id'] = (int) $id;
     if ($map['id'] <= 0) {
         $this->error('请选择要查看的订单');
     }
     $model = new OrderModel();
     if (false === $model->checkAuth($map['id'])) {
         $this->error('没有权限');
     }
     $info = $model->where($map)->find();
     $this->assign('info', $info);
     //订单信息
     $pay_M = new Model('Payment');
     $pay_info = $pay_M->find($info['payment_id']);
     $this->assign('pay_info', $pay_info);
     //支付方式信息
     $og_M = new Model('OrderGoods');
     $ordergoods = $og_M->where('order_id=' . $id)->select();
     $this->assign('ordergoods', $ordergoods);
     //订单商品列表
     if (!empty($ordergoods)) {
         $goods_M = new Model('goods');
         $goods_ids = field_unique($ordergoods, 'goods_id');
         $map = array('id' => array('in', $goods_ids));
         $goodslist = $goods_M->where($map)->getField('id,goods_name,image');
         $this->assign('goodslist', $goodslist);
         //列表用到的, ID为key索引
     }
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
コード例 #19
0
 /**
  * 属性值列表
  */
 public function valLists($atid, $status = null)
 {
     $model = new AttrValModel();
     $map = array();
     $status_view = array('default' => '所有', 'del' => '已删除', 'forbid' => '禁用', 'allow' => '正常');
     //查询条件 处理
     $map['attr_id'] = (int) $atid;
     if ($map['attr_id'] <= 0) {
         $this->error('参数非法');
     }
     $attr_M = new Model('Attr');
     $attr_info = $attr_M->find($map['attr_id']);
     if (empty($attr_info) || false === $attr_info) {
         $this->error('类别不存在');
     }
     if (isset($status) && key_exists($status, AttrValModel::$mystat)) {
         //指定查询状态
         $map['status'] = AttrValModel::$mystat[$status];
         $now_status = $status_view[$status];
     } else {
         $now_status = $status_view['default'];
         $map['status'] = array('EGT', 0);
         //默认查询状态为未删除的数据
     }
     /******************/
     $list = $this->_lists($model, $map);
     $this->assign('list', $list);
     //列表
     $this->assign('attr_info', $attr_info);
     // 所属类别信息
     $this->assign('now_status', $now_status);
     //当前页面筛选的状态
     // 记录当前列表页的cookie
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
コード例 #20
0
 /**
  * 新建商品
  * @param number $sid	店铺ID
  */
 public function add($sid)
 {
     //验证店铺是否存在
     $map['store_id'] = (int) $sid;
     if ($map['store_id'] <= 0) {
         $this->error('参数非法');
     }
     $store_M = new Model('Store');
     $store_info = $store_M->find($map['store_id']);
     if (empty($store_info)) {
         $this->error('店铺不存在');
     }
     $this->assign('store_info', $store_info);
     //店铺信息
     $map['status'] = '1';
     //只要状态正常商品分类
     $cate_M = new CategoryModel();
     $cate_tree = $cate_M->ztreeArr($map);
     $cate_tree = array_merge(array(array('id' => 0, 'pId' => 0, 'name' => '无分类', 'open' => true)), $cate_tree);
     $cate_tree = json_encode($cate_tree);
     $this->assign('tree_json', $cate_tree);
     //category ztree json
     cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
     $this->display();
 }
コード例 #21
0
ファイル: HyFrameModel.class.php プロジェクト: homyit/HyFrame
 /**
  * 重写find方法 以支持associate和sqlOptions
  * @param array $options find(['hy'=>true])
  */
 public function find($options)
 {
     if (!$this->isCallHyFunc($options)) {
         return parent::find($options);
     }
     $data = $this->select(array_merge(is_array($options) ? $options : array(), array('find' => true)));
     return $data[0];
 }
コード例 #22
0
 /**
  * 查看商品
  */
 public function read($id)
 {
     $map['id'] = (int) $id;
     if ($map['id'] <= 0) {
         $this->error('请选择商品');
     }
     $model = new GoodsModel();
     if (false === $model->checkAuth($id)) {
         $this->error('无权限');
     }
     $info = $model->where($map)->find();
     $store_M = new Model('Store');
     $store_info = $store_M->find(STID);
     $this->assign('store_info', $store_info);
     //所属店铺
     $cate_M = new CategoryModel();
     if ($info['cate_id'] > 0) {
         $info['cate_name'] = $cate_M->where('id=' . $info['cate_id'])->getField('cate_name');
     } else {
         $info['cate_name'] = '无分类';
     }
     $map = array('store_id' => STID, 'status' => 1);
     $cate_tree = $cate_M->ztreeArr($map);
     //ztree json
     $tmp = array(array('id' => null, 'pId' => 0, 'name' => '无分类'));
     $cate_tree = array_merge(array(array('id' => 0, 'pId' => 0, 'name' => '无分类', 'open' => true)), $cate_tree);
     //$tmp + $cate_tree;
     $cate_tree = json_encode($cate_tree);
     $this->assign('tree_json', $cate_tree);
     //ztree json
     $this->assign('info', $info);
     //商品信息
     //cookie(C('CURRENT_URL_NAME'),$_SERVER['REQUEST_URI']);
     $html = $this->fetch();
     $this->success($html);
 }