Supplier.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\common\model\supplier;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 商家供应商模型
  6. */
  7. class Supplier extends BaseModel
  8. {
  9. protected $name = 'supplier';
  10. protected $pk = 'shop_supplier_id';
  11. /**
  12. * 关联应用表
  13. */
  14. public function app()
  15. {
  16. return $this->belongsTo('app\\common\\model\\app\\App', 'app_id', 'app_id');
  17. }
  18. /**
  19. * 关联logo
  20. */
  21. public function logo()
  22. {
  23. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'logo_id');
  24. }
  25. /**
  26. * 关联品牌类型
  27. */
  28. public function category()
  29. {
  30. return $this->hasOne('app\\common\\model\\supplier\\Category', 'category_id', 'category_id');
  31. }
  32. /**
  33. * 关联business
  34. */
  35. public function business()
  36. {
  37. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'business_id');
  38. }
  39. /**
  40. * 关联超管
  41. */
  42. public function superUser()
  43. {
  44. return $this->hasOne('app\\common\\model\\supplier\\User', 'shop_supplier_id', 'shop_supplier_id')
  45. ->where('is_super','=', 1);
  46. }
  47. /**
  48. * 详情
  49. */
  50. public static function detail($shop_supplier_id, $with = [])
  51. {
  52. return (new static())->with($with)->find($shop_supplier_id);
  53. }
  54. /**
  55. * 累积供应商结算金额 (批量)
  56. */
  57. public function onBatchIncSupplierMoney($data)
  58. {
  59. foreach ($data as $supplierId => $supplierMoney) {
  60. $this->where(['shop_supplier_id' => $supplierId])
  61. ->inc('total_money', $supplierMoney)
  62. ->inc('money', $supplierMoney)
  63. ->update();
  64. }
  65. return true;
  66. }
  67. }