ProductGroupSku.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\product;
  12. use app\common\model\BaseModel;
  13. use app\common\repositories\store\order\StoreOrderRepository;
  14. class ProductGroupSku extends BaseModel
  15. {
  16. /**
  17. * TODO
  18. * @return string
  19. * @author Qinii
  20. * @day 1/7/21
  21. */
  22. public static function tablePk(): string
  23. {
  24. return '';
  25. }
  26. public function sku()
  27. {
  28. return $this->hasOne(ProductAttrValue::class,'unique','unique');
  29. }
  30. public function getSalesAttr()
  31. {
  32. $make = app()->make(StoreOrderRepository::class);
  33. $where = [
  34. 'product_sku' => $this->unique,
  35. 'product_type' => 4,
  36. 'exsits_id' => $this->product_group_id,
  37. ];
  38. $count = $make->getTattendCount($where,null)->sum('product_num');
  39. return $count;
  40. }
  41. /**
  42. * TODO
  43. * @return string
  44. * @author Qinii
  45. * @day 1/7/21
  46. */
  47. public static function tableName(): string
  48. {
  49. return 'store_product_group_sku';
  50. }
  51. public function searchProductGroupIdAttr($query,$value)
  52. {
  53. $query->where('product_group_id',$value);
  54. }
  55. public function searchuniqueAttr($query,$value)
  56. {
  57. $query->where('unique',$value);
  58. }
  59. }