noble=\think\facade\Config::get("noble"); } //活动列表 public function list(){ $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1"; $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10"; $where = [["ga.is_del","=",0]]; $activity_name = isset($this->post['activity_name']) && $this->post['activity_name'] !=="" ? trim($this->post['activity_name']):""; if($activity_name!=""){ $where[]=['ga.activity_name',"like","%$activity_name%"]; } $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):""; if($status!==""){ $where[]=['ga.status',"=",$status]; } $activity_code = isset($this->post['activity_code']) && $this->post['activity_code'] !=="" ? trim($this->post['activity_code']):""; if($activity_code!==""){ $where[]=['ga.activity_code',"like","%$activity_code%"]; } $starttime = isset($this->post['starttime']) && $this->post['starttime']!=="" ? $this->post['starttime']:""; if($starttime!==""){ $where[]=['ga.start',">=",date('Y-m-d H:i:s',strtotime($starttime))]; } $endtime = isset($this->post['endtime']) && $this->post['endtime']!=="" ? $this->post['endtime']:""; if($endtime!==""){ $where[]=['ga.end',"<",date('Y-m-d H:i:s',strtotime($endtime)+24*3600)]; } $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']):""; if($platform_code!==""){ $where[]=['ga.platform_code',"=",$platform_code]; } $company_id = isset($this->post['company_id']) && $this->post['company_id'] !=="" ? trim($this->post['company_id']):""; if($company_id!==""){ $where[]=['ga.company_id',"=",$company_id]; } $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']) :""; if($creater!=""){ $where[]=['ga.creater',"like","%$creater%"]; } $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? trim($this->post['createrid']) :""; if($createrid!==""){ $where[]=['ga.createrid',"=",$createrid]; } // $role=$this->checkRole(); // if(!empty($role['write'])){ // $where[]=["ga.createrid","in",$role['write']]; // } // $role = $this->checkDataShare(); // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['ga.createrid', 'in', $role[DataGroupModel::$type_全部]]; $role = $this->checkDataShare(); $hand = resign_hand_user($this->uid,0); if (!empty($role[DataGroupModel::$type_全部])) { $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部])); $where[] = ['ga.createrid', 'in',$arr]; } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $where[] = ["ga.createrid", 'in', get_company_item_user_by_name($company_name)]; $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $where[]=['ga.company_id','=', $relaComNo]; $count = Db::name('good_activity') ->alias('ga') ->leftJoin("platform p", "p.id=ga.platform_code") ->where($where) ->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('good_activity') ->alias('ga') ->field('ga.*,ga.company_id companyNo,p.platform_name') ->leftJoin("platform p", "p.id=ga.platform_code") ->withAttr('is_allow_update',function($val,$data)use($role){ return (in_array($this->roleid, [1, 33]) || in_array($data['createrid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0;//是否具有编辑权限 })->where($where) ->page($page,$size) ->order("ga.addtime desc") ->select() ->toArray(); $all_createrid = array_column($list,'createrid'); $item = get_company_name_by_uid($all_createrid); $names = get_headquarters_code_and_name(array_unique(array_column($list,'companyNo'))); foreach ($list as &$value){ $value['company_name']=$item[$value['createrid']]??''; $value['companyName']=$names[$value['companyNo']]??''; } return app_show(0,"获取成功",['list'=>$list,'count'=>$count]); } //活动商品列表 public function linst() { $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1"; $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10"; $where = [["a.is_del", "=", 0]]; $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] !== "" ? trim($this->post['skuCode']) : ""; if ($skuCode !== "") { $where[] = ['a.skuCode', "like", "%$skuCode%"]; } $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : ""; if ($good_name != "") { $where[] = ['a.good_name', "like", "%$good_name%"]; } $activity_code = isset($this->post['activity_code']) && $this->post['activity_code'] !=="" ? trim($this->post['activity_code']):""; if($activity_code!==""){ $where[]=['a.activity_code',"like","%$activity_code%"]; } $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):""; if($status!==""){ $where[]=['a.status',"=",$status]; } $activity_name = isset($this->post['activity_name']) && $this->post['activity_name'] !=="" ? trim($this->post['activity_name']):""; if($activity_name!=""){ $where[]=['b.activity_name',"like","%$activity_name%"]; } $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']):""; if($platform_code!=""){ $where[]=['b.platform_code',"=",$platform_code]; } $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $where[]=['b.company_id','=', $relaComNo]; $count = Db::name('activity_info')->alias("a") ->join("good_activity b","b.activity_code=a.activity_code","left") ->join("platform c","c.id=b.platform_code","left") ->where($where)->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('activity_info') ->alias("a") ->join("good_activity b","b.activity_code=a.activity_code","left") ->join("platform c","c.id=b.platform_code","left") ->where($where) ->page($page,$size) ->order("a.addtime desc") ->field("a.*,b.activity_name,c.platform_name,c.platform_code,b.company_id companyNo") ->select() ->toArray(); $names = get_headquarters_code_and_name(array_column($list,'companyNo')); foreach ($list as &$value){ $value['companyName'] = $names[$value['companyNo']] ?? ''; } return app_show(0,"获取成功",['list'=>$list,'count'=>$count]); } public function zilist(){ $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1"; $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10"; $where = [["a.is_del", "=", 0]]; $spuCode = isset($this->post['spuCode']) && $this->post['spuCode'] !== "" ? trim($this->post['spuCode']) : ""; if ($spuCode != "") $where[] = ['a.spuCode', "like", "%$spuCode%"]; $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : ""; if ($good_name != "") $where[] = ['a.good_name', "like", "%$good_name%"]; $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):""; if($status!="") $where[]=['a.status',"=",$status]; $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : ""; if ($supplierNo != "") $where[] = ['a.supplierNo', "like", "%$supplierNo%"]; $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : ""; if ($name != "") $where[] = ['b.name', "like", "%$name%"]; $start = isset($this->post['start']) && $this->post['start'] !== "" ? trim($this->post['start']) : ""; if ($start != "") $where[] = ['a.addtime', ">=", $start]; $end = isset($this->post['end']) && $this->post['end'] !== "" ? trim($this->post['end']) : ""; if ($end != "") $where[] = ['a.addtime', "<=", $end.' 23:59:59']; $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $where[]=['a.supplierNo|a.companyNo','=', $relaComNo]; $count = Db::name('good_zixun') ->alias("a") ->join("supplier b","b.code=a.supplierNo","left") ->where($where) ->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('good_zixun') ->alias("a") // ->join("supplier b","b.code=a.supplierNo","left") ->where($where) ->page($page,$size) ->order("a.addtime desc") ->select() ->toArray(); $all_platform_id = array_column($list,'platform_id'); $all_platform = Db::name('platform') ->where(['is_del'=>0,'id'=>$all_platform_id]) ->column('platform_name','id'); $all_brand_id = array_column($list,'brand_id'); $all_brand = Db::name('brand') ->where(['is_del'=>0,'id'=>$all_brand_id]) ->column('brand_name','id'); $all_good_unit = array_column($list,'good_unit'); $all_unit = Db::name('unit') ->where(['is_del'=>0,'id'=>$all_good_unit]) ->column('unit','id'); $all_code = array_merge(array_column($list,'supplierNo'),array_column($list,'companyNo')); $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('getCodeAndName',['code'=>$all_code]); //halt($list); $data=[]; //分类/规格/品牌 等字段取出对应文字 foreach ($list as $value){ $value['cat_info']= made($value['cat_id'],[]); // $platform = Db::name("platform")->where(["id"=>$value['platform_id']])->find(); $value['platform_name'] = $all_platform[$value['platform_id']]??'';//isset($platform['platform_name']) ? $platform['platform_name']:""; $value['platform_code_en'] = '';//isset($platform['platform_code_en']) ? $platform['platform_code_en']:""; // $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find(); $value['supplier_name'] = $tmp[$value['supplierNo']] ?? '';//isset($supplier['name']) ? $supplier['name']:""; // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find(); $value["brand_name"]=$all_brand[$value['brand_id']]??'';//isset($brand['brand_name'])?$brand['brand_name']:""; // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find(); $value['unit'] =$all_unit[$value['good_unit']]??'';//isset($unit['unit'])?$unit['unit']:""; // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find(); $value['company'] = $tmp[$value['companyNo']]??'';//isset($company['company'])?$company['company']:""; // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find(); // $value['company'] = isset($company['company'])?$company['company']:""; $value['stock_total'] = Db::name("good_stock") ->where(['spuCode'=>$value['spuCode'],"is_del"=>0]) ->sum("usable_stock"); // $value['status']=$value['exam_status']; // $value['exclusive']=makeExcluse($value['is_exclusive']); $value['good_info_img']=$value['good_info_img']; $value['good_img']=$value['good_img']; $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray(); $speclist=[]; if(!empty($spec)){ foreach ($spec as $val){ $temp=[]; $temp['spec_id']=$val['spec_id']; $temp['spec_value_id']=$val['spec_value_id']; $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find(); $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:""; $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find(); $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:""; $speclist[]=$temp; } } $value['specinfo']=$speclist; $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :""; $data[]=$value; } return app_show(0,"获取成功",['list'=>$data,'count'=>$count]); } //创建活动 public function create(){ $activity_name = isset($this->post['activity_name'])&&$this->post['activity_name']!="" ? trim($this->post['activity_name']):""; if($activity_name==""){ return error_show(1004,"参数activity_name不能为空"); } $platform_code = isset($this->post['platform_code'])&&$this->post['platform_code']!="" ? trim($this->post['platform_code']):""; if($platform_code==""){ return error_show(1004,"参数platform_code不能为空"); } $company_id = isset($this->post['company_id'])&&$this->post['company_id']!="" ? trim($this->post['company_id']):""; if($company_id==""){ return error_show(1004,"参数company_id不能为空"); } $activity_start = isset($this->post['activity_start'])&&$this->post['activity_start']!="" ? $this->post['activity_start']:""; if($activity_start==""){ return error_show(1004,"参数activity_start不能为空"); } $activity_end = isset($this->post['activity_end'])&&$this->post['activity_end']!="" ? $this->post['activity_end']:""; if($activity_end==""){ return error_show(1004,"参数activity_end不能为空"); } $activity_desc = isset($this->post['activity_desc'])&&$this->post['activity_desc']!="" ? trim($this->post['activity_desc']):""; if($activity_desc==""){ return error_show(1004,"参数activity_desc不能为空"); } $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!=="" ? intval($this->post['is_stock']):""; if($is_stock===""){ return error_show(1004,"参数is_stock不能为空"); } $good_list= isset($this->post['good_list'])&&$this->post['good_list']!=="" ?$this->post['good_list']:""; if($good_list==""){ return error_show(1004,"参数good_list不能为空"); } $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):""; if($token==''){ return error_show(105,"参数token不能为空"); } $user =GetUserInfo($token); if(empty($user)||$user['code']!=0){ return error_show(102,"用户数据不存在"); } $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : ""; $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; $activity_code = makeNo("AT"); Db::startTrans(); try{ $data=[ "activity_name"=>$activity_name, "activity_code"=>$activity_code, "is_stock"=>$is_stock, "start"=>$activity_start, "end"=>$activity_end, "platform_code"=>$platform_code, "activity_desc"=>$activity_desc, "company_id"=>$company_id, "creater"=>$creater, "createrid"=>$createrid, "status"=>1, "is_del"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $inset = Db::name("good_activity")->insertGetId($data); if($inset>0){ if($good_list!=""&&!empty($good_list)){ $temp=[]; $skuCode =array_column($good_list,"skuCode"); $ist = Db::name("good_activity") ->alias("a") ->leftJoin("activity_info b", "a.activity_code = b.activity_code and b.is_del=0") ->where(["b.skuCode" => $skuCode, "a.is_del" => 0]) ->where([["a.status", "<>", 8]]) ->where(function ($query) use ($activity_end, $activity_start) { return $query->whereOr([[["start", "<=", $activity_start], ["end", ">=", $activity_end]], ["start|end", "between", [$activity_start, $activity_end]]]); }) ->select() ->toArray(); if(!empty($ist)){ Db::rollback(); $limit=[]; foreach ($ist as $value){ $limit[]="活动 ".$value['activity_name']. ' 已存在商品 '. $value['good_name']; } return app_show(1007,'活动商品已存在', $limit); } foreach ($good_list as $value){ $lemp = []; $good = Db::name('good')->alias("a")->leftJoin("good_platform b", "a.spuCode=b.spuCode")->where(["skuCode" => $value['skuCode'], "a.is_del" => 0])->findOrEmpty(); $lemp['skuCode']=$value['skuCode']; $lemp['good_name']=isset($good['good_name']) ?$good['good_name']:"" ; $lemp['activity_code']=$activity_code; $lemp['activity_stock']=$value['activity_stock']; $lemp['moq_num']=0; $lemp['cost_price']=0; $lemp['sale_price']=0; $lemp['activity_price']=0; $lemp['status']=0; $lemp['remark']=""; $lemp['is_del']=0; $lemp['addtime']=date("Y-m-d H:i:s"); $lemp['updatetime']=date("Y-m-d H:i:s"); $temp[]=$lemp; //当是库存品的时候校验可用库存数,不满足的时候不能添加 if ($is_stock == 1) { // $usable_stock = Db::name('good_stock') // ->where(['spuCode' => $good['spuCode'], 'is_del' => 0]) // ->sum('usable_stock'); if ($value['activity_stock'] > $good['usable_stock']) { Db::rollback(); // throw new \Exception($lemp['good_name'] . '的库存只有' . $usable_stock); return app_show(1005,'库存不足',[$lemp['good_name']. '的库存只有' . $good['usable_stock']]); } } } $iall=Db::name("activity_info")->insertAll($temp); if($iall==0){ Db::rollback(); return error_show(1005,"新建失败"); } } $stn = ["order_code" => $activity_code, "status" => 0, "action_remark" => '', "action_type" => "create"]; ActionLog::logAdd($this->post['token'], $stn, "HD", $data['status'], $data); $process = ["order_code" => $activity_code, "order_id" => $inset, "order_status" => $data['status'], "order_type" => 'HD', "before_status" => 0, 'holder_id' => $data['createrid']]; ProcessOrder::AddProcess($this->post['token'], $process); Db::commit(); return app_show(0,"新建成功"); } }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } //采购定价 public function cost(){ $good_list= isset($this->post['good_list'])&&!empty($this->post['good_list']) ?$this->post['good_list']:""; if($good_list==""){ return error_show(1004,"参数good_list不能为空"); } $activity_code= isset($this->post['activity_code'])&&$this->post['activity_code']!=="" ?trim($this->post['activity_code']):""; if($activity_code==""){ return error_show(1004,"参数activity_code不能为空"); } $activity = Db::name("good_activity")->where(["activity_code"=>$activity_code,"is_del"=>0])->find(); if($activity==false){ return error_show(1004,"未找到活动数据"); } Db::startTrans(); try{ foreach ($good_list as $value){ $temp=[]; $ladd = Db::name("good_ladder")->where(["skuCode"=>$value['skuCode'],"is_del"=>0])->where ([["min_num","<=",$value['moq_num']]])->order("min_num desc")->find(); $temp["id"]=$value['id']; $temp["cost_price"]=$value['cost_price']; $temp["moq_num"]=$value['moq_num']; $temp["sale_price"]=isset($ladd['sale_price'])?$ladd['sale_price']:0; $temp["updatetime"]=date("Y-m-d H:i:s"); $up=Db::name("activity_info")->save($temp); if($up==false){ Db::rollback(); return error_show(1004,"商品数据更新失败"); } } $old_activity_status = $activity['status']; $activity['status']=2; $activity['updatetime']=date("Y-m-d H:i:s"); $act = Db::name("good_activity")->save($activity); if($act){ $stn = ["order_code" => $activity_code, "status" => $old_activity_status, "action_remark" => '', "action_type" => "status"]; ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity); $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'holder_id' => $activity['createrid']]; ProcessOrder::AddProcess($this->post['token'], $process); Db::commit(); return error_show(0,"商品数据更新成功"); }else{ Db::rollback(); return error_show(1004,"商品数据更新失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } //财务定价 public function activity(){ $good_list= isset($this->post['good_list'])&&!empty($this->post['good_list']) ?$this->post['good_list']:""; if($good_list==""){ return error_show(1004,"参数good_list不能为空"); } $activity_code= isset($this->post['activity_code'])&&$this->post['activity_code']!=="" ?trim($this->post['activity_code']):""; if($activity_code==""){ return error_show(1004,"参数activity_code不能为空"); } $activity = Db::name("good_activity")->where(["activity_code"=>$activity_code,"is_del"=>0])->find(); if($activity==false){ return error_show(1004,"未找到活动数据"); } Db::startTrans(); try{ foreach ($good_list as $value){ $temp=[]; $temp["id"]=$value['id']; $temp["activity_price"]=$value['activity_price']; $temp['is_activity'] = $value['is_activity']; $temp['settle_price'] = $value['settle_price']; $temp["updatetime"]=date("Y-m-d H:i:s"); $up=Db::name("activity_info")->save($temp); if($up==false){ Db::rollback(); return error_show(1004,"商品数据更新失败"); } } $old_activity_status = $activity['status']; $activity['status']=3; $activity['updatetime']=date("Y-m-d H:i:s"); $act = Db::name("good_activity")->save($activity); if($act){ $stn = ["order_code" => $activity_code, "status" => $old_activity_status, "action_remark" => '', "action_type" => "status"]; ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity); $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'holder_id' => $activity['createrid']]; ProcessOrder::AddProcess($this->post['token'], $process); Db::commit(); return error_show(0,"商品数据更新成功"); }else{ Db::rollback(); return error_show(1004,"商品数据更新失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } //财务审核定价 public function exam(){ $good_list= isset($this->post['good_list'])&&!empty($this->post['good_list']) ?$this->post['good_list']:""; if($good_list==""){ return error_show(1004,"参数good_list不能为空"); } $activity_code= isset($this->post['activity_code'])&&$this->post['activity_code']!=="" ?trim($this->post['activity_code']):""; if($activity_code==""){ return error_show(1004,"参数activity_code不能为空"); } $activity = Db::name("good_activity")->where(["activity_code"=>$activity_code,"is_del"=>0])->find(); if($activity==false){ return error_show(1004,"未找到活动数据"); } Db::startTrans(); try{ $isRejectAll = true;//是否全部驳回 foreach ($good_list as $value){ $temp=[]; $temp["id"]=$value['id']; $temp["status"]=$value['status']; $temp["remark"]=$value['remark']; $temp["updatetime"]=date("Y-m-d H:i:s"); $up=Db::name("activity_info")->save($temp); if($up==false){ Db::rollback(); return error_show(1004,"商品数据更新失败"); } if ($isRejectAll && ($value['status'] == 1)) $isRejectAll = false;//只要有一个商品通过,即不能全部驳回 } $old_activity_status = $activity['status']; $activity['status'] = $isRejectAll ? 8 : 4;//4审核通过,8审核未通过 $activity['updatetime']=date("Y-m-d H:i:s"); $act = Db::name("good_activity")->save($activity); if($act){ $stn = ["order_code" => $activity_code, "status" => $old_activity_status, "action_remark" => '', "action_type" => "status"]; ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity); $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'holder_id' => $activity['createrid']]; ProcessOrder::AddProcess($this->post['token'], $process); Db::commit(); return error_show(0,"商品数据审核成功"); }else{ Db::rollback(); return error_show(1004,"商品数据审核失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } //活动详情 public function info() { $activity_code = isset($this->post['activity_code']) && $this->post['activity_code'] !== "" ? trim($this->post['activity_code']) : ""; if ($activity_code == "") { return error_show(1004, "参数activity_code不能为空"); } $activity = Db::name("good_activity") ->alias('ga') ->field('ga.*,p.platform_name,p.platform_type') ->leftJoin('platform p', 'p.id=ga.platform_code AND p.is_del=0') ->where(["ga.activity_code" => $activity_code, "ga.is_del" => 0]) ->find(); if ($activity == false) { return error_show(1004, "未找到活动数据"); } $activity_info = Db::name("activity_info") ->where(["activity_code" => $activity_code, "is_del" => 0]) ->select() ->toArray(); if (!empty($activity_info)) { //状态不是(0待产品部审核,1待采购定价),才会有起订量,才可以考虑计算售价 if ($activity['status'] > 1) { //判断是否是启用实时金价的贵金属 $rs = Db::name('good_platform') ->alias('a') ->join('good g', 'g.spuCode=a.spuCode') ->join('good_nake c', 'c.spuCode=a.spuCode') ->whereIn('a.skuCode', array_column($activity_info, 'skuCode')) ->column('g.cat_id,g.is_gold_price,g.demo_fee,g.open_fee,g.weight,c.cost_fee,c.package_fee,c.mark_fee,c.cert_fee,g.noble_metal,c.nake_fee,c.delivery_fee', 'a.skuCode'); foreach ($activity_info as &$value) { //如果启用了实时金价,且是贵金属 if (isset($rs[$value['skuCode']])) { $top_cat = made($rs[$value['skuCode']]['cat_id']); if (isset($top_cat[0]['id']) && $top_cat[0]['id'] == 6 && $rs[$value['skuCode']]['is_gold_price'] == 1) { $gold_price = Db::name("gold_price1")->where(["type" => $rs[$value['skuCode']]['noble_metal'], "is_del" => 0, "status" => 1])->order("addtime desc")->value('price'); $value['sale_price'] = round($rs[$value['skuCode']]['demo_fee'] / $value['moq_num'] + $rs[$value['skuCode']]['open_fee'] / $value['moq_num'] + $rs[$value['skuCode']]['weight'] * $gold_price + $rs[$value['skuCode']]['cost_fee'] * $rs[$value['skuCode']]['weight'] + $rs[$value['skuCode']]['package_fee'] + $rs[$value['skuCode']]['mark_fee'] + $rs[$value['skuCode']]['cert_fee'] + $rs[$value['skuCode']]['nake_fee'] + $rs[$value['skuCode']]['delivery_fee'], 2); } } } } $activity['info'] = $activity_info; } else $activity['info'] = []; // $activity['info'] = empty($activity_info) ? [] : $activity_info; return app_show(0, "获取成功", $activity); } //修改活动状态 public function actstatus(){ $activity_code= isset($this->post['activity_code'])&&$this->post['activity_code']!=="" ?trim($this->post['activity_code']):""; if($activity_code==""){ return error_show(1004,"参数activity_code不能为空"); } $activity = Db::name("good_activity")->where(["activity_code"=>$activity_code,"is_del"=>0])->find(); if($activity==false){ return error_show(1004,"未找到活动数据"); } $status = isset($this->post['status'])&&$this->post['status']!=="" ?intval($this->post['status']):""; if($status==""){ return error_show(1004,"参数status不能为空"); } $remark =isset($tihs->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):""; if($remark=="" &&$status==8){ return error_show(1004,"参数remark不能为空"); } $old_status = $activity['status']; $activity['status']=$status; $activity['remark']=$remark; $activity['updatetime']=date("Y-m-d H:i:s"); $up = Db::name("good_activity")->save($activity); if($up){ $stn = ["order_code" => $activity_code, "status" => $old_status, "action_remark" => '', "action_type" => "status"]; ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity); $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_status, 'holder_id' => $activity['createrid']]; ProcessOrder::AddProcess($this->post['token'], $process); return app_show(0,"修改成功"); }else{ return error_show(1004,"修改失败"); } } public function query(){ $skuCode= isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):""; if($skuCode==""){ return error_show(1004,"参数skuCode不能为空"); } $where=['a.is_del'=>0,"b.is_del"=>0,"a.status"=>6,"b.status"=>1,"b.skuCode"=>$skuCode]; $condition=['a.skuCode' =>$skuCode,"a.is_del"=>0,'a.exam_status'=>3]; $company = isset($this->post['companyNo'])&&$this->post['companyNo']!=""?trim($this->post['companyNo']):""; if($company!=""){ $where['a.company_id'] = $company; $condition['companyNo'] = $company; } $plat =isset($this->post['platform_id'])&&$this->post['platform_id']!=""?intval($this->post['platform_id']) :""; if($plat!==""){ $where['a.platform_code'] = $plat; $condition['platform_code'] = $plat; } $good = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left') ->where($condition)->select()->toArray(); $goodlist=[]; if(!empty($good)){ foreach ($good as $value){ $temp=[]; //如果是非库存商品,库存数改为最大(即将库存设为无限) $temp['stock_num'] = $value['is_stock'] == 1 ? intval($value['usable_stock']) : 9999; $temp['skuCode']=$value['skuCode']; $temp['spuCode']=$value['spuCode']; $temp['is_stock']=$value['is_stock']; $temp['good_name']=$value['good_name']; $temp['good_img']=$value['good_img']; $temp['good_info_img']=$value['good_info_img']; $temp['noble_metal']=$value['noble_metal']; $temp['noble_name']=$value['noble_metal']!=0?$this->noble[$value['noble_metal']]:""; $goodlist[]=$temp; } } $list = Db::name('good_activity')->alias("a") ->join("activity_info b","b.activity_code=a.activity_code","left") ->where($where)->field('b.id,a.activity_name,a.activity_code,a.is_stock,a.start,a.end,b.skuCode,b.good_name,b.activity_stock, b.cost_price,b.moq_num,b.sale_price,b.activity_price')->select()->toArray(); return app_show(0,"获取成功",["act"=>$list,"good"=>$goodlist]); } //新增库存 public function editStock(){ $actCode=isset($this->post['actCode'])&&$this->post['actCode']!='' ? trim($this->post['actCode']):""; if($actCode==''){ return error_show(1004,"参数 actCode 不能为空"); } $skuCode=isset($this->post['skuCode'])&&$this->post['skuCode']!='' ? trim($this->post['skuCode']):""; if($skuCode==''){ return error_show(1004,"参数 skuCode 不能为空"); } $act_stock=isset($this->post['act_stock'])&&$this->post['act_stock']!='' ? intval($this->post['act_stock']):""; if($act_stock==''){ return error_show(1004,"参数 act_stock 不能为空"); } $act =Db::name("good_activity")->where(["activity_code"=>$actCode,"is_del"=>0])->findOrEmpty(); if(empty($act)){ return error_show(1005,"活动信息不存在"); } if(!in_array($act['status'],[4,5,6]))return error_show(1005,"活动暂时不能修改"); $goodinfo=Db::name("activity_info")->where(["activity_code"=>$actCode,"skuCode"=>$skuCode,"is_del"=>0]) ->findOrEmpty(); if(empty($goodinfo)){ return error_show(1005,"活动商品信息不存在"); } $good = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left') ->where(['a.skuCode' =>$skuCode,"a.is_del"=>0,'a.exam_status'=>3])->findOrEmpty(); if(empty($good)){ return error_show(1005,"商品信息不存在或已下架"); } if($good['is_stock']==1){ // $stock =Db::name("good_stock")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->sum('usable_stock'); if($act_stock+$goodinfo['activity_stock']> $good['usable_stock']){ return error_show(1005,"商品库存不足"); } } $update =["activity_stock"=>$act_stock+$goodinfo['activity_stock'],"updatetime"=>date("Y-m-d H:i:s")]; $up=Db::name("activity_info")->where($goodinfo)->update($update); return $up ? app_show(0,"活动库存增加成功"):error_show(1006,"活动库存增加失败"); } }