OrderCategory.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class OrderCategory extends Model{
  6. use SoftDelete;
  7. protected $createTime = 'createTime';
  8. protected $deleteTime='delete_time';
  9. public function GoodInfo(){
  10. return $this->belongsTo(Good::class,"spuCode","spuCode")->bind(["good_name"]);
  11. }
  12. public static function checkInfo($code,$orderType,$info){
  13. if(!empty($info)){
  14. $save=[];
  15. foreach ($info as $key=>$value){
  16. $ist = self::where(["code"=>$code,"order_type"=>$orderType,"spuCode"=>$value['spuCode']])->findOrEmpty();
  17. if($ist->isEmpty() || $ist->cat_code==''){
  18. $Temp=[
  19. "id"=>$ist->id??null,
  20. "code"=>$code,
  21. "order_type"=>$orderType,
  22. "spuCode"=>$value['spuCode'],
  23. "cat_code"=>$value['cat_code']??"",
  24. "cat_name"=>$value['cat_name']??"",
  25. "short_name"=>$value['short_name']??"",
  26. "merge_code"=>$value['merge_code']??"",
  27. "tax"=>$value['tax']??"",
  28. "inv_good_name"=>$value['inv_good_name']
  29. ];
  30. $save[]=$Temp;
  31. }
  32. }
  33. if(!empty($save)){
  34. (new OrderCategory)->saveAll($save);
  35. }
  36. }
  37. }
  38. public static function GetTaxInfoByCode($code){
  39. $info=self::with(['GoodInfo'])->where(["code"=>$code])->field(["code","spuCode","cat_code","cat_name","merge_code","short_name","tax","inv_good_name"])->select();
  40. $temp=[];
  41. if(!empty($info)){
  42. if (is_array($code)){
  43. foreach ($info as $value){
  44. $temp[$value['code']][]=$value;
  45. }
  46. }else $temp= $info->toArray();
  47. }
  48. return $temp;
  49. }
  50. }