87 行
5.4 KiB
PHP
可执行文件
87 行
5.4 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Distribution\Model;
|
||
|
||
/**
|
||
* 分销/订单购买记录表视图模型
|
||
* Class DisBillOrderModel
|
||
* @package Common\Model
|
||
*/
|
||
class DisBillOrderModel extends \Common\Model\BaseViewModel
|
||
{
|
||
public $viewFields = array(
|
||
'dis_order' => array(
|
||
'_table' => 'ls_distribution_order',
|
||
'id', //int(11) NOT NULL AUTO_INCREMENT,
|
||
'bill_id', //int(11) NOT NULL DEFAULT '0' COMMENT '订单id',
|
||
'dis_str_id', //int(11) NOT NULL DEFAULT '0' COMMENT '分销商品ID',
|
||
'did', //int(11) NOT NULL DEFAULT '0' COMMENT '一级分销员ID',
|
||
'pid', //int(11) NOT NULL DEFAULT '0' COMMENT '二级分销员ID',
|
||
'sell_first_money', //decimal(10,2) DEFAULT '0.00' COMMENT '商品一级佣金',
|
||
'sell_second_money', //decimal(10,2) DEFAULT '0.00' COMMENT '商品二级佣金',
|
||
'withdraw_state', //tinyint(1) DEFAULT '0' COMMENT '结算情况 0未结算 1已结算 2已失效',
|
||
'first_refund_money', //decimal(10,2) DEFAULT '0.00' COMMENT '一级佣金被退金额',
|
||
'second_refund_money', //decimal(10,2) DEFAULT '0.00' COMMENT '二级佣金被退金额',
|
||
'first_balance_rate', //decimal(10,2) DEFAULT '0.00' COMMENT '一级佣金比',
|
||
'second_balance_rate', //decimal(10,2) DEFAULT '0.00' COMMENT '二级佣金比',
|
||
'settlement_date', //int(11) DEFAULT 0 NULL COMMENT '结算时间',
|
||
'total_amount', //decimal(10,2) DEFAULT 0.00 NULL COMMENT '支付金额(除去配送费)',
|
||
'_type' => 'LEFT',
|
||
),
|
||
'retail_order' => array(
|
||
'_table' => 'ls_retail_bill_order',
|
||
'id' => 'retail_order_id', //int(11) NOT NULL AUTO_INCREMENT,
|
||
'all_money', //decimal(10,2) DEFAULT NULL COMMENT '总价',
|
||
'pay_state', //tinyint(1) DEFAULT '0' COMMENT '0未支付 1已支付 2待支付(确认订单或已支付定金)',
|
||
'pay_type', //tinyint(1) DEFAULT '0' COMMENT '支付类型 1现金 2银行卡 3微信 4支付宝 5会员余额 6小程序微信 7其他 8组合',
|
||
'refund_status', //tinyint(1) DEFAULT '0' COMMENT '订单类型 0正常买单 1申请退款或换货 2退款换货成功 3换货中、待用户发货 4用户已发货、待商家收货 5商家已收货、待商家发货或退款 6驳回退款或换货 7取消退款换货',
|
||
'type', //tinyint(1) DEFAULT NULL COMMENT '应用类型 1商城 2店内',
|
||
'order_type', //tinyint(1) DEFAULT '1' COMMENT '订单类型 默认为1:购买订单 2:退款订单 3换货订单',
|
||
'add_time', //varchar(20) DEFAULT NULL COMMENT '添加时间',
|
||
'vid', //int(11) DEFAULT NULL COMMENT '会员卡id',
|
||
'store_id', //int(11) DEFAULT NULL COMMENT '门店id',
|
||
'merchant_id', //int(11) DEFAULT NULL COMMENT '商户id',
|
||
'cashier_id', //int(11) DEFAULT NULL COMMENT '收银员id',
|
||
'guide_id', //int(11) DEFAULT NULL COMMENT '导购员id',
|
||
'order_no', //varchar(50) DEFAULT NULL COMMENT '订单号',
|
||
'uid', //int(11) DEFAULT NULL COMMENT '小程序用户id',
|
||
'refund_no', //varchar(32) DEFAULT '0' COMMENT '(属于退款订单) 保存被退款的订单编号',
|
||
'refund_money', //decimal(11,2) DEFAULT '0.00' COMMENT '退款金额',
|
||
'amount_received', //decimal(11,2) DEFAULT '0.00' COMMENT '实收金额',
|
||
'give_change', //decimal(11,2) DEFAULT '0.00' COMMENT '找零金额',
|
||
'zero_storage', //decimal(11,2) DEFAULT '0.00' COMMENT '存零金额',
|
||
'finish_time', //varchar(20) DEFAULT NULL COMMENT '订单完成时间',
|
||
'pay_money', //decimal(10,2) DEFAULT '0.00' COMMENT '已经支付的金额',
|
||
'upgrade_state', //tinyint(1) DEFAULT '0' COMMENT '是否升级为plus会员 0否 1是',
|
||
'deliver_state', //tinyint(1) DEFAULT '0' COMMENT '用户退款换货订单是否需要客户发货 0不需要 1需要',
|
||
'express_id', //int(11) DEFAULT '0' COMMENT '快递express_order的id',
|
||
'operation_id', //int(11) DEFAULT '0' COMMENT '后台操作人id',
|
||
'_on' => 'dis_order.bill_id = retail_order.id',
|
||
),
|
||
);
|
||
|
||
/**
|
||
* 计算门店在固定时间内的佣金结算金额
|
||
* @param $item
|
||
* @return mixed
|
||
*/
|
||
public function getStoreSettledInfo($item)
|
||
{
|
||
$map = array(
|
||
'order_type' => 1,
|
||
'pay_state' => 1,
|
||
'withdraw_state' => 1,
|
||
'store_id' => $item['store_id'],
|
||
'settlement_date' => array('between', array($item['start_time'], $item['end_time'])),
|
||
);
|
||
$sell_first_money = $this->getSum($map, 'sell_first_money');
|
||
$sell_second_money = $this->getSum($map, 'sell_second_money');
|
||
$first_refund_money = $this->getSum($map, 'first_refund_money');
|
||
$second_refund_money = $this->getSum($map, 'second_refund_money');
|
||
$money = bcadd($sell_first_money, $sell_second_money, 2);
|
||
$refund_money = bcadd($first_refund_money, $second_refund_money, 2);
|
||
$item['money'] = bcsub($money, $refund_money, 2);
|
||
return $item;
|
||
}
|
||
}
|