Order.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\controller\trade;
  3. use app\admin\model\User;
  4. use app\common\controller\Backend;
  5. use think\Db;
  6. use think\exception\PDOException;
  7. use think\exception\ValidateException;
  8. /**
  9. * 盲盒购买订单管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Order extends Backend
  14. {
  15. /**
  16. * Order模型对象
  17. * @var \app\admin\model\trade\Order
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\trade\Order;
  24. $this->view->assign("payMethodList", $this->model->getPayMethodList());
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. /**
  32. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  33. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  34. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35. */
  36. public function index()
  37. {
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model->alias('order')
  47. ->field('order.*')
  48. ->field('user.nickname,user.avatar')
  49. ->join('user user', 'user.id = order.user_id', 'left')
  50. ->where($where)
  51. ->where('order.status', 'neq', 'unpay')
  52. ->order($sort, $order)
  53. ->paginate($limit)
  54. ->each(function ($item) {
  55. $item->avatar = $item->avatar ? cdnurl($item->avatar, true) : letter_avatar($item->nickname);
  56. });
  57. $totalMoney = $this->model->alias('order')
  58. ->join('user user', 'user.id = order.user_id', 'left')
  59. ->where($where)
  60. ->where('order.status', 'neq', 'unpay')
  61. ->sum('rmb_amount');
  62. // 清空对应角标
  63. $filter = json_decode(input('filter'), true);
  64. if ($filter && !$list->isEmpty()) {
  65. \app\admin\model\trade\Order::where('backend_read', 0)->where('status', $list[0]->status)->update(['backend_read' => 1]);
  66. }
  67. $result = array("total" => $list->total(), "rows" => $list->items(), 'totalmoney' => $totalMoney);
  68. return json($result);
  69. }
  70. // 渲染角标数字
  71. $sidebar = [
  72. 'all' => \app\admin\model\trade\Order::where('backend_read', 0)->where('status', 'neq', 'unpay')->count(),
  73. // 'unpay' => \app\admin\model\trade\Order::where('backend_read', 0)->where('status', 'unpay')->count(),
  74. 'unused' => \app\admin\model\trade\Order::where('backend_read', 0)->where('status', 'unused')->count(),
  75. 'used' => \app\admin\model\trade\Order::where('backend_read', 0)->where('status', 'used')->count(),
  76. 'refund' => \app\admin\model\trade\Order::where('backend_read', 0)->where('status', 'refund')->count(),
  77. ];
  78. $this->assignconfig('sidebar_number', $sidebar);
  79. $this->assign('sidebar_number', $sidebar);
  80. return $this->view->fetch();
  81. }
  82. public function edit($ids = null)
  83. {
  84. $row = $this->model->get($ids);
  85. if (!$row) {
  86. $this->error(__('No Results were found'));
  87. }
  88. $adminIds = $this->getDataLimitAdminIds();
  89. if (is_array($adminIds)) {
  90. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  91. $this->error(__('You have no permission'));
  92. }
  93. }
  94. $row->userinfo = [
  95. 'nickname' => '',
  96. 'mobile' => '',
  97. 'avatar' => '/assets/img/avatar.png'
  98. ];
  99. $user = User::field('nickname,mobile,avatar')->where('id', $row->user_id)->find();
  100. if ($user) {
  101. $user->avatar = $user->avatar ? cdnurl($user->avatar, true) : letter_avatar($user->nickname);
  102. $row->userinfo = $user;
  103. }
  104. $this->view->assign("row", $row);
  105. return $this->view->fetch();
  106. }
  107. }