Orderrefund.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shopapi\controller;
  13. use app\model\order\OrderCommon;
  14. use app\model\order\OrderRefund as OrderRefundModel;
  15. use app\model\member\Member;
  16. /**
  17. * 订单维权
  18. * Class Orderrefund
  19. * @package app\shop\controller
  20. */
  21. class Orderrefund extends BaseApi
  22. {
  23. public function __construct()
  24. {
  25. //执行父类构造函数
  26. parent::__construct();
  27. $token = $this->checkToken();
  28. if ($token[ 'code' ] < 0) {
  29. echo $this->response($token);
  30. exit;
  31. }
  32. }
  33. /**
  34. * 获取订单条件
  35. * @return false|string
  36. */
  37. public function condition()
  38. {
  39. $order_refund_model = new OrderRefundModel();
  40. $refund_status_list = $order_refund_model->order_refund_status;
  41. $data = [
  42. 'refund_status_list' => $refund_status_list,//退款状态
  43. 'refund_type_list' => $order_refund_model->refund_type//退款方式
  44. ];
  45. return $this->response($this->success($data));
  46. }
  47. /**
  48. * 维权订单列表
  49. * @return mixed
  50. */
  51. public function lists()
  52. {
  53. $refund_status = isset($this->params[ 'refund_status' ]) ? $this->params[ 'refund_status' ] : '';//退款状态
  54. $sku_name = isset($this->params[ 'sku_name' ]) ? $this->params[ 'sku_name' ] : '';//商品名称
  55. $refund_type = isset($this->params[ 'refund_type' ]) ? $this->params[ 'refund_type' ] : '';//退款方式
  56. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';//开始时间
  57. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';//结束时间
  58. $order_no = isset($this->params[ 'order_no' ]) ? $this->params[ 'order_no' ] : '';//订单编号
  59. $delivery_status = isset($this->params[ 'delivery_status' ]) ? $this->params[ 'delivery_status' ] : '';//物流状态
  60. $refund_no = isset($this->params[ 'refund_no' ]) ? $this->params[ 'refund_no' ] : '';//退款编号
  61. $delivery_no = isset($this->params[ 'delivery_no' ]) ? $this->params[ 'delivery_no' ] : '';//物流编号
  62. $refund_delivery_no = isset($this->params[ 'refund_delivery_no' ]) ? $this->params[ 'refund_delivery_no' ] : '';//退款物流编号
  63. $order_refund_model = new OrderRefundModel();
  64. $page_index = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  65. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  66. $condition = [
  67. [ "nop.site_id", "=", $this->site_id ]
  68. ];
  69. //退款状态
  70. if ($refund_status != "") {
  71. $condition[] = [ "nop.refund_status", "=", $refund_status ];
  72. } else {
  73. $condition[] = [ "nop.refund_status", "<>", 0 ];
  74. }
  75. //物流状态
  76. if ($delivery_status != "") {
  77. $condition[] = [ "nop.delivery_status", "=", $delivery_status ];
  78. }
  79. //商品名称
  80. if ($sku_name != "") {
  81. $condition[] = [ "nop.sku_name", "like", "%$sku_name%" ];
  82. }
  83. //退款方式
  84. if ($refund_type != "") {
  85. $condition[] = [ "nop.refund_type", "=", $refund_type ];
  86. }
  87. //退款编号
  88. if ($refund_no != "") {
  89. $condition[] = [ "nop.refund_no", "like", "%$refund_no%" ];
  90. }
  91. //订单编号
  92. if ($order_no != "") {
  93. $condition[] = [ "nop.order_no", "like", "%$order_no%" ];
  94. }
  95. //物流编号
  96. if ($delivery_no != "") {
  97. $condition[] = [ "nop.delivery_no", "like", "%$delivery_no%" ];
  98. }
  99. //退款物流编号
  100. if ($refund_delivery_no != "") {
  101. $condition[] = [ "nop.refund_delivery_no", "like", "%$refund_delivery_no%" ];
  102. }
  103. if (!empty($start_time) && empty($end_time)) {
  104. $condition[] = [ "nop.refund_action_time", ">=", date_to_time($start_time) ];
  105. } elseif (empty($start_time) && !empty($end_time)) {
  106. $condition[] = [ "nop.refund_action_time", "<=", date_to_time($end_time) ];
  107. } elseif (!empty($start_time) && !empty($end_time)) {
  108. $condition[] = [ 'nop.refund_action_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  109. }
  110. $list = $order_refund_model->getRefundOrderGoodsPageList($condition, $page_index, $page_size, "nop.refund_action_time desc");
  111. return $this->response($list);
  112. }
  113. /**
  114. * 维权订单详情
  115. * @return mixed
  116. */
  117. public function detail()
  118. {
  119. $order_goods_id = isset($this->params[ 'order_goods_id' ]) ? $this->params[ 'order_goods_id' ] : 0;
  120. //维权订单项信息
  121. $order_refund_model = new OrderRefundModel();
  122. $detail_result = $order_refund_model->getRefundDetail($order_goods_id);
  123. $detail = $detail_result[ "data" ];
  124. if (empty($detail)) {
  125. return $this->response($this->error('查询不到此退款信息!'));
  126. }
  127. if ($detail['site_id'] != $this->site_id){
  128. return $this->response($this->error('查询不到此退款信息!'));
  129. }
  130. $order_common_model = new OrderCommon();
  131. $order_info_result = $order_common_model->getOrderInfo([ [ "order_id", "=", $detail[ "order_id" ] ], [ 'site_id', '=', $this->site_id ] ]);
  132. $order_info = $order_info_result[ "data" ];
  133. //添加会员昵称
  134. $member = new Member();
  135. $member_info = $member->getMemberInfo([ [ "member_id", '=', $order_info[ 'member_id' ] ] ], 'nickname');
  136. $order_info[ 'nickname' ] = $member_info[ 'data' ][ 'nickname' ];
  137. $data = [
  138. 'detail' => $detail,
  139. 'order_info' => $order_info
  140. ];
  141. return $this->response($this->success($data));
  142. }
  143. /**
  144. * 维权拒绝
  145. * @return mixed
  146. */
  147. public function refuse()
  148. {
  149. $order_goods_id = isset($this->params[ 'order_goods_id' ]) ? $this->params[ 'order_goods_id' ] : 0;
  150. $refund_refuse_reason = isset($this->params[ 'refund_refuse_reason' ]) ? $this->params[ 'refund_refuse_reason' ] : '';
  151. $order_refund_model = new OrderRefundModel();
  152. $data = array (
  153. "order_goods_id" => $order_goods_id,
  154. "refund_refuse_reason" => $refund_refuse_reason,
  155. 'site_id' => $this->site_id
  156. );
  157. $log_data = [
  158. 'uid' => $this->user_info[ 'uid' ],
  159. 'nick_name' => $this->user_info[ 'username' ],
  160. 'action' => '商家拒绝了维权',
  161. 'action_way' => 2
  162. ];
  163. $res = $order_refund_model->orderRefundRefuse($data, $this->user_info, $refund_refuse_reason, $log_data);
  164. return $this->response($res);
  165. }
  166. /**
  167. * 维权同意
  168. * @return mixed
  169. */
  170. public function agree()
  171. {
  172. $order_goods_id = isset($this->params[ 'order_goods_id' ]) ? $this->params[ 'order_goods_id' ] : 0;
  173. $order_refund_model = new OrderRefundModel();
  174. $data = array (
  175. "order_goods_id" => $order_goods_id,
  176. 'site_id' => $this->site_id
  177. );
  178. $res = $order_refund_model->orderRefundConfirm($data, $this->user_info);
  179. return $this->response($res);
  180. }
  181. /**
  182. * 维权收货
  183. * @return mixed
  184. */
  185. public function receive()
  186. {
  187. $order_goods_id = isset($this->params[ 'order_goods_id' ]) ? $this->params[ 'order_goods_id' ] : 0;
  188. $is_refund_stock = isset($this->params[ 'is_refund_stock' ]) ? $this->params[ 'is_refund_stock' ] : 0;
  189. $order_refund_model = new OrderRefundModel();
  190. $data = array (
  191. "order_goods_id" => $order_goods_id,
  192. "is_refund_stock" => $is_refund_stock,
  193. 'site_id' => $this->site_id
  194. );
  195. $res = $order_refund_model->orderRefundTakeDelivery($data, $this->user_info);
  196. return $this->response($res);
  197. }
  198. /**
  199. * 维权通过
  200. * @return mixed
  201. */
  202. public function complete()
  203. {
  204. $order_goods_id = isset($this->params[ 'order_goods_id' ]) ? $this->params[ 'order_goods_id' ] : 0;
  205. $refund_money_type = $this->params[ 'refund_money_type' ] ?? 2;
  206. $shop_refund_remark = $this->params[ 'shop_refund_remark' ] ?? '';
  207. $refund_real_money = $this->params[ 'refund_real_money' ] ?? 0;
  208. $order_refund_model = new OrderRefundModel();
  209. $data = array (
  210. 'order_goods_id' => $order_goods_id,
  211. 'site_id' => $this->site_id,
  212. 'refund_money_type' => $refund_money_type,
  213. 'shop_refund_remark' => $shop_refund_remark,
  214. 'refund_real_money' => $refund_real_money
  215. );
  216. $log_data = [
  217. 'uid' => $this->user_info[ 'uid' ],
  218. 'nick_name' => $this->user_info[ 'username' ],
  219. 'action' => '商家对维权进行了转账,维权结束',
  220. 'action_way' => 2
  221. ];
  222. $res = $order_refund_model->orderRefundFinish($data, $this->user_info, $log_data);
  223. return $this->response($res);
  224. }
  225. /**
  226. * 维权关闭
  227. * @return false|string
  228. */
  229. public function close(){
  230. $order_goods_id = isset($this->params[ 'order_goods_id' ]) ? $this->params[ 'order_goods_id' ] : 0;
  231. $order_refund_model = new OrderRefundModel();
  232. $res = $order_refund_model->orderRefundClose($order_goods_id, $this->site_id, $this->user_info);
  233. return $this->response($res);
  234. }
  235. /**
  236. * 主动退款
  237. * @return false|string
  238. */
  239. public function activeRefund(){
  240. $order_goods_id = $this->params['order_goods_id'] ?? 0;
  241. $refund_money_type = $this->params['refund_money_type'] ?? '';
  242. $shop_refund_remark = $this->params['shop_refund_remark'] ?? '';
  243. $do_refund_money = $this->params['do_refund_money'] ?? '';
  244. $order_refund_model = new OrderRefundModel();
  245. $params = array (
  246. 'site_id' => $this->site_id,
  247. 'app_module' => $this->app_module,
  248. 'refund_money_type' => $refund_money_type,
  249. 'shop_refund_remark' => $shop_refund_remark,
  250. 'user_info' => $this->user_info,
  251. 'order_goods_id' => $order_goods_id,
  252. 'do_refund_money' => $do_refund_money
  253. );
  254. $res = $order_refund_model->doOrderOrderRefund($params);
  255. return $this->response($res);
  256. }
  257. }