123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- <?php
- namespace app\common\model;
- use think\Db;
- class WxGoods extends Base
- {
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- $result = validate('WxGoods')->check($data,[],'');
- if(true !== $result){
- $this->error = validate('WxGoods')->getError();
- return false;
- }
- if(!empty($data['imgs'])){
- $data['imgs']=implode(',',$data['imgs']);;
- }
- $cateInfo = Db::name('wx_goods_cate')
- ->where('id',$data['cate_id'])
- ->find();
- if($cateInfo['is_water']==1){
- if(empty($data['barrel_id'])){
- $this->error = '请选择空桶';
- return false;
- }
- }else{
- $data['barrel_id'] = 0;
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- public function cateGoodsList($userId,$orgId,$cateId,$title,$desc_name='sale',$desc='desc'){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['enable','=',1];
- $map[] = ['del','=',0];
- $cateInfo = [];
- if($cateId > 0){
- $map[] = ['cate_id','=',$cateId];
- $cateInfo = Db::name('wx_goods_cate')
- ->field('id,title,is_water,path')
- ->where(['id'=>$cateId])->find();
- }
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $ret=Db::name('wx_goods')
- ->field('id,title,price,img,price,label,dec')
- ->where($map)
- ->order([$desc_name=>$desc,'sort'=>'asc','id'=>'desc',])
- ->select();
- foreach ($ret as $k=>$v){
- $ret[$k]['label_name']=$v['label'] >0?Db::name('wx_goods_label')
- ->where('id',$v['label'])
- ->value('title'):'';
- $cart = Db::name('wx_goods_cart')
- ->where('user_id',$userId)
- ->where('goods_id',$v['id'])
- ->find();
- $ret[$k]['cart_num'] = $cart?$cart['nums']:0;
- $ret[$k]['cartId'] = $cart?$cart['id']:0;
- }
- $data =[
- 'list'=>$ret,
- 'cateInfo'=>$cateInfo,
- ];
- return $data;
- }
- public function details($id,$userId){
- $ret=Db::name('wx_goods')
- ->field('id,title,price,img,imgs,sale,content,label')
- ->where('id',$id)
- ->where('del',0)
- ->where('enable',1)
- ->find();
- if($ret){
- $ret['isFav'] = 0;
- $ret['imgs']=$ret['imgs']?explode(',',$ret['imgs']):[];
- $ret['label_name']=$ret['label'] >0?Db::name('wx_goods_label')
- ->where('id',$ret['label'])
- ->value('title'):'';
- $checkFav = Db::name('wx_goods_fav')
- ->where('user_id',$userId)
- ->where('goods_id',$ret['id'])
- ->find();
- if($checkFav){
- $ret['isFav'] = 1;
- }
- }
- return $ret;
- }
- public function getTjGoods($orgId){
- $list = Db::name('wx_goods')
- ->field('id,title,img,price,label')
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('enable',1)
- ->where('is_tj',1)
- ->order(['sort'=>'asc','id'=>'desc'])
- ->limit(3)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
- ->where('id',$v['label'])
- ->value('title'):"";
- }
- return $list?$list:[];
- }
- public function getTjGoodsList($orgId,$page,$size){
- $list = Db::name('wx_goods')
- ->field('id,title,img,price,label,sale')
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('enable',1)
- ->where('is_tj',1)
- ->order(['sort'=>'asc','id'=>'desc'])
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
- ->where('id',$v['label'])
- ->value('title'):"";
- }
- return $list?$list:[];
- }
- public function getIndexGoods($orgId){
- $list = Db::name('wx_goods')
- ->field('id,title,img,price,label,sale')
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('enable',1)
- // ->where('is_tj',0)
- ->order(['sort'=>'asc','id'=>'desc'])
- ->limit(10)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
- ->where('id',$v['label'])
- ->value('title'):"";
- }
- return $list?$list:[];
- }
- public function getIndexGoodsList($orgId,$page,$size,$type,$desc_name='sale',$desc='desc',$kw=''){
- $map = [];
- if($kw!=''){
- $map[] = ['title','like','%'.$kw.'%'];
- }
- if($type ==0){
- $order= [$desc_name=>$desc,'sort'=>'asc','id'=>'desc'];
- }else{
- $order= ['sort'=>'asc','id'=>'desc'];
- }
- if($type ==1){
- $map[] = ['label','=',1];
- }elseif ($type==2){
- $map[] = ['barrel_id','>',0];
- }elseif ($type==3){
- $map[] = ['is_tj','=',1];
- }
- $list = Db::name('wx_goods')
- ->field('id,title,img,price,label,sale,dec')
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('enable',1)
- ->where($map)
- ->order($order)
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
- ->where('id',$v['label'])
- ->value('title'):"";
- }
- return $list?$list:[];
- }
- public function favGoodsList($userId,$orgId,$page,$size){
- $ids = Db::name('wx_goods_fav')
- ->where('user_id',$userId)
- ->group('goods_id')
- ->column('goods_id');
- if(empty($ids)){
- $map[] = ['id','=',-1];
- }else{
- $map[] = ['id','in',$ids];
- }
- $list = Db::name('wx_goods')
- ->field('id,title,img,price,label,sale,dec')
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('enable',1)
- ->where($map)
- ->order(['sort'=>'asc','id'=>'desc'])
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['label_name'] = $v['label']>0?Db::name('wx_goods_label')
- ->where('id',$v['label'])
- ->value('title'):"";
- }
- return $list?$list:[];
- }
- public function barrelList($orgId,$page,$size){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $list = Db::name('wx_barrel')
- ->field('id,title,cash_price,path')
- ->where($map)
- ->order(['sort'=>'asc','id'=>'desc'])
- ->page($page,$size)
- ->select();
- return $list?$list:[];
- }
- public function myBarrelList($orgId,$userId,$page,$size){
- $map[] = ['a.org_id','=',$orgId];
- $map[] = ['a.del','=',0];
- $map[] = ['a.user_id','=',$userId];
- $list = Db::name('wx_cash')
- ->alias('a')
- ->join('wx_barrel b','a.barrel_id=b.id')
- ->field('a.id,b.title,b.cash_price,b.path,a.num,a.amount')
- ->where($map)
- ->order(['a.id'=>'desc'])
- ->page($page,$size)
- ->select();
- return $list?$list:[];
- }
- public function myRefundBarrelList($orgId,$userId,$page,$size){
- $map[] = ['a.org_id','=',$orgId];
- $map[] = ['a.del','=',0];
- $map[] = ['a.user_id','=',$userId];
- $list = Db::name('wx_cash_refund')
- ->alias('a')
- ->join('wx_barrel b','a.barrel_id=b.id')
- ->field('a.id,b.title,b.cash_price,b.path,a.num,a.amount,a.status,a.create_time,a.remark')
- ->where($map)
- ->order(['a.id'=>'desc'])
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['status_name'] =isset(model('WxCash')->status[$v['status']])?model('WxCash')->status[$v['status']]:'';
- $list[$k]['remark'] = $v['remark']?$v['remark']:"";
- }
- return $list?$list:[];
- }
- }
|