BalanceLog.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\user;
  10. use app\common\model\BaseModel;
  11. use app\common\enum\user\balanceLog\Scene as SceneEnum;
  12. /**
  13. * 用户余额变动明细模型
  14. * Class BalanceLog
  15. * @package app\common\model\user
  16. */
  17. class BalanceLog extends BaseModel
  18. {
  19. protected $name = 'user_balance_log';
  20. protected $updateTime = false;
  21. /**
  22. * 获取当前模型属性
  23. * @return array
  24. */
  25. public static function getAttributes()
  26. {
  27. return [
  28. // 充值方式
  29. 'scene' => SceneEnum::data(),
  30. ];
  31. }
  32. /**
  33. * 关联会员记录表
  34. * @return \think\model\relation\BelongsTo
  35. */
  36. public function user()
  37. {
  38. $module = self::getCalledModule() ?: 'common';
  39. return $this->belongsTo("app\\{$module}\\model\\User");
  40. }
  41. /**
  42. * 余额变动场景
  43. * @param $value
  44. * @return array
  45. */
  46. public function getSceneAttr($value)
  47. {
  48. return ['text' => SceneEnum::data()[$value]['name'], 'value' => $value];
  49. }
  50. /**
  51. * 新增记录
  52. * @param $scene
  53. * @param $data
  54. * @param $describeParam
  55. */
  56. public static function add($scene, $data, $describeParam)
  57. {
  58. $model = new static;
  59. $model->save(array_merge([
  60. 'scene' => $scene,
  61. 'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
  62. 'wxapp_id' => $model::$wxapp_id
  63. ], $data));
  64. }
  65. }