WithdrawMoneyLog.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\api\model\user;
  4. use app\api\model\User;
  5. use app\api\service\User as UserService;
  6. use app\common\model\user\WithdrawMoneyLog as WithdrawMoneyLogModel;
  7. use Exception;
  8. use think\facade\Db;
  9. use think\facade\Log;
  10. /**
  11. * 用户余额变动明细模型
  12. * Class BalanceLog
  13. * @package app\api\model\user
  14. */
  15. class WithdrawMoneyLog extends WithdrawMoneyLogModel
  16. {
  17. /**
  18. * 隐藏字段
  19. * @var array
  20. */
  21. protected $hidden = [
  22. 'store_id',
  23. ];
  24. /**
  25. * 获取账单明细列表
  26. * @return \think\Paginator
  27. * @throws \app\common\exception\BaseException
  28. * @throws \think\db\exception\DbException
  29. */
  30. public function getList()
  31. {
  32. // 当前用户ID
  33. $userId = UserService::getCurrentLoginUserId();
  34. // 获取列表数据
  35. return $this->where('user_id', '=', $userId)
  36. ->order(['create_time' => 'desc'])
  37. ->paginate(15);
  38. }
  39. /**
  40. * 记录分佣明细
  41. * @param $userId
  42. * @param $scene
  43. * @param $money
  44. * @param string $describe
  45. * @param string $remark
  46. * @return bool
  47. * @throws Exception
  48. */
  49. /* public static function addNewLog($userId,$scene,$money,$describe='',$remark=''){
  50. $log = new self();
  51. $user = User::find($userId);
  52. try {
  53. $log->save([
  54. 'user_id' => $userId,
  55. 'scene' => $scene,
  56. 'money' => $money,
  57. 'describe' => $describe,
  58. 'remark' => $remark,
  59. ]);
  60. //提现余额也要累加计算
  61. $user->can_withdraw_money = Db::raw('can_withdraw_money+'.$money);
  62. //可提现金额
  63. $user->ktxyj_amount = Db::raw('ktxyj_amount+'.$money);
  64. $user->save();
  65. }catch (Exception $e){
  66. Log::error('order_id::'.$remark.',desc::'.$describe.','.$e->getMessage());
  67. throw $e;
  68. }
  69. $user = User::find($userId);
  70. return $user->can_withdraw_money;
  71. }*/
  72. public static function sumGiveOutOrder(){
  73. $userId = UserService::getCurrentLoginUserId();
  74. return self::where('user_id',$userId)->where('scene',50)->sum('money');
  75. }
  76. /**
  77. * 批量加入余额变更
  78. * @param $lists
  79. * @return bool
  80. * @throws Exception
  81. */
  82. public static function addNewLogBatch($lists){
  83. $log = new self();
  84. try {
  85. $log->saveAll($lists);
  86. }catch (Exception $e){
  87. throw $e;
  88. //return false;
  89. }
  90. return true;
  91. }
  92. }