RefundOrder.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. // 取消 订单所发放的福利
  109. $this->repository->cancelOrderBonus($id);
  110. }else{
  111. $fail_message = $this->request->param('fail_message','');
  112. if($status == -1 && empty($fail_message)){
  113. return app('json')->fail('未通过必须填写');
  114. }
  115. if($fail_message==''){
  116. return app('json')->fail('未通过必须填写');
  117. }
  118. $data['status'] = $status;
  119. $data['fail_message'] = $fail_message;
  120. $this->repository->refuse($id,$data);
  121. $this->repository->set_consult(2,$id);//协商记录
  122. }
  123. return app('json')->success('审核成功');
  124. }
  125. public function switchStatusjhm($id)
  126. {
  127. $this->repository->agreejhm($id);
  128. return app('json')->success('审核成功');
  129. }
  130. public function switchStatusnf($id)
  131. {
  132. $res = $this->repository->agreenf($id);
  133. return app('json')->success($res);
  134. }
  135. public function switchStatusqds($id)
  136. {
  137. $res = $this->repository->agreeqds($id);
  138. return app('json')->success($res);
  139. }
  140. /**
  141. * TODO 收货后确定退款
  142. * @param $id
  143. * @return mixed
  144. * @author Qinii
  145. * @day 2020-06-12
  146. */
  147. public function refundPrice($id)
  148. {
  149. if(!$this->repository->getRefundPriceExists($this->request->merId(),$id))
  150. return app('json')->fail('信息或状态错误');
  151. if($this->request->param('status') == 2){
  152. $part_refund_message = $this->request->param('part_refund_message','');
  153. $refund_price =(float) $this->request->param('part_refund_price',0);
  154. if($refund_price<0.01){
  155. return app('json')->fail('退款金额不能小于0.01');
  156. }
  157. $refund_order=$this->repository->get($id);
  158. $pay_price=Db::name('store_order')->where('order_id',$refund_order['order_id'])->value('pay_price');
  159. if($refund_price > $pay_price){
  160. return app('json')->fail('退款金额不能大于用户支付金额');
  161. }
  162. if($part_refund_message==''){
  163. return app('json')->fail('请填写商家备注');
  164. }
  165. $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')]);
  166. }else if($this->request->param('status') == -1){
  167. $fail_message = $this->request->param('fail_message','');
  168. if(empty($fail_message))
  169. return app('json')->fail('请输入拒绝原因');
  170. $data['status'] = -1;
  171. $data['fail_message'] = $fail_message;
  172. $this->repository->refuse($id,$data);
  173. $this->repository->set_consult(7,$id);//协商记录
  174. return app('json')->success('拒绝成功');
  175. }
  176. $this->repository->set_consult(5,$id);//协商记录
  177. $this->repository->adminRefund($id,$this->request->adminId());
  178. return app('json')->success('退款成功');
  179. }
  180. /**
  181. * TODO
  182. * @param $id
  183. * @return mixed
  184. * @author Qinii
  185. * @day 2020-06-12
  186. */
  187. public function switchStatusForm($id)
  188. {
  189. if(!$this->repository->getStatusExists($this->request->merId(),$id))
  190. return app('json')->fail('信息或状态错误');
  191. // $douduo = $this -> repository -> douduofund($id,false);
  192. // if($douduo['code'] < 0){
  193. // return app('json')->fail($douduo['message']);
  194. // }
  195. // if($douduo['code'] == 2){
  196. // return app('json')->success($douduo['message']);
  197. // }
  198. return app('json')->success(formToData($this->repository->statusForm($id)));
  199. }
  200. /**
  201. * TODO
  202. * @param $id
  203. * @return mixed
  204. * @author Qinii
  205. * @day 2020-06-18
  206. */
  207. public function delete($id)
  208. {
  209. if(!$this->repository->getUserDelExists($this->request->merId(),$id))
  210. return app('json')->fail('信息或状态错误');
  211. $this->repository->update($id,['is_system_del' => 1]);
  212. return app('json')->success('删除成功');
  213. }
  214. /**
  215. * TODO
  216. * @param $id
  217. * @return mixed
  218. * @author Qinii
  219. * @day 2020-06-18
  220. */
  221. public function markForm($id)
  222. {
  223. if(!$this->repository->getExistsById($this->request->merId(),$id))
  224. return app('json')->fail('数据不存在');
  225. return app('json')->success(formToData($this->repository->markForm($id)));
  226. }
  227. /**
  228. * TODO
  229. * @param $id
  230. * @return mixed
  231. * @author Qinii
  232. * @day 2020-06-18
  233. */
  234. public function mark($id)
  235. {
  236. if(!$this->repository->getExistsById($this->request->merId(),$id))
  237. return app('json')->fail('数据不存在');
  238. $this->repository->update($id,['mer_mark' => $this->request->param('mer_mark','')]);
  239. return app('json')->success('备注成功');
  240. }
  241. public function log($id)
  242. {
  243. list($page,$limit) = $this->getPage();
  244. $make = app()->make(StoreRefundStatusRepository::class);
  245. return app('json')->success($make->search($id,$page,$limit));
  246. }
  247. public function reList($id)
  248. {
  249. [$page,$limit] = $this->getPage();
  250. $make = app()->make(MerchantReconciliationRepository::class);
  251. if(!$make->getWhereCount(['mer_id' => $this->request->merId(),'reconciliation_id' => $id]))
  252. return app('json')->fail('数据不存在');
  253. $where = ['reconciliation_id' => $id,'type' => 1];
  254. return app('json')->success($this->repository->reconList($where,$page,$limit));
  255. }
  256. /**
  257. * TODO 快递查询
  258. * @param $id
  259. * @return mixed
  260. * @author Qinii
  261. * @day 2020-06-25
  262. */
  263. public function express($id)
  264. {
  265. // if(!$this->repository->getWhereCount(['refund_order_id' => $id,'status' =>2]))
  266. // return app('json')->fail('订单信息或状态错误');
  267. return app('json')->success($this->repository->express($id));
  268. }
  269. }