ImportSku.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\common\model;
  4. use think\Model;
  5. use app\common\model\PackSpecs;
  6. class ImportSku Extends Model
  7. {
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = true;
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. protected $type = [
  13. 'createtime' => 'timestamp:Y-m-d H:i',
  14. 'updatetime' => 'timestamp:Y-m-d H:i',
  15. ];
  16. public function stockconfig()
  17. {
  18. return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,title');
  19. }
  20. //获取店铺下规格
  21. public static function getSpecsIdByShopId(string $shop_id, string $spec_id): object
  22. {
  23. // return self::where('shop_id', $shop_id)->where('sku_id', $spec_id)->findOrEmpty();
  24. $result = self::alias('f')
  25. ->where(['f.shop_id'=>$shop_id,'f.sku_id'=>$spec_id])
  26. ->join('yun_product_config p', 'f.variety_id = p.type_id AND f.spec_id = p.id', 'INNER')
  27. ->field([
  28. 'f.*',
  29. 'p.type_id',
  30. 'p.title as spec_name',
  31. 'p.weight',
  32. 'p.box_id'
  33. ])
  34. ->findOrEmpty();
  35. return $result;
  36. }
  37. //批量插入规格
  38. public static function insertSpecs(string $shop_id, string $sku_id, int $variety_id, int $spec_id)
  39. {
  40. return self::create(['shop_id'=> $shop_id, 'variety_id'=>$variety_id, 'spec_id'=>$spec_id, 'sku_id'=>$sku_id]);
  41. }
  42. //获规格下的打包规格
  43. public static function getPackSpecs(string $shop_id, string $spec_id)
  44. {
  45. // return self::where('shop_id', $shop_id)->where('sku_id', $spec_id)->findOrEmpty();
  46. $result = self::alias('f')
  47. ->where(['f.shop_id'=>$shop_id,'f.sku_id'=>$spec_id])
  48. ->join('yun_product_config p', 'f.variety_id = p.type_id AND f.spec_id = p.id', 'INNER')
  49. ->field([
  50. 'p.pack_specs_id'
  51. ])
  52. ->findOrEmpty();
  53. $pack_specs_id=$result->pack_specs_id;
  54. if(empty($pack_specs_id)) return null;
  55. $packSpecs=new PackSpecs();
  56. $result=$packSpecs->where('id',$pack_specs_id)->findOrEmpty();
  57. return $result;
  58. }
  59. }