ConsultTemp.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. foreach ($list as $item){
  57. $item['good_unit'] = $item['unit_id'];
  58. $item['specinfo'] = json_encode($item['specinfo'],JSON_UNESCAPED_UNICODE);
  59. $item['good_img'] = implode(",",$item['good_img']);
  60. $item['customized'] = $item['work_day'];
  61. $item['craft_desc'] = $item['good_name'];
  62. $item['noble_metal'] = $item['metal_id'];
  63. $item['isChild'] = 1;
  64. $item['creater'] = $item['cgder'];
  65. $item['createrid'] = $item['cgderid'];
  66. $addGood[] = array_merge($item->toArray(),$marage);
  67. $combind[]=[
  68. "spuCode"=>$marage["parent_code"],
  69. "good_name"=>$marage["parent_name"],
  70. "childCode"=>$item["spuCode"],
  71. "child_name"=>$item["good_name"],
  72. "child_num"=>$item["good_num"],
  73. ];
  74. }
  75. if(empty($addGood)==false)(new GoodZixun())->strict(false)->insertAll($addGood);
  76. if(empty($combind)==false)(new GoodCombind())->insertAll($combind);
  77. }
  78. }
  79. }