|
@@ -1,213 +0,0 @@
|
|
|
-<?php
|
|
|
-namespace app\mall\controller;
|
|
|
-use app\common\model\GroupGoodsItem;
|
|
|
-use app\common\model\StoreGoodsItem;
|
|
|
-use library\Controller;
|
|
|
-use library\tools\Data;
|
|
|
-use think\cache\driver\Redis;
|
|
|
-use think\Db;
|
|
|
-/**
|
|
|
- * 拼团商品
|
|
|
- * Class GroupGoods
|
|
|
- * @package app\mall\controller
|
|
|
- */
|
|
|
-class GroupGoods extends Controller
|
|
|
-{
|
|
|
-
|
|
|
- /**
|
|
|
- * 绑定数据表
|
|
|
- * @var string
|
|
|
- */
|
|
|
- protected $table = 'GroupGoods';
|
|
|
-
|
|
|
- /**
|
|
|
- * 列表
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function index()
|
|
|
- {
|
|
|
- $lid = input('id');
|
|
|
- $search_name = input('search_name','');
|
|
|
- $this->title = Db::name('GroupActivity')->where('id',$lid)->value('title');
|
|
|
- $this->lid = $lid;
|
|
|
- $where = [];
|
|
|
- $where[]= ['v.act_id','=',$lid];
|
|
|
- if($search_name) $where[] = ['g.name','like',"%".$search_name."%"];
|
|
|
- $list = $this->_query($this->table)->alias('v')
|
|
|
- ->field('v.create_at,v.sort,v.id,v.goods_id,v.act_id,g.name as goods_name,g.cover,g.name,g.low_price,g.status,g.is_deleted')
|
|
|
- ->where($where)
|
|
|
- ->join('StoreGoods g','v.goods_id = g.id','LEFT')
|
|
|
- ->order('v.sort desc ,v.id desc')
|
|
|
- ->page();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据列表处理
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @param array $data
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- protected function _index_page_filter(&$data)
|
|
|
- {
|
|
|
- foreach ($data as &$v){
|
|
|
- $v['goods_num'] = Db::name('GroupGoods')->where('act_id',$v['id'])->count();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 可添加商品列表
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @param array $data
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function goods_list()
|
|
|
- {
|
|
|
- $lid = input('id');
|
|
|
- $this->title = Db::name('GroupActivity')->where('id',$lid)->value('title');
|
|
|
- $this->lid = $lid;
|
|
|
- $name = input('name');
|
|
|
- $sel_ids = Db::name('GroupGoods')->where(['act_id'=>$lid])->column('goods_id');
|
|
|
- $where = [];
|
|
|
- $where[]= ['is_deleted','=',0];
|
|
|
- $where[]= ['status','=',1];
|
|
|
- if(!empty($sel_ids)) $where[] = ['id','not in',$sel_ids];
|
|
|
- if($name) $where[] = ['name','like','%'.$name.'%'];
|
|
|
- $list = $this->_query('StoreGoods')
|
|
|
- ->field('id,name,cover,low_price')
|
|
|
- ->where($where)
|
|
|
- ->order('sort desc ,id desc')->page();
|
|
|
- return $this->fetch('goods_list');
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * ajax添加商品
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @param array $data
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
-
|
|
|
- public function ajax_add()
|
|
|
- {
|
|
|
- $sel_goods = input('post.ids');
|
|
|
- $act_id = input('post.act_id');
|
|
|
- foreach ($sel_goods as $goods_id){
|
|
|
- $int_data[]=[
|
|
|
- 'act_id' => $act_id,
|
|
|
- 'goods_id' => $goods_id,
|
|
|
- 'sort' => 0,
|
|
|
- 'create_at' => date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $goods_item = StoreGoodsItem::where('goods_id',$goods_id)->field("goods_id,id as spec_id,sell_price ,is_combo,original_price,sell_price")->select()->toArray();
|
|
|
- array_walk($goods_item,function (&$v,$k)use($act_id){
|
|
|
- $v['act_id'] = $act_id;
|
|
|
- $v['group_price'] = $v['sell_price'];
|
|
|
- });
|
|
|
- (new GroupGoodsItem())->saveAll($goods_item);
|
|
|
- }
|
|
|
- Db::name('GroupGoods')->insertAll($int_data);
|
|
|
-
|
|
|
- return json_encode(['code'=>200]);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 拼团设置
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @param array $data
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function price_set()
|
|
|
- {
|
|
|
- if ($this->request->isGet()) {
|
|
|
- $act_goods = $this->request->get('id');
|
|
|
- $act_info = \app\common\model\GroupGoods::where('id',$act_goods)->find()->toArray();// 活动商品记录
|
|
|
- $goods_info = Db::name('StoreGoods')->field('id,name')->where(['id' => $act_info['goods_id']])->find();// 商品详情
|
|
|
- empty($goods_info) && $this->error('无效的商品信息,请稍候再试!');
|
|
|
- $group_item = GroupGoodsItem::field('s.*,i.goods_spec ,i.stock istock,i.base_stock ibase_stock')->alias('s')
|
|
|
- ->leftJoin('StoreGoodsItem i','i.id = s.spec_id')
|
|
|
- ->where(['s.act_id'=>$act_info['act_id'],'s.goods_id'=>$act_info['goods_id']])
|
|
|
- ->select()->toArray();// 拼团设置
|
|
|
- $this->fetch('', ['goods_info' => $goods_info,'group_item'=>$group_item]);
|
|
|
- }else{
|
|
|
- $post = input('post.');
|
|
|
- if(empty($post)) $this->error('数据错误');
|
|
|
- $group_set = [];
|
|
|
- //$redis = new Redis();
|
|
|
- // GROUP_活动id_GroupGoodsItem主键 :剩余库存
|
|
|
- // $redis_prefix = 'GROUP_'.$this->request->get('act_id').'_';
|
|
|
- foreach ($post['id'] as $k=>$id) {
|
|
|
- $group_set[$k]['id'] = $id;
|
|
|
- $group_set[$k]['original_price'] = $post['original_price'][$k];
|
|
|
- $group_set[$k]['sell_price'] = $post['sell_price'][$k];
|
|
|
- $group_set[$k]['group_price'] = $post['group_price'][$k];
|
|
|
- /* if($post['add_stock'][$k] != 0){
|
|
|
- //$redis->inc($redis_prefix.'_'.$id,$post['add_stock'][$k]);
|
|
|
- GroupGoodsItem::where('id',$id)->setInc('stock',$post['add_stock'][$k]);
|
|
|
- GroupGoodsItem::where('id',$id)->setInc('base_stock',$post['add_stock'][$k]);
|
|
|
- }*/
|
|
|
- }
|
|
|
- (new GroupGoodsItem())->saveAll($group_set);
|
|
|
- $this->success('保存成功!');
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除关联商品
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function del_goods()
|
|
|
- {
|
|
|
- $id = input('id');
|
|
|
- $detail = \app\common\model\GroupGoods::where('id',$id)->find()->toArray();
|
|
|
- GroupGoodsItem::where(['act_id'=>$detail['act_id'],'goods_id'=>$detail['goods_id']])->delete();
|
|
|
- $this->_delete($this->table);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 表单数据处理
|
|
|
- * @auth true
|
|
|
- * @menu true
|
|
|
- * @param array $data
|
|
|
- */
|
|
|
- protected function _form_filter(&$data)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- protected function _form_result($result){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|