BalanceLog.php 2.0 KB

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