XzLogModel.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. use think\Model;
  5. class XzLogModel extends Model
  6. {
  7. protected $name = 'xz_log';
  8. /**
  9. * 关联user
  10. * @return \think\model\relation\BelongsTo
  11. */
  12. public function user ()
  13. {
  14. return $this->belongsTo('app\common\model\UserModel', 'uid', 'id');
  15. }
  16. /**
  17. * 记录
  18. * @param $param
  19. * @return array
  20. * @throws \think\db\exception\DbException
  21. */
  22. public function getLog ($param)
  23. {
  24. $type_conf = config('type.xz');
  25. $list = self::where('uid', $param->uid)
  26. ->withAttr('type', function ($value, $data) use ($type_conf) {
  27. $typeStr = isset($type_conf[$value]) ? $type_conf[$value] : '未知类型';
  28. if (in_array($value , [5,6])){
  29. $uid_user = Db::name('user')->where('id', $data['uid2'])->find();
  30. if ($uid_user){
  31. $typeStr = $typeStr."(".$uid_user['mobile'].")";
  32. }
  33. }
  34. return $typeStr;
  35. })
  36. ->order('create_at', 'desc')
  37. ->paginate($param->data['limit'])
  38. ->toArray();
  39. // $history = self::where([
  40. // ['uid', '=', $param->uid],
  41. // ['state', '=', 1]
  42. // ])->sum('money');
  43. return $list['data'];
  44. return compact('list', 'history');
  45. }
  46. }