RefundOrder.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-15
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\order;
  11. use app\common\repositories\user\UserRepository;
  12. use crmeb\basic\BaseController;
  13. use app\common\repositories\store\order\MerchantReconciliationorderRepository;
  14. use app\common\repositories\store\order\MerchantReconciliationRepository;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. use app\common\repositories\store\order\StoreRefundOrderRepository as repository;
  17. use think\App;
  18. use think\facade\Db;
  19. class RefundOrder extends BaseController
  20. {
  21. protected $repository;
  22. public function __construct(App $app,repository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. public function lst($id)
  28. {
  29. [$page,$limit] = $this->getPage();
  30. // $where['reconciliation_type'] = $this->request->param('status',1);
  31. $where['status'] =$this->request->param('status','');
  32. $where['date'] = $this->request->param('date');
  33. $where['mer_id'] = $id;
  34. $where['status'] = 3;
  35. return app('json')->success($this->repository->getAdminList($where,$page,$limit));
  36. }
  37. public function markForm($id)
  38. {
  39. if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  40. return app('json')->fail('数据不存在');
  41. return app('json')->success(formToData($this->repository->adminMarkForm($id)));
  42. }
  43. public function mark($id)
  44. {
  45. if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  46. return app('json')->fail('数据不存在');
  47. $data = $this->request->params(['admin_mark']);
  48. $this->repository->update($id,$data);
  49. return app('json')->success('备注成功');
  50. }
  51. public function getAllList()
  52. {
  53. [$page,$limit] = $this->getPage();
  54. $where = $this->request->params(['refund_order_sn','status','refund_type','date','mer_id','order_sn']);
  55. return app('json')->success($this->repository->getAllList($where, $page, $limit));
  56. }
  57. public function detail($id)
  58. {
  59. $data=$this->repository->getOne($id);
  60. return app('json')->success($data);
  61. }
  62. /**
  63. * @param $id
  64. * @return mixed
  65. * @author Qinii
  66. * @day 2020-06-12
  67. */
  68. public function switchStatus($id)
  69. {
  70. $status=-1;
  71. if($this->request->param('status') == 1){
  72. $status=1;
  73. }else if($this->request->param('status') == 2){
  74. $status=2;
  75. }
  76. // $status = ($this->request->param('status') == 1) ? 1 : -1;
  77. if($status == 1 || $status == 2){
  78. $refund_order=$this->repository->get($id);
  79. if($status==2){
  80. $part_refund_message = $this->request->param('part_refund_message','');
  81. $refund_price =(float) $this->request->param('part_refund_price',0);
  82. if($refund_price<0.01){
  83. return app('json')->fail('退款金额不能小于0.01');
  84. }
  85. if($refund_order && $refund_price >$refund_order['refund_price']){
  86. return app('json')->fail('退款金额不能大于用户申请金额');
  87. }
  88. if($part_refund_message==''){
  89. return app('json')->fail('请填写商家备注');
  90. }
  91. $this->repository->update($id,['part_refund_price'=>$refund_price,'part_refund_message' => $part_refund_message,'part_refund_time'=>date('Y-m-d H:i:s')]);
  92. }
  93. $douduo = $this -> repository -> douduofund($id,true);
  94. if($douduo['code'] < 0){
  95. return app('json')->fail($douduo['message']);
  96. }
  97. if($douduo['code'] == 2){
  98. return app('json')->success($douduo['message']);
  99. }
  100. $data = $this->request->params(['mer_delivery_user','mer_delivery_address','phone']);
  101. if($refund_order['refund_type']==2 && $status == 1 && ($data['mer_delivery_user']=='' || $data['mer_delivery_address']=='' || $data['phone']=='')){
  102. return app('json')->fail('请输入收货人信息');
  103. }
  104. $data['status'] = $status;
  105. // Db::name('log')->insert(['data'=>'这了'. 1]);
  106. $this->repository->agree($id,$data,$this->request->adminId(),1);
  107. }else{
  108. $fail_message = $this->request->param('fail_message','');
  109. if($status == -1 && empty($fail_message)){
  110. return app('json')->fail('未通过必须填写');
  111. }
  112. if($fail_message==''){
  113. return app('json')->fail('未通过必须填写');
  114. }
  115. $data['status'] = $status;
  116. $data['fail_message'] = $fail_message;
  117. $this->repository->refuse($id,$data);
  118. $this->repository->set_consult(2,$id);//协商记录
  119. }
  120. return app('json')->success('审核成功');
  121. }
  122. /**
  123. * TODO 收货后确定退款
  124. * @param $id
  125. * @return mixed
  126. * @author Qinii
  127. * @day 2020-06-12
  128. */
  129. public function refundPrice($id)
  130. {
  131. if($this->request->param('status') == 2){
  132. $part_refund_message = $this->request->param('part_refund_message','');
  133. $refund_price =(float) $this->request->param('part_refund_price',0);
  134. if($refund_price<0.01){
  135. return app('json')->fail('退款金额不能小于0.01');
  136. }
  137. $refund_order=$this->repository->get($id);
  138. if($refund_order && $refund_price>$refund_order['refund_price']){
  139. return app('json')->fail('退款金额不能大于用户申请金额');
  140. }
  141. $this->repository->update($id,['part_refund_price'=>$refund_price,'part_refund_message' => $part_refund_message,'part_refund_time'=>date('Y-m-d H:i:s')]);
  142. }else if($this->request->param('status') == -1){
  143. $fail_message = $this->request->param('fail_message','');
  144. if(empty($fail_message))
  145. return app('json')->fail('未通过必须填写');
  146. $data['status'] = -1;
  147. $data['fail_message'] = $fail_message;
  148. $this->repository->refuse($id,$data);
  149. $this->repository->set_consult(7,$id);//协商记录
  150. return app('json')->success('拒绝成功');
  151. }
  152. $this->repository->set_consult(5,$id);//协商记录
  153. $this->repository->adminRefund($id,$this->request->adminId());
  154. return app('json')->success('退款成功');
  155. }
  156. /**
  157. * TODO 快递查询
  158. * @param $id
  159. * @return mixed
  160. * @author Qinii
  161. * @day 2020-06-25
  162. */
  163. public function express($id)
  164. {
  165. // if(!$this->repository->getWhereCount(['refund_order_id' => $id,'status' =>2]))
  166. // return app('json')->fail('订单信息或状态错误');
  167. return app('json')->success($this->repository->express($id));
  168. }
  169. public function reList($id)
  170. {
  171. [$page,$limit] = $this->getPage();
  172. $where = ['reconciliation_id' => $id,'type' => 1];
  173. return app('json')->success($this->repository->reconList($where,$page,$limit));
  174. }
  175. public function dhm_list(){
  176. [$page,$limit] = $this->getPage();
  177. $status = $this->request->param('status','');
  178. $order_sn = $this->request->param('order_sn');
  179. $refund_order_sn = $this->request->param('refund_order_sn');
  180. $query = Db::name('StoreRefundOrder')
  181. -> alias('sro')
  182. -> join('StoreOrder so','sro.order_id = so.order_id')
  183. -> where('so.supply_type','in',[1,4,5]);
  184. if($status != ''){
  185. $query -> where('so.douhuomall_status',$status);
  186. }
  187. if($order_sn != ''){
  188. $query -> where('so.order_sn',$order_sn);
  189. }
  190. if($refund_order_sn != ''){
  191. $query -> where('sro.refund_order_sn',$refund_order_sn);
  192. }
  193. $query -> order('sro.refund_order_id desc');
  194. $count = $query->count();
  195. $list = $query->page($page, $limit)->field("so.*,sro.*,sro.status as sro_status") -> select();
  196. if ($list){
  197. $list = $list -> toArray();
  198. foreach ($list as $key => &$value){
  199. $product = Db::name('store_refund_product') -> where('refund_order_id',$value['refund_order_id']) -> select()->each(function ($item){
  200. $item['product'] = Db::name('store_order_product') -> where('order_product_id',$item['order_product_id']) -> find();
  201. $item['product']['cart_info'] = json_decode($item['product']['cart_info']);
  202. return $item;
  203. });
  204. $value['refundProduct'] = $product;
  205. $value['user'] = Db::name('user') -> where('uid',$value['uid']) -> field('nickname,phone,uid') -> find();
  206. }
  207. }
  208. return app('json')->success(compact('count', 'list'));
  209. }
  210. public function dhm_status(){
  211. $status = $this->request->param('status',0);
  212. $id = $this->request->param('id',0);
  213. $c = Db::name('StoreRefundOrder') -> where(['refund_order_id' => $id]) -> field('status') -> find();
  214. if($c['status'] != 0 || !$c || $status == 0) return app('json')->fail('信息或状态错误');
  215. if ($status == -1){
  216. $fail_message = $this->request->param('fail_message','');
  217. if($status == -1 && empty($fail_message))
  218. return app('json')->fail('未通过必须填写');
  219. $data['status'] = $status;
  220. $data['fail_message'] = $fail_message;
  221. $this->repository->refuse($id,$data);
  222. }elseif ($status == 2){
  223. //处理中
  224. $dhm_msg = $this->request->param('dhm_msg','');
  225. Db::name('StoreRefundOrder') -> where(['refund_order_id' => $id]) -> update(['dhm_msg'=>$dhm_msg]);
  226. return app('json')->success('提交成功');
  227. }else{
  228. $data['status'] = $status;
  229. $this->repository->agree($id,$data,$this->request->adminId(),1);
  230. }
  231. return app('json')->success('审核成功');
  232. }
  233. }