model = new ActGood(); } public function goodList(){ $param = $this->request->param(["good_name"=>"","skuCode"=>'',"plat_code"=>'',"page"=>1,"size"=>15],"post","trim"); $where=[["is_del","=",0],["platform_id",'in',$this->platform_id],['exam_status','=',6]]; 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']."%"]; $list=PlatformYouzan::with(["good"=>["unit","category","brand"],"platform"]) ->where($where)->order("id desc") ->field("id,plat_code,spuCode,skuCode,sale_price,final_price,exam_status,online_time,creater") ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]); $list->each(function (&$item) { $item->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$item->good_img); $item->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$item->good_info_img); $item->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$item->good_thumb_img); $item['spec_info'] =GoodSpec::where(['spuCode' => $item['spuCode'], 'is_del' => 0])->with(['spec', 'Spec_info'])->field('spec_id,spec_value_id')->select(); }); $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(); if(count($goodArr->toArray())!==count($param['snArr'])){ $this->error("商品信息有误"); } $yzGood = array_column($goodArr->toArray(),"yzGood","skuCode"); $Act = \app\txx\model\Act::where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty(); if($Act->isEmpty()){ $this->error("活动信息有误"); } if($Act->status!=0){ $this->error("活动状态有误"); } if(strtotime($Act->endTime)error("活动已结束"); } if(strtotime($Act->startTime)error('活动已开始'); } $valids= Validate::rule([ "skuCode|商品编码"=>"require|max:20", "stock_num|库存数量"=>"require|integer", "awards_type|商品类型"=>"require|max:255", "roundId|轮次"=>"integer", ]); $actArr=[]; foreach ($param['snArr'] as $k=>$v){ if(!$valids->check($v)){ $this->error($valids->getError()); } if(!isset($yzGood[$v['skuCode']])) $this->error('商品信息有误'); if($yzGood[$v['skuCode']]['status']!=6) $this->error($v['skuCode'].'有赞商品未上线'); $temp=[ 'actCode'=>$param['actCode'], 'yz_good_code'=>$v['skuCode'], 'goodName'=>$yzGood[$v['skuCode']]['title']??'', 'stock_num'=>$v['stock_num'], "awards_type"=>$v['awards_type'], 'used_num'=>0, "version"=>"2.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],['version',"=","2.0"]]; if($param['actCode']!==""){ $where[]=["actCode","like","%".$param['actCode']."%"]; } if($param['status']!==""){ $where[]=["status","=",$param['status']]; // if($param['status']==3) $where[]=["used_num",">=",$param['stock_num']]; } 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->visible(['id',"actCode","yz_good_code","stock_num","awards_type","status","addtime","updatetime","act_name", "company_name","contactor","mobile","startTime","endTime","act_status","sale_price","good_name","unit_name","cat_name", "brand_name","fetch_url","roundId","status_cn","ActStatus_cn","awards_order_num"]); $list->each(function (&$item){ $item['status_cn']=ActGood::$statusCn[$item['status']]??""; $item['ActStatus_cn']=\app\txx\model\Act::$statusCn[$item['act_status']]; if($item['act_status']!=4){ $item['fetch_url']=null; } $item['awards_order_num']=YzActivityPromoCode::GetOrderNumById($item['id']); }); $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"])->where(["is_del"=>0])->findOrEmpty($param['id']); if($info->isEmpty()){ $this->error("信息有误"); } $info->visible(['id','actCode','yz_good_code','awards_type','stock_num','status','addtime','updatetime','act_name', 'company_name','contactor','mobile','startTime','endTime','act_status','final_price','good_name','unit_name','cat_name', 'brand_name','fetch_url','roundId','status_cn','act_status_cn']); $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("状态有误"); try{ if($info->promocode_id!=0){ $promocode= \app\youzan\model\YzActivityPromoCode::where(["is_del"=>0,"id"=>$info->promocode_id])->findOrEmpty(); if($promocode->isEmpty()){ $info->promocode_id=0; $info->status=1; }else { $promocode->save(['status'=>0]); $info->remark="重试生成券码"; } }else{ $info->promocode_id=0; $info->status=1; } $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::where(['is_del'=>0,'id'=>$info->promocode_id])->findOrEmpty(); if($promocode->isEmpty())throw new \Exception('优惠券信息有误'); $promocode->save(['is_del'=>1]); } }catch (\Exception $e){ $this->error($e->getMessage()); } $this->success("删除成功"); } }