UserIntegralModel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\common\model;
  3. class UserIntegralModel extends BaseModel
  4. {
  5. protected $table='user_integral';
  6. /**
  7. * 获取用户下单时的积分抵扣
  8. * @param $user_id
  9. * @param $total_price 订单总金额
  10. * @param $total_deduction_integral 抵扣积分
  11. * @return array
  12. */
  13. public function checkDeductionIntegral($user_id,$total_price,$total_deduction_integral)
  14. {
  15. $integral_config=[
  16. 'integral'=>0,
  17. 'status'=>0,
  18. 'money'=>0,//扣除积分后的金额
  19. 'money_in'=>0,//扣除积分后的金额
  20. ];
  21. if($total_deduction_integral>0){
  22. $integral = $this->where(['user_id'=>$user_id,'status'=>1])->sum('integral');
  23. if($integral>$total_deduction_integral){
  24. $integral_money = $total_deduction_integral;
  25. $integral_config=[
  26. 'integral'=>$total_deduction_integral,
  27. 'status'=>1,
  28. 'money'=>getMoneyFormat(($total_price-$integral_money)),//扣除积分后的金额
  29. 'money_in'=>$total_price-$integral_money,//扣除积分后的金额
  30. ];
  31. }
  32. }
  33. return $integral_config;
  34. }
  35. }