WalletLog.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\admin\controller\shopro\user;
  3. use app\admin\controller\shopro\Common;
  4. use app\admin\model\shopro\user\WalletLog as WalletLogModel;
  5. use addons\shopro\library\Operator;
  6. class WalletLog extends Common
  7. {
  8. protected $model = null;
  9. public function _initialize()
  10. {
  11. parent::_initialize();
  12. $this->model = new WalletLogModel;
  13. }
  14. /**
  15. * 余额记录
  16. */
  17. public function money($id)
  18. {
  19. $list_rows = $this->request->param('list_rows', 10);
  20. $walletLogs = WalletLogModel::where('user_id', $id)->money()->order('id', 'desc')->paginate($list_rows);
  21. // 多态关联 oper
  22. $morphs = [
  23. 'user' => \app\admin\model\shopro\user\User::class,
  24. 'admin' => \app\admin\model\Admin::class,
  25. 'system' => \app\admin\model\Admin::class,
  26. ];
  27. $walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']);
  28. $walletLogs = $walletLogs->toArray();
  29. // 解析操作人信息
  30. foreach ($walletLogs['data'] as &$log) {
  31. $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
  32. }
  33. $this->success('', null, $walletLogs);
  34. }
  35. /**
  36. * 积分记录
  37. */
  38. public function score($id)
  39. {
  40. $list_rows = $this->request->param('list_rows', 10);
  41. $walletLogs = WalletLogModel::where('user_id', $id)->score()->order('id', 'desc')->paginate($list_rows);
  42. // 多态关联 oper
  43. $morphs = [
  44. 'user' => \app\admin\model\shopro\user\User::class,
  45. 'admin' => \app\admin\model\Admin::class,
  46. 'system' => \app\admin\model\Admin::class,
  47. ];
  48. $walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']);
  49. $walletLogs = $walletLogs->toArray();
  50. // 解析操作人信息
  51. foreach ($walletLogs['data'] as &$log) {
  52. $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
  53. }
  54. $this->success('', null, $walletLogs);
  55. }
  56. /**
  57. * 佣金记录
  58. */
  59. public function commission($id)
  60. {
  61. $list_rows = $this->request->param('list_rows', 10);
  62. $walletLogs = WalletLogModel::where('user_id', $id)->commission()->order('id', 'desc')->paginate($list_rows);
  63. // 多态关联 oper
  64. $morphs = [
  65. 'user' => \app\admin\model\shopro\user\User::class,
  66. 'admin' => \app\admin\model\Admin::class,
  67. 'system' => \app\admin\model\Admin::class,
  68. ];
  69. $walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']);
  70. $walletLogs = $walletLogs->toArray();
  71. // 解析操作人信息
  72. foreach ($walletLogs['data'] as &$log) {
  73. $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
  74. }
  75. $this->success('', null, $walletLogs);
  76. }
  77. }