ConsultTemp.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;use think\model\concern\SoftDelete;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class ConsultTemp extends Model
  9. {
  10. use SoftDelete;
  11. protected $createTime="addtime";
  12. protected $updateTime="updatetime";
  13. protected $deleteTime = 'delete_time';
  14. public function CreateByZx($list,$merage){
  15. foreach ($list as $key=>&$item){
  16. isset($item['id'])?:$item['id']=null;
  17. if(isset($item['spuCode'])==false){
  18. $item['spuCode']= substr(makeNo("SPU"), 0, -2) . str_pad(strval($key), 2, '0', STR_PAD_LEFT);
  19. }
  20. if(empty($item['specinfo'])==false){
  21. foreach ($item['specinfo'] as &$v){
  22. $v['spec_name'] = Specs::where("id",$v['spec_id'])->value("spec_name",'');
  23. $v['spec_value_name'] = SpecValue::where("id",$v['spec_value_id'])->value("spec_value",'');
  24. }
  25. }
  26. $item = array_merge($item,$merage);
  27. }
  28. self::saveAll($list);
  29. }
  30. public function Brand(){
  31. return $this->belongsTo(Brand::class,"brand_id")->bind(["brand_name"]);
  32. }
  33. public function Unit(){
  34. return $this->belongsTo(Unit::class,'unit_id')->bind(['unit_name'=>"unit"]);
  35. }
  36. public function Cat(){
  37. return $this->belongsTo(Cat::class,'cat_id')->bind(["cat_name"=>'search']);
  38. }
  39. public function GetSpecinfoAttr($v){
  40. return json_decode($v,true);
  41. }
  42. public function SetSpecinfoAttr($v){
  43. return json_encode($v,JSON_UNESCAPED_UNICODE);
  44. }
  45. public function GetGoodImgAttr($v){
  46. return json_decode($v,true);
  47. }
  48. public function SetGoodImgAttr($v){
  49. return json_encode($v,JSON_UNESCAPED_UNICODE);
  50. }
  51. public function CreateGood($bidNo,$marage){
  52. $list =$this->where(["bidNo"=>$bidNo])->hidden(["id"])->select();
  53. if($list->isEmpty()==false){
  54. $addGood=[];
  55. $combind =[];
  56. $goodTax=[];
  57. foreach ($list as $item){
  58. $item['good_unit'] = $item['unit_id'];
  59. $item['specinfo'] = json_encode($item['specinfo'],JSON_UNESCAPED_UNICODE);
  60. $item['good_img'] = implode(",",$item['good_img']);
  61. $item['customized'] = $item['work_day'];
  62. $item['craft_desc'] = $item['good_name'];
  63. $item['noble_metal'] = $item['metal_id'];
  64. $item['isChild'] = 1;
  65. $item['creater'] = $item['cgder'];
  66. $item['createrid'] = $item['cgderid'];
  67. $addGood[] = array_merge($item->toArray(),$marage);
  68. $combind[]=[
  69. "spuCode"=>$marage["parent_code"],
  70. "good_name"=>$marage["parent_name"],
  71. "childCode"=>$item["spuCode"],
  72. "child_name"=>$item["good_name"],
  73. "child_num"=>$item["good_num"],
  74. ];
  75. if($item['open_type']==1){
  76. $goodTax[]=[
  77. 'spuCode'=>$item['spuCode'],
  78. 'companyNo'=>$item['companyNo'],
  79. 'tax_id'=>$item['tax_id'],
  80. "open_type"=>$item['open_type'],
  81. 'inv_good_name'=>$item['inv_good_name'],
  82. 'tax'=>$item['tax'],
  83. 'out_tax_id'=>$item['out_tax_id'],
  84. 'out_tax'=>str_replace('%','',$item['out_tax']),
  85. "cgd_tax_id"=>$item['cgd_tax_id'],
  86. "cgd_tax"=>str_replace("%","",$item['cgd_tax']),
  87. "status"=>2,
  88. 'createrid' => $marage['createrid'],
  89. 'creater' => $marage['creater'],
  90. ];
  91. }
  92. }
  93. if(empty($addGood)==false)(new GoodZixun())->strict(false)->insertAll($addGood);
  94. if(empty($combind)==false)(new GoodCombind())->insertAll($combind);
  95. if(empty($goodTax)==false)(new GoodTax())->insertAll($goodTax);
  96. }
  97. }
  98. }