RefundOrder.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace app\controller\merchant\store\order;
  3. use app\common\repositories\store\ExcelRepository;
  4. use app\common\repositories\store\order\MerchantReconciliationRepository;
  5. use app\common\repositories\store\order\StoreRefundStatusRepository;
  6. use think\App;
  7. use ln\basic\BaseController;
  8. use app\common\repositories\store\order\StoreRefundOrderRepository as repository;
  9. class RefundOrder extends BaseController
  10. {
  11. /**
  12. * @var repository
  13. */
  14. protected $repository;
  15. /**
  16. * Order constructor.
  17. * @param App $app
  18. * @param repository $repository
  19. */
  20. public function __construct(App $app, repository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. }
  25. /**
  26. * @return mixed
  27. * @author Qinii
  28. * @day 2020-06-12
  29. */
  30. public function lst()
  31. {
  32. list($page,$limit) = $this->getPage();
  33. $where = $this->request->params(['refund_order_sn','status','refund_type','date','order_sn','id','delivery_id']);
  34. $where['mer_id'] = $this->request->merId();
  35. return app('json')->success($this->repository->getList($where,$page,$limit));
  36. }
  37. /**
  38. * @param $id
  39. * @return mixed
  40. * @author Qinii
  41. * @day 2020-06-12
  42. */
  43. public function detail($id)
  44. {
  45. if(!$this->repository->getExistsById($this->request->merId(),$id))
  46. return app('json')->fail('数据不存在');
  47. return app('json')->success($this->repository->getOne($id));
  48. }
  49. /**
  50. * @param $id
  51. * @return mixed
  52. * @author Qinii
  53. * @day 2020-06-12
  54. */
  55. public function switchStatus($id)
  56. {
  57. if(!$this->repository->getStatusExists($this->request->merId(),$id))
  58. return app('json')->fail('信息或状态错误');
  59. $status = ($this->request->param('status') == 1) ? 1 : -1;
  60. if($status == 1){
  61. $data = $this->request->params(['mer_delivery_user','mer_delivery_address','phone']);
  62. $data['status'] = $status;
  63. $this->repository->agree($id,$data,$this->request->adminId());
  64. }else{
  65. $fail_message = $this->request->param('fail_message','');
  66. if($status == -1 && empty($fail_message))
  67. return app('json')->fail('未通过必须填写');
  68. $data['status'] = $status;
  69. $data['fail_message'] = $fail_message;
  70. $this->repository->refuse($id,$data);
  71. }
  72. return app('json')->success('审核成功');
  73. }
  74. /**
  75. * TODO 收货后确定退款
  76. * @param $id
  77. * @return mixed
  78. * @author Qinii
  79. * @day 2020-06-12
  80. */
  81. public function refundPrice($id)
  82. {
  83. if(!$this->repository->getRefundPriceExists($this->request->merId(),$id))
  84. return app('json')->fail('信息或状态错误');
  85. $this->repository->adminRefund($id,$this->request->adminId());
  86. return app('json')->success('退款成功');
  87. }
  88. /**
  89. * TODO
  90. * @param $id
  91. * @return mixed
  92. * @author Qinii
  93. * @day 2020-06-12
  94. */
  95. public function switchStatusForm($id)
  96. {
  97. if(!$this->repository->getStatusExists($this->request->merId(),$id))
  98. return app('json')->fail('信息或状态错误');
  99. return app('json')->success(formToData($this->repository->statusForm($id)));
  100. }
  101. /**
  102. * TODO
  103. * @param $id
  104. * @return mixed
  105. * @author Qinii
  106. * @day 2020-06-18
  107. */
  108. public function delete($id)
  109. {
  110. if(!$this->repository->getUserDelExists($this->request->merId(),$id))
  111. return app('json')->fail('信息或状态错误');
  112. $this->repository->update($id,['is_system_del' => 1]);
  113. return app('json')->success('删除成功');
  114. }
  115. /**
  116. * TODO
  117. * @param $id
  118. * @return mixed
  119. * @author Qinii
  120. * @day 2020-06-18
  121. */
  122. public function markForm($id)
  123. {
  124. if(!$this->repository->getExistsById($this->request->merId(),$id))
  125. return app('json')->fail('数据不存在');
  126. return app('json')->success(formToData($this->repository->markForm($id)));
  127. }
  128. /**
  129. * TODO
  130. * @param $id
  131. * @return mixed
  132. * @author Qinii
  133. * @day 2020-06-18
  134. */
  135. public function mark($id)
  136. {
  137. if(!$this->repository->getExistsById($this->request->merId(),$id))
  138. return app('json')->fail('数据不存在');
  139. $this->repository->update($id,['mer_mark' => $this->request->param('mer_mark','')]);
  140. return app('json')->success('备注成功');
  141. }
  142. public function log($id)
  143. {
  144. list($page,$limit) = $this->getPage();
  145. $make = app()->make(StoreRefundStatusRepository::class);
  146. return app('json')->success($make->search($id,$page,$limit));
  147. }
  148. public function reList($id)
  149. {
  150. [$page,$limit] = $this->getPage();
  151. $make = app()->make(MerchantReconciliationRepository::class);
  152. if(!$make->getWhereCount(['mer_id' => $this->request->merId(),'reconciliation_id' => $id]))
  153. return app('json')->fail('数据不存在');
  154. $where = ['reconciliation_id' => $id,'type' => 1];
  155. return app('json')->success($this->repository->reconList($where,$page,$limit));
  156. }
  157. /**
  158. * TODO 快递查询
  159. * @param $id
  160. * @return mixed
  161. * @author Qinii
  162. * @day 2020-06-25
  163. */
  164. public function express($id)
  165. {
  166. // if(!$this->repository->getWhereCount(['refund_order_id' => $id,'status' =>2]))
  167. // return app('json')->fail('订单信息或状态错误');
  168. return app('json')->success($this->repository->express($id));
  169. }
  170. public function createExcel()
  171. {
  172. $where = $this->request->params(['refund_order_sn','status','refund_type','date','order_sn','id']);
  173. $where['mer_id'] = $this->request->merId();
  174. app()->make(ExcelRepository::class)->create($where,$this->request->adminId(),'refundOrder',$this->request->merId());
  175. return app('json')->success('开始生成导出文件');
  176. }
  177. }