ImportSku.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\common\model;
  4. use think\Model;
  5. class ImportSku Extends Model
  6. {
  7. // 自动写入时间戳字段
  8. protected $autoWriteTimestamp = true;
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. protected $type = [
  12. 'createtime' => 'timestamp:Y-m-d H:i',
  13. 'updatetime' => 'timestamp:Y-m-d H:i',
  14. ];
  15. public function stockconfig()
  16. {
  17. return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,title');
  18. }
  19. //获取店铺下规格
  20. public static function getSpecsIdByShopId(string $shop_id, string $spec_id): object
  21. {
  22. // return self::where('shop_id', $shop_id)->where('sku_id', $spec_id)->findOrEmpty();
  23. $result = self::alias('f')
  24. ->where(['f.shop_id'=>$shop_id,'f.sku_id'=>$spec_id])
  25. ->join('yun_product_config p', 'f.variety_id = p.type_id AND f.spec_id = p.id', 'INNER')
  26. ->field([
  27. 'f.*',
  28. 'p.type_id',
  29. 'p.title as spec_name',
  30. 'p.another_name as box_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. }