model = new ActGood(); } public function goodList(){ $param = $this->request->param(["good_name"=>"","skuCode"=>'',"plat_code"=>'',"exam_status"=>"","page"=>1,"size"=>15],"post","trim"); $where=[["is_del","=",0],["platform_id",'in',$this->platform_id]]; if($param['good_name']!=="")$where[]=["good_name","like","%".$param['good_name']."%"]; if($param['skuCode']!=="")$where[]=["skuCode","like","%".$param['skuCode']."%"]; if($param['plat_code']!=="")$where[]=["plat_code","like","%".$param['plat_code']."%"]; if($param['exam_status']!==''){ $where[]=["exam_status","=",$param['exam_status']]; } $list=PlatformYouzan::with(["good"=>["unit","category","brand"],"platform","yzGood"]) ->where($where)->order("id desc") ->field("plat_code,spuCode,skuCode,sale_price,final_price,exam_status,online_time,creater") ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]); $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } public function create(){ $param = $this->request->param(["snArr"=>"","actCode"=>""],"post","trim"); $valid = Validate::rule([ "snArr|选中的商品集合"=>"require|array", "actCode|活动编码"=>"require|max:20" ]); if(!$valid->check($param)){ $this->error($valid->getError()); } $skuCodeArr= array_column($param['snArr'],"skuCode"); $goodArr= PlatformYouzan::with(["yzGood"])->where(["skuCode"=>$skuCodeArr,"is_del"=>0])->select()->toArray(); if(count($goodArr)!==count($param['snArr'])){ $this->error("商品信息有误"); } $yzGood = array_column($goodArr,"yzGood","skuCode"); $Act = \app\txx\model\Act::where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty(); if($Act->isEmpty()){ $this->error("活动信息有误"); } if($Act->status!==4){ $this->error("活动状态有误"); } if(strtotime($Act->end_time)error("活动已结束"); } if(strtotime($Act->start_time)error('活动已开始'); } $valids= Validate::rule([ "skuCode|商品编码"=>"require|max:20", "stock_num|库存数量"=>"require|integer", "roundId|轮次"=>"integer", ]); $actArr=[]; foreach ($param['snArr'] as $k=>$v){ if(!$valids->check($v)){ $this->error($valids->getError()); } if(!isset($yzGood[$v['skuCode']])|| isset($yzGood[$v['skuCode']]['status']))throw new \Exception('商品信息有误'); if($yzGood[$v['skuCode']]['status']!==6)throw new \Exception($v['skuCode'].'有赞商品未上线'); $temp=[ 'actCode'=>$param['actCode'], 'yz_good_code'=>$v['skuCode'], 'stock_num'=>$v['stock_num'], 'used_num'=>0, 'balance_num'=>$v['stock_num'], 'roundId'=>$v['roundId']??'', 'good_url'=>$yzGood[$v['skuCode']]['detail_url']??'', 'origin_price'=>$yzGood[$v['skuCode']]['origin']??'', 'status'=>1, ]; $actArr[]=$temp; } $this->model->startTrans(); try{ $add= $this->model->saveAll($actArr); if($add->isEmpty()) throw new \Exception('添加失败'); $Act->save(["status"=>1]); $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); $this->error($e->getMessage()); } $this->success('添加成功'); } public function list(){ $param=$this->request->param(["actCode"=>"","status"=>"","skuCode"=>"","roundId"=>"","page"=>1,"size"=>15],"post","trim"); $where=[["is_del","=",0]]; if($param['actCode']!==""){ $where[]=["actCode","like","%".$param['actCode']."%"]; } if($param['status']!==""){ $where[]=["status","=",$param['status']]; } if($param['skuCode']!==""){ $where[]=["yz_good_code","like","%".$param['skuCode']."%"]; } if($param['roundId']!==""){ $where[]=["roundId","=",$param['roundId']]; } $list= $this->model->with(["act","platformYz"=>["platform","good"=>['unit','brand','category']],"promocode"])->where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]); $list->each(function($item,$key){ $item['status_cn']=ActGood::$statusCn[$item['status']]??""; $item['act_status_cn']=\app\txx\model\Act::$statusCn[$item['act_status']]??""; return $item; }); $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } public function info(){ $param=$this->request->param(["id"=>""],"post","trim"); $info= $this->model->with(["act","platformYz"=>["platform","good"=>['unit','brand','category']],"promocode"])->findOrEmpty($param['id']); if($info->isEmpty()){ $this->error("信息有误"); } $info['status_cn']=ActGood::$statusCn[$info['status']]??""; $info['act_status_cn']=\app\txx\model\Act::$statusCn[$info['act_status']]; $this->success("获取成功",$info); } public function resetPromocode(){ $param=$this->request->param(["id"=>""],"post","trim"); $info= $this->model->findOrEmpty($param['id']); if($info->isEmpty()){ $this->error("信息有误"); } if(!in_array($info->status,[4,5]))throw new \Exception("状态有误"); $info->status=1; try{ if($info->promocode_id!==0){ $promocode= \app\youzan\model\YzActivityPromoCode::findOrEmpty($info->promocode_id); if($promocode->isEmpty())throw new \Exception('优惠券信息有误'); $promocode->save(['status'=>0]); }else{ $info->promocode_id=0; } $save= $info->save(); if(!$save)throw new \Exception('重置失败'); }catch (\Exception $e){ $this->error($e->getMessage()); } $this->success("重置成功"); } public function delete(){ $param=$this->request->param(["id"=>""],"post","trim"); $info= $this->model->findOrEmpty($param['id']); if($info->isEmpty()){ $this->error("信息有误"); } $info->is_del=1; try{ $save= $info->save(); if(!$save)throw new \Exception('删除失败'); if($info->promocode_id!==0){ $promocode= \app\youzan\model\YzActivityPromoCode::findOrEmpty($info->promocode_id); if($promocode->isEmpty())throw new \Exception('优惠券信息有误'); $promocode->save(['is_del'=>1]); } }catch (\Exception $e){ $this->error($e->getMessage()); } $this->success("删除成功"); } }