Admin.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\admin\model;
  3. use app\common\model\MoneyLog;
  4. use think\Model;
  5. use think\Session;
  6. class Admin extends Model
  7. {
  8. // 开启自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $hidden = [
  14. 'password',
  15. 'salt'
  16. ];
  17. public static function init()
  18. {
  19. self::beforeWrite(function ($row) {
  20. $changed = $row->getChangedData();
  21. //如果修改了用户或或密码则需要重新登录
  22. if (isset($changed['username']) || isset($changed['password']) || isset($changed['salt'])) {
  23. $row->token = '';
  24. }
  25. });
  26. }
  27. public static function money($money, $user_id, $memo)
  28. {
  29. $user = self::get($user_id);
  30. if ($user && $money != 0) {
  31. $before = $user->money;
  32. $after = function_exists('bcadd') ? bcadd($user->money, $money, 7) : $user->money + $money;
  33. MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => $memo]);
  34. }
  35. }
  36. }