123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\model;
- use think\Model;use think\model\concern\SoftDelete;
- /**
- * @mixin \think\Model
- */
- class ConsultTemp extends Model
- {
- use SoftDelete;
- protected $createTime="addtime";
- protected $updateTime="updatetime";
- protected $deleteTime = 'delete_time';
-
- public function CreateByZx($list,$merage){
- foreach ($list as $key=>&$item){
- isset($item['id'])?:$item['id']=null;
- if(isset($item['spuCode'])==false){
- $item['spuCode']= substr(makeNo("SPU"), 0, -2) . str_pad(strval($key), 2, '0', STR_PAD_LEFT);
- }
- if(empty($item['specinfo'])==false){
- foreach ($item['specinfo'] as &$v){
- $v['spec_name'] = Specs::where("id",$v['spec_id'])->value("spec_name",'');
- $v['spec_value_name'] = SpecValue::where("id",$v['spec_value_id'])->value("spec_value",'');
- }
- }
- $item = array_merge($item,$merage);
- }
- self::saveAll($list);
- }
-
- public function Brand(){
- return $this->belongsTo(Brand::class,"brand_id")->bind(["brand_name"]);
- }
-
- public function Unit(){
- return $this->belongsTo(Unit::class,'unit_id')->bind(['unit_name'=>"unit"]);
- }
-
- public function Cat(){
- return $this->belongsTo(Cat::class,'cat_id')->bind(["cat_name"=>'search']);
- }
-
- public function GetSpecinfoAttr($v){
- return json_decode($v,true);
- }
-
- public function SetSpecinfoAttr($v){
- return json_encode($v,JSON_UNESCAPED_UNICODE);
- }
-
- public function GetGoodImgAttr($v){
- return json_decode($v,true);
- }
-
- public function SetGoodImgAttr($v){
- return json_encode($v,JSON_UNESCAPED_UNICODE);
- }
-
-
- public function CreateGood($bidNo,$marage){
- $list =$this->where(["bidNo"=>$bidNo])->hidden(["id"])->select();
- if($list->isEmpty()==false){
- $addGood=[];
- $combind =[];
- $goodTax=[];
- foreach ($list as $item){
- $item['good_unit'] = $item['unit_id'];
- $item['specinfo'] = json_encode($item['specinfo'],JSON_UNESCAPED_UNICODE);
- $item['good_img'] = implode(",",$item['good_img']);
- $item['customized'] = $item['work_day'];
- $item['craft_desc'] = $item['good_name'];
- $item['noble_metal'] = $item['metal_id'];
- $item['isChild'] = 1;
- $item['creater'] = $item['cgder'];
- $item['createrid'] = $item['cgderid'];
- $addGood[] = array_merge($item->toArray(),$marage);
- $combind[]=[
- "spuCode"=>$marage["parent_code"],
- "good_name"=>$marage["parent_name"],
- "childCode"=>$item["spuCode"],
- "child_name"=>$item["good_name"],
- "child_num"=>$item["good_num"],
- ];
- if($item['open_type']==1){
- $goodTax[]=[
- 'spuCode'=>$item['spuCode'],
- 'companyNo'=>$item['companyNo'],
- 'tax_id'=>$item['tax_id'],
- "open_type"=>$item['open_type'],
- 'inv_good_name'=>$item['inv_good_name'],
- 'tax'=>$item['tax'],
- 'out_tax_id'=>$item['out_tax_id'],
- 'out_tax'=>str_replace('%','',$item['out_tax']),
- "cgd_tax_id"=>$item['cgd_tax_id'],
- "cgd_tax"=>str_replace("%","",$item['cgd_tax']),
- "status"=>2,
- 'createrid' => $marage['createrid'],
- 'creater' => $marage['creater'],
- ];
- }
- }
- if(empty($addGood)==false)(new GoodZixun())->strict(false)->insertAll($addGood);
- if(empty($combind)==false)(new GoodCombind())->insertAll($combind);
- if(empty($goodTax)==false)(new GoodTax())->insertAll($goodTax);
- }
- }
- }
|