UserOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\admin\model\UserOrder as UO;
  5. use app\common\model\SenderOrder;
  6. use think\Db;
  7. /**
  8. * 订单管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class UserOrder extends Backend
  13. {
  14. protected $relationSearch=true;
  15. protected $noNeedLogin=['status'];
  16. /**
  17. * UserOrder模型对象
  18. * @var UO
  19. */
  20. protected $model = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new UO;
  25. }
  26. public function import()
  27. {
  28. parent::import();
  29. }
  30. /**
  31. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  32. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  33. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  34. */
  35. /**
  36. * 查看
  37. */
  38. public function index()
  39. {
  40. //当前是否为关联查询
  41. $this->relationSearch = true;
  42. //设置过滤方法
  43. $this->request->filter(['strip_tags', 'trim']);
  44. if ($this->request->isAjax()) {
  45. //如果发送的来源是Selectpage,则转发到Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  50. $list = $this->model
  51. ->with(['user'])
  52. ->where($where)
  53. ->order($sort, $order)
  54. ->paginate($limit);
  55. foreach ($list as $row) {
  56. $row->visible(['id','from_city','to_city','images','created_at','real_amount','coupon_amount','status']);
  57. $row->visible(['user']);
  58. $row->getRelation('user')->visible(['nickname']);
  59. }
  60. $result = array("total" => $list->total(), "rows" => $list->items());
  61. return json($result);
  62. }
  63. return $this->view->fetch();
  64. }
  65. public function status(){
  66. return \app\common\model\UserOrder::$statusList;
  67. }
  68. public function edit($ids = null)
  69. {
  70. $this->assign('freight',\app\common\model\UserOrder::$freights);
  71. $this->assign('status',\app\common\model\UserOrder::$statusList);
  72. $this->assign('refund',\app\common\model\UserOrder::$refundStatus);
  73. $senders=SenderOrder::sender($ids)->with('user')->select();
  74. $senders=array_column($senders->toArray(),null,'type');
  75. $this->assign('senders',$senders);
  76. return parent::edit($ids);
  77. }
  78. public function send_detail($ids){
  79. $order=$this->model->findOrFail($ids);
  80. $this->assign('order',$order);
  81. return view();
  82. }
  83. public function remark($ids){
  84. $order=$this->model->find($ids);
  85. if (!$order){
  86. $this->error('信息不存在');
  87. }
  88. $data=input();
  89. $this->validate($data,[
  90. 'remark'=>['require','max:100'],
  91. ]);
  92. $order->log()->save([
  93. 'txt'=>$data['remark'],
  94. ]);
  95. $this->success();
  96. }
  97. public function deal_settle($ids){
  98. $data=input();
  99. $this->validate($data,[
  100. 'status'=>['require','in:1,2'],
  101. ]);
  102. Db::startTrans();
  103. $order= $this->model->settle()->lock(true)->find($ids);
  104. if (!$order){
  105. $this->error('信息不存在');
  106. }
  107. $order->dealSettle($data);
  108. Db::commit();
  109. $this->success();
  110. }
  111. public function delete($ids){
  112. $order= \app\common\model\UserOrder::findOrFail($ids);
  113. $order->remove();
  114. $this->success();
  115. }
  116. }