Merchant.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-04-16
  7. *
  8. *
  9. */
  10. namespace app\common\model\system\merchant;
  11. use app\common\dao\store\product\ProductDao;
  12. use app\common\model\BaseModel;
  13. use app\common\model\store\coupon\StoreCouponProduct;
  14. use app\common\model\store\coupon\StoreCouponUser;
  15. use app\common\model\store\product\Product;
  16. use app\common\model\user\User;
  17. class Merchant extends BaseModel
  18. {
  19. /**
  20. * @return string
  21. * @author xaboy
  22. * @day 2020-03-30
  23. */
  24. public static function tablePk(): string
  25. {
  26. return 'mer_id';
  27. }
  28. /**
  29. * @return string
  30. * @author xaboy
  31. * @day 2020-03-30
  32. */
  33. public static function tableName(): string
  34. {
  35. return 'merchant';
  36. }
  37. public function product()
  38. {
  39. return $this->hasMany(Product::class, 'mer_id', 'mer_id');
  40. }
  41. public function showProduct()
  42. {
  43. return $this->hasMany(Product::class, 'mer_id', 'mer_id')
  44. ->where((new ProductDao())->productShow())
  45. ->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag');
  46. }
  47. public function recommend()
  48. {
  49. return $this->hasMany(Product::class, 'mer_id', 'mer_id')
  50. ->where((new ProductDao())->productShow())
  51. ->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,ot_price')
  52. ->where('seckill',0)
  53. ->where('is_good',1)
  54. ->order('product_id','desc')
  55. ->limit(3);
  56. }
  57. public function coupon()
  58. {
  59. $time = date('Y-m-d H:i:s');
  60. return $this->hasMany(StoreCouponUser::class, 'mer_id', 'mer_id')->where('start_time', '<', $time)->where('end_time', '>', $time)
  61. ->where('is_fail', 0)->where('status', 0)->order('coupon_price DESC')
  62. ->with(['product' => function ($query) {
  63. $query->field('coupon_id,product_id');
  64. }, 'coupon' => function ($query) {
  65. $query->field('coupon_id,type');
  66. }]);
  67. }
  68. public function MerchantIntention(){
  69. return $this->hasOne(MerchantIntention::class, 'mer_id', 'mer_id');
  70. }
  71. public function merchantCategory()
  72. {
  73. return $this->hasOne(MerchantCategory::class, 'merchant_category_id', 'category_id');
  74. }
  75. public function getMerCommissionRateAttr()
  76. {
  77. return $this->commission_rate ? $this->commission_rate : $this->merchantCategory->commission_rate;
  78. }
  79. public function spread()
  80. {
  81. return $this->hasOne(User::class, 'uid', 'recommender');
  82. }
  83. }