RefundOrder.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-12
  7. *
  8. *
  9. */
  10. namespace app\controller\merchant\store\order;
  11. use app\common\repositories\store\order\MerchantReconciliationRepository;
  12. use app\common\repositories\store\order\StoreRefundStatusRepository;
  13. use think\App;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\store\order\StoreRefundOrderRepository as repository;
  16. use think\facade\Db;
  17. class RefundOrder extends BaseController
  18. {
  19. /**
  20. * @var repository
  21. */
  22. protected $repository;
  23. /**
  24. * Order constructor.
  25. * @param App $app
  26. * @param repository $repository
  27. */
  28. public function __construct(App $app, repository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * @return mixed
  35. * @author Qinii
  36. * @day 2020-06-12
  37. */
  38. public function lst()
  39. {
  40. list($page,$limit) = $this->getPage();
  41. $where = $this->request->params(['refund_order_sn','status','refund_type','date','order_sn']);
  42. $where['mer_id'] = $this->request->merId();
  43. return app('json')->success($this->repository->getList($where,$page,$limit));
  44. }
  45. /**
  46. * @param $id
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-06-12
  50. */
  51. public function detail($id)
  52. {
  53. if(!$this->repository->getExistsById($this->request->merId(),$id))
  54. return app('json')->fail('数据不存在');
  55. $data=$this->repository->getOne($id);
  56. return app('json')->success($data);
  57. }
  58. /**
  59. * @param $id
  60. * @return mixed
  61. * @author Qinii
  62. * @day 2020-06-12
  63. */
  64. public function switchStatus($id)
  65. {
  66. if(!$this->repository->getStatusExists($this->request->merId(),$id))
  67. return app('json')->fail('信息或状态错误');
  68. $status=-1;
  69. if($this->request->param('status') == 1){
  70. $status=1;
  71. }else if($this->request->param('status') == 2){
  72. $status=2;
  73. }
  74. // $status = ($this->request->param('status') == 1) ? 1 : -1;
  75. if($status == 1 || $status == 2){
  76. $refund_order=$this->repository->get($id);
  77. if($status==2){
  78. $part_refund_message = $this->request->param('part_refund_message','');
  79. $refund_price =(float) $this->request->param('part_refund_price',0);
  80. if($refund_price<0.01){
  81. return app('json')->fail('退款金额不能小于0.01');
  82. }
  83. $pay_price=Db::name('store_order')->where('order_id',$refund_order['order_id'])->value('pay_price');
  84. if($refund_order && $refund_price > $pay_price){
  85. return app('json')->fail('退款金额不能大于用户支付金额');
  86. }
  87. if($part_refund_message==''){
  88. return app('json')->fail('请填写商家备注');
  89. }
  90. $this->repository->update($id,['refund_type'=>1,'refund_price'=>$refund_price,'part_refund_price'=>$refund_price,'part_refund_message' => $part_refund_message,'part_refund_time'=>date('Y-m-d H:i:s')]);
  91. }
  92. $douduo = $this -> repository -> douduofund($id,true);
  93. if($douduo['code'] < 0){
  94. return app('json')->fail($douduo['message']);
  95. }
  96. if($douduo['code'] == 2){
  97. return app('json')->success($douduo['message']);
  98. }
  99. // $data = $this->request->params(['mer_delivery_user','mer_delivery_address','phone']);
  100. $data['mer_delivery_user']=$this->request->param('mer_refund_user','');
  101. $data['mer_delivery_address']=$this->request->param('mer_refund_address','');
  102. $data['phone']=$this->request->param('set_phone','');
  103. if($refund_order['refund_type']==2 && $status == 1 && ($data['mer_delivery_user']=='' || $data['mer_delivery_address']=='' || $data['phone']=='')){
  104. return app('json')->fail('请输入收货人信息');
  105. }
  106. $data['status'] = $status;
  107. $this->repository->agree($id,$data,$this->request->adminId(),1);
  108. }else{
  109. $fail_message = $this->request->param('fail_message','');
  110. if($status == -1 && empty($fail_message)){
  111. return app('json')->fail('未通过必须填写');
  112. }
  113. if($fail_message==''){
  114. return app('json')->fail('未通过必须填写');
  115. }
  116. $data['status'] = $status;
  117. $data['fail_message'] = $fail_message;
  118. $this->repository->refuse($id,$data);
  119. $this->repository->set_consult(2,$id);//协商记录
  120. }
  121. return app('json')->success('审核成功');
  122. }
  123. public function switchStatusjhm($id)
  124. {
  125. $this->repository->agreejhm($id);
  126. return app('json')->success('审核成功');
  127. }
  128. public function switchStatusnf($id)
  129. {
  130. $res = $this->repository->agreenf($id);
  131. return app('json')->success($res);
  132. }
  133. public function switchStatusqds($id)
  134. {
  135. $res = $this->repository->agreeqds($id);
  136. return app('json')->success($res);
  137. }
  138. /**
  139. * TODO 收货后确定退款
  140. * @param $id
  141. * @return mixed
  142. * @author Qinii
  143. * @day 2020-06-12
  144. */
  145. public function refundPrice($id)
  146. {
  147. if(!$this->repository->getRefundPriceExists($this->request->merId(),$id))
  148. return app('json')->fail('信息或状态错误');
  149. if($this->request->param('status') == 2){
  150. $part_refund_message = $this->request->param('part_refund_message','');
  151. $refund_price =(float) $this->request->param('part_refund_price',0);
  152. if($refund_price<0.01){
  153. return app('json')->fail('退款金额不能小于0.01');
  154. }
  155. $refund_order=$this->repository->get($id);
  156. $pay_price=Db::name('store_order')->where('order_id',$refund_order['order_id'])->value('pay_price');
  157. if($refund_price > $pay_price){
  158. return app('json')->fail('退款金额不能大于用户支付金额');
  159. }
  160. if($part_refund_message==''){
  161. return app('json')->fail('请填写商家备注');
  162. }
  163. $this->repository->update($id,['refund_price'=>$refund_price,'part_refund_price'=>$refund_price,'part_refund_message' => $part_refund_message,'part_refund_time'=>date('Y-m-d H:i:s')]);
  164. }else if($this->request->param('status') == -1){
  165. $fail_message = $this->request->param('fail_message','');
  166. if(empty($fail_message))
  167. return app('json')->fail('请输入拒绝原因');
  168. $data['status'] = -1;
  169. $data['fail_message'] = $fail_message;
  170. $this->repository->refuse($id,$data);
  171. $this->repository->set_consult(7,$id);//协商记录
  172. return app('json')->success('拒绝成功');
  173. }
  174. $this->repository->set_consult(5,$id);//协商记录
  175. $this->repository->adminRefund($id,$this->request->adminId());
  176. return app('json')->success('退款成功');
  177. }
  178. /**
  179. * TODO
  180. * @param $id
  181. * @return mixed
  182. * @author Qinii
  183. * @day 2020-06-12
  184. */
  185. public function switchStatusForm($id)
  186. {
  187. if(!$this->repository->getStatusExists($this->request->merId(),$id))
  188. return app('json')->fail('信息或状态错误');
  189. // $douduo = $this -> repository -> douduofund($id,false);
  190. // if($douduo['code'] < 0){
  191. // return app('json')->fail($douduo['message']);
  192. // }
  193. // if($douduo['code'] == 2){
  194. // return app('json')->success($douduo['message']);
  195. // }
  196. return app('json')->success(formToData($this->repository->statusForm($id)));
  197. }
  198. /**
  199. * TODO
  200. * @param $id
  201. * @return mixed
  202. * @author Qinii
  203. * @day 2020-06-18
  204. */
  205. public function delete($id)
  206. {
  207. if(!$this->repository->getUserDelExists($this->request->merId(),$id))
  208. return app('json')->fail('信息或状态错误');
  209. $this->repository->update($id,['is_system_del' => 1]);
  210. return app('json')->success('删除成功');
  211. }
  212. /**
  213. * TODO
  214. * @param $id
  215. * @return mixed
  216. * @author Qinii
  217. * @day 2020-06-18
  218. */
  219. public function markForm($id)
  220. {
  221. if(!$this->repository->getExistsById($this->request->merId(),$id))
  222. return app('json')->fail('数据不存在');
  223. return app('json')->success(formToData($this->repository->markForm($id)));
  224. }
  225. /**
  226. * TODO
  227. * @param $id
  228. * @return mixed
  229. * @author Qinii
  230. * @day 2020-06-18
  231. */
  232. public function mark($id)
  233. {
  234. if(!$this->repository->getExistsById($this->request->merId(),$id))
  235. return app('json')->fail('数据不存在');
  236. $this->repository->update($id,['mer_mark' => $this->request->param('mer_mark','')]);
  237. return app('json')->success('备注成功');
  238. }
  239. public function log($id)
  240. {
  241. list($page,$limit) = $this->getPage();
  242. $make = app()->make(StoreRefundStatusRepository::class);
  243. return app('json')->success($make->search($id,$page,$limit));
  244. }
  245. public function reList($id)
  246. {
  247. [$page,$limit] = $this->getPage();
  248. $make = app()->make(MerchantReconciliationRepository::class);
  249. if(!$make->getWhereCount(['mer_id' => $this->request->merId(),'reconciliation_id' => $id]))
  250. return app('json')->fail('数据不存在');
  251. $where = ['reconciliation_id' => $id,'type' => 1];
  252. return app('json')->success($this->repository->reconList($where,$page,$limit));
  253. }
  254. /**
  255. * TODO 快递查询
  256. * @param $id
  257. * @return mixed
  258. * @author Qinii
  259. * @day 2020-06-25
  260. */
  261. public function express($id)
  262. {
  263. // if(!$this->repository->getWhereCount(['refund_order_id' => $id,'status' =>2]))
  264. // return app('json')->fail('订单信息或状态错误');
  265. return app('json')->success($this->repository->express($id));
  266. }
  267. }