123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\common\model\user;
- use app\common\model\BaseModel;
- use app\common\model\OrderGoods;
- /**
- * 配送模板模型
- * Class Delivery
- * @package app\common\model
- */
- class CommissionsDetail extends BaseModel
- {
- // 定义表名
- protected $name = 'commissions_detail_order';
- // 定义主键
- protected $pk = 'id';
- const NOT_SHOP_COMMISSION = 0;
- const IS_SHOP_COMMISSION = 1;
- const MISS_SHOP_COMMISSION = 2;
- const CLEARING_STATUS_WAIT = 0; // 待结算
- const CLEARING_STATUS_FINISHED = 1; // 已结算
- const CLEARING_STATUS_REFUND = 2; // 已退款/已退货退款
- const ROLE = [1=>'普通用户',2=>'店老板',3=>'店长',4=>'店员',5=>'煮饭厨师',99=>'分销员'];
- const CLEARING_STATUS = [0=>'待结算',1=>'已结算',2=>'已退款'];
- /**
- * 关联用户
- * @return \think\model\relation\BelongsTo
- */
- public function user()
- {
- $model = "app\\common\\model\\User";
- return $this->belongsTo($model);
- }
- public static function getUsableList($storeId){
- return self::alias('cm')
- ->leftJoin('order og','cm.order_id=og.order_id')
- ->where('cm.clearing_status',0)
- ->where('og.commission_settlement_time','>',0)
- ->where('og.commission_settlement_time','<',time())
- ->where('og.commission_settlement_status',0)
- ->whereNotExists('select order_goods_id from yoshop_order_goods where order_id=cm.order_id and frozen_status=1')
- ->field('cm.id,cm.order_id,cm.user_id,cm.clearing_money,cm.commission_percent,og.order_no')
- ->select();
- }
- /**
- * 更新分佣结算状态(整个订单)
- * @param $orderId
- * @param int $clearingStatus 2:不结算
- * @return CommissionsDetail
- */
- public static function updateAllDetails($orderId, $clearingStatus = self::MISS_SHOP_COMMISSION){
- $arr['clearing_status'] = $clearingStatus;
- if ($clearingStatus == self::MISS_SHOP_COMMISSION){
- $arr['remark'] = '订单退全款扣除全部佣金';
- }
- return self::where('order_id', $orderId)->update($arr);
- }
- /**
- * 订单商品列表
- * @return \think\model\relation\HasMany
- */
- public function goods()
- {
- $module = self::getCalledModule();
- return $this->hasMany("app\\{$module}\\model\\OrderGoods",'order_id','order_id')->withoutField('content');
- }
- /**
- * 订单列表
- * @return \think\model\relation\hasOne
- */
- public function orders()
- {
- $module = self::getCalledModule();
- return $this->hasOne("app\\{$module}\\model\\Order",'order_id','order_id');
- }
- public static function sumOrderSaleVolume(array $wheres){
- $wheres[] = ['is_delete','=',0];
- return self::where($wheres)->sum('order_sale_volume');
- }
- }
|