CommissionsDetail.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\model\user;
  13. use app\common\model\BaseModel;
  14. use app\common\model\OrderGoods;
  15. /**
  16. * 配送模板模型
  17. * Class Delivery
  18. * @package app\common\model
  19. */
  20. class CommissionsDetail extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'commissions_detail_order';
  24. // 定义主键
  25. protected $pk = 'id';
  26. const NOT_SHOP_COMMISSION = 0;
  27. const IS_SHOP_COMMISSION = 1;
  28. const MISS_SHOP_COMMISSION = 2;
  29. const CLEARING_STATUS_WAIT = 0; // 待结算
  30. const CLEARING_STATUS_FINISHED = 1; // 已结算
  31. const CLEARING_STATUS_REFUND = 2; // 已退款/已退货退款
  32. const ROLE = [1=>'普通用户',2=>'店老板',3=>'店长',4=>'店员',5=>'煮饭厨师',99=>'分销员'];
  33. const CLEARING_STATUS = [0=>'待结算',1=>'已结算',2=>'已退款'];
  34. /**
  35. * 关联用户
  36. * @return \think\model\relation\BelongsTo
  37. */
  38. public function user()
  39. {
  40. $model = "app\\common\\model\\User";
  41. return $this->belongsTo($model);
  42. }
  43. public static function getUsableList($storeId){
  44. return self::alias('cm')
  45. ->leftJoin('order og','cm.order_id=og.order_id')
  46. ->where('cm.clearing_status',0)
  47. ->where('og.commission_settlement_time','>',0)
  48. ->where('og.commission_settlement_time','<',time())
  49. ->where('og.commission_settlement_status',0)
  50. ->whereNotExists('select order_goods_id from yoshop_order_goods where order_id=cm.order_id and frozen_status=1')
  51. ->field('cm.id,cm.order_id,cm.user_id,cm.clearing_money,cm.commission_percent,og.order_no')
  52. ->select();
  53. }
  54. /**
  55. * 更新分佣结算状态(整个订单)
  56. * @param $orderId
  57. * @param int $clearingStatus 2:不结算
  58. * @return CommissionsDetail
  59. */
  60. public static function updateAllDetails($orderId, $clearingStatus = self::MISS_SHOP_COMMISSION){
  61. $arr['clearing_status'] = $clearingStatus;
  62. if ($clearingStatus == self::MISS_SHOP_COMMISSION){
  63. $arr['remark'] = '订单退全款扣除全部佣金';
  64. }
  65. return self::where('order_id', $orderId)->update($arr);
  66. }
  67. /**
  68. * 订单商品列表
  69. * @return \think\model\relation\HasMany
  70. */
  71. public function goods()
  72. {
  73. $module = self::getCalledModule();
  74. return $this->hasMany("app\\{$module}\\model\\OrderGoods",'order_id','order_id')->withoutField('content');
  75. }
  76. /**
  77. * 订单列表
  78. * @return \think\model\relation\hasOne
  79. */
  80. public function orders()
  81. {
  82. $module = self::getCalledModule();
  83. return $this->hasOne("app\\{$module}\\model\\Order",'order_id','order_id');
  84. }
  85. public static function sumOrderSaleVolume(array $wheres){
  86. $wheres[] = ['is_delete','=',0];
  87. return self::where($wheres)->sum('order_sale_volume');
  88. }
  89. }