Orders.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\OrderInfo;
  4. use app\common\controller\Backend;
  5. use app\common\model\OrderLogistics;
  6. /**
  7. *
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Orders extends Backend
  12. {
  13. /**
  14. * Orders模型对象
  15. * @var \app\admin\model\Orders
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\Orders;
  22. $this->assign('status',$this->model::getStatus());
  23. $this->assign('pay_types',$this->model::getPayTypes());
  24. }
  25. public function import()
  26. {
  27. parent::import();
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. /**
  35. * 查看
  36. */
  37. public function index()
  38. {
  39. //当前是否为关联查询
  40. $this->relationSearch = true;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if ($this->request->isAjax()) {
  44. //如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $list = $this->model
  50. ->with(['user','logistics'])
  51. ->where($where)
  52. ->order($sort, $order)
  53. ->paginate($limit);
  54. foreach ($list as $row) {
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. #发货
  62. public function send($ids){
  63. $order=$this->model->find($ids);
  64. if($this->request->isGet()){
  65. $this->assign('row',$order);
  66. $this->assign('companys',\app\common\model\LogisticsCompany::all());
  67. return $this->fetch();
  68. }else{
  69. $data=input('row/a');
  70. $this->validate($data,[
  71. 'com_id'=>['require',],
  72. 'trans_no'=>['require'],
  73. 'remark|备注'=>['require','max:100'],
  74. ]);
  75. /*if($order->logistics){
  76. $this->error('已发货无法再次发货');
  77. }*/
  78. $order->makeSend($order->logistics,$data);
  79. $this->success();
  80. }
  81. }
  82. #详情
  83. public function detail($ids){
  84. //当前是否为关联查询
  85. $this->relationSearch = true;
  86. //设置过滤方法
  87. $this->request->filter(['strip_tags', 'trim']);
  88. if ($this->request->isAjax()) {
  89. //如果发送的来源是Selectpage,则转发到Selectpage
  90. if ($this->request->request('keyField')) {
  91. return $this->selectpage();
  92. }
  93. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  94. $list = OrderInfo::where($where)
  95. ->where('order_info.order_id',$ids)
  96. ->select();
  97. $result = array("total" => $list->count(), "rows" => $list->all());
  98. return json($result);
  99. }
  100. $this->assign('order',$this->model->find($ids));
  101. return $this->view->fetch();
  102. }
  103. #发票
  104. public function tax($ids){
  105. $order=$this->model->find($ids);
  106. if($this->request->isGet()){
  107. $this->assign('row',$order);
  108. return $this->fetch();
  109. }else{
  110. $data=input('row/a');
  111. $this->validate($data,[
  112. 'tax_link|发票'=>['require',],
  113. ]);
  114. $order['tax_link']=$data['tax_link'];
  115. $order->save();
  116. $this->success();
  117. }
  118. }
  119. #查看物流
  120. public function logistics($ids){
  121. $order=$this->model->find($ids);
  122. $timeLine=logistics()
  123. ->setLogistics($order->logistics->com)
  124. ->setPhone($order->address->mobile)
  125. ->setUserName($order->address->name)
  126. ->setNo($order->logistics->trans_no)
  127. ->query();
  128. $this->assign('timeLine',$timeLine);
  129. return $this->fetch();
  130. }
  131. }