Fund.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 采购基金
  7. */
  8. namespace app\allwin\model;
  9. use think\Model;
  10. use util\Util;
  11. class Fund extends Model
  12. {
  13. protected $pk = 'id';
  14. protected $table = 'ai_allwin_fund';
  15. /**
  16. * 基金账户充值
  17. * @param integer $miniapp_id
  18. * @param integer $money(元)
  19. * @return void
  20. */
  21. public function recharge(int $miniapp_id,float $money){
  22. $info = self::where(['member_miniapp_id' => $miniapp_id])->find();
  23. if(empty($info)){
  24. $data['member_miniapp_id'] = $miniapp_id;
  25. $data['balance'] = floatval($money);
  26. $data['subsidize'] = 0;
  27. $data['subsidize_num'] = 0;
  28. return self::insert($data);
  29. }else{
  30. $info->balance = floatval($info->balance+$money);
  31. return $info->save();
  32. }
  33. }
  34. /**
  35. * 账务补贴
  36. * @param integer $miniapp_id
  37. * @param integer $money(元)
  38. * @return void
  39. */
  40. public function subsidy(int $miniapp_id,float $money){
  41. $rel = self::where(['member_miniapp_id' => $miniapp_id])->find();
  42. if(empty($rel)){
  43. return;
  44. }else{
  45. if($rel->balance <= 0){
  46. return;
  47. }
  48. $subsidize = ($rel->balance-$money) < 0 ? $rel->balance : $money;
  49. $rel->balance = ['dec',$subsidize];
  50. $rel->subsidize = ['inc',$subsidize];
  51. $rel->subsidize_num = ['inc',1];
  52. $rel->save();
  53. return $subsidize;
  54. }
  55. }
  56. }