ConsultTemp.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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])->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. $addGood[] = array_merge($item->toArray(),$marage);
  63. $combind[]=[
  64. "spuCode"=>$marage["parent_code"],
  65. "good_name"=>$marage["parent_name"],
  66. "childCode"=>$item["spuCode"],
  67. "child_name"=>$item["good_name"],
  68. "child_num"=>$item["good_num"],
  69. ];
  70. }
  71. if(empty($addGood)==false)(new GoodZixun())->strict(false)->insertAll($addGood);
  72. if(empty($combind)==false)(new GoodCombind())->insertAll($combind);
  73. }
  74. }
  75. }