ImportGoods.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/2/22
  6. * Time: 19:35
  7. */
  8. namespace app\common\models;
  9. use app\backend\modules\goods\models\Sale;
  10. use app\backend\modules\goods\observers\GoodsObserver;
  11. use app\common\exceptions\AppException;
  12. use Illuminate\Database\Eloquent\Builder;
  13. use Illuminate\Database\Eloquent\SoftDeletes;
  14. use Illuminate\Support\Facades\DB;
  15. use app\common\models\Coupon;
  16. class ImportGoods extends BaseModel
  17. {
  18. use SoftDeletes;
  19. public $table = 'yz_goods';
  20. public static function getGoodsByIdAll($goodsId)
  21. {
  22. $model = self::where('id', $goodsId);
  23. $model->with(['hasManySpecs'=>function($query){
  24. return $query->with('hasManySpecsItem');
  25. }]);
  26. $model->with('hasManyOptions');
  27. $model->with('hasManyParam');
  28. $model->with('hasOneShare');
  29. return $model;
  30. }
  31. public function hasManyParam()
  32. {
  33. return $this->hasMany('app\common\models\GoodsParam','goods_id','id');
  34. }
  35. public function hasManySpecs()
  36. {
  37. return $this->hasMany('app\common\models\GoodsSpec','goods_id','id');
  38. }
  39. public function hasManyOptions()
  40. {
  41. return $this->hasMany('app\common\models\GoodsOption','goods_id','id');
  42. }
  43. public function hasOneShare()
  44. {
  45. return $this->hasOne('app\common\models\goods\Share','goods_id','id');
  46. }
  47. }