1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace app\common\model;
- class UserIntegralModel extends BaseModel
- {
- protected $table='user_integral';
- /**
- * 获取用户下单时的积分抵扣
- * @param $user_id
- * @param $total_price 订单总金额
- * @param $total_deduction_integral 抵扣积分
- * @return array
- */
- public function checkDeductionIntegral($user_id,$total_price,$total_deduction_integral)
- {
- $integral_config=[
- 'integral'=>0,
- 'status'=>0,
- 'money'=>0,//扣除积分后的金额
- 'money_in'=>0,//扣除积分后的金额
- ];
- if($total_deduction_integral>0){
- $integral = $this->where(['user_id'=>$user_id,'status'=>1])->sum('integral');
- if($integral>$total_deduction_integral){
- $integral_money = $total_deduction_integral;
- $integral_config=[
- 'integral'=>$total_deduction_integral,
- 'status'=>1,
- 'money'=>getMoneyFormat(($total_price-$integral_money)),//扣除积分后的金额
- 'money_in'=>$total_price-$integral_money,//扣除积分后的金额
- ];
- }
- }
- return $integral_config;
- }
- }
|