Membervrrefund.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 虚拟退款控制器
  14. */
  15. class Membervrrefund extends MobileMember {
  16. public function initialize() {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberrefund.lang.php');
  19. }
  20. /**
  21. * @api {POST} api/Membervrrefund/add_refund 添加兑换码退款
  22. * @apiVersion 1.0.0
  23. * @apiGroup Membervrrefund
  24. *
  25. * @apiHeader {String} X-DS-KEY 用户授权token
  26. *
  27. * @apiParam {Int} orderId 订单id
  28. * @apiParam {Array} rec_id 订单商品id
  29. * @apiParam {String} buyer_message 买家留言
  30. *
  31. * @apiSuccess {String} code 返回码,10000为成功
  32. * @apiSuccess {String} message 返回消息
  33. * @apiSuccess {Object} result 返回数据
  34. */
  35. public function add_refund() {
  36. $vrrefund_model = model('vrrefund');
  37. $order_id = intval(input('param.order_id'));
  38. if ($order_id < 1) {//参数验证
  39. ds_json_encode(10001, lang('param_error'));
  40. }
  41. $condition = array();
  42. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  43. $condition[] = array('order_id','=',$order_id);
  44. $order_info = $vrrefund_model->getRightVrorderList($condition,$order_id);
  45. $order = $order_info['order_info'];
  46. if (!$order['if_refund']) {//检查状态,防止页面刷新不及时造成数据错误
  47. ds_json_encode(10001, lang('param_error'));
  48. }
  49. $code_list = $order['code_list'];
  50. $refund_array = array();
  51. $goods_num = 0; //兑换码数量
  52. $refund_amount = 0; //退款金额
  53. $redeemcode_sn = '';
  54. $rec_id_array = input('post.rec_id/a');
  55. if (!empty($rec_id_array) && is_array($rec_id_array)) {//选择退款的兑换码
  56. foreach ($rec_id_array as $key => $value) {
  57. $code = $code_list[$value];
  58. if (!empty($code)) {
  59. $goods_num += 1;
  60. $refund_amount += $code['pay_price']; //实际支付金额
  61. $redeemcode_sn .= $code['vr_code'] . ','; //兑换码编号
  62. }
  63. }
  64. }
  65. if ($goods_num < 1) {
  66. ds_json_encode(10001, lang('param_error'));
  67. }
  68. $refund_array['redeemcode_sn'] = rtrim($redeemcode_sn, ',');
  69. $refund_array['admin_state'] = '1'; //状态:1为待审核,2为同意,3为不同意
  70. $refund_array['refund_amount'] = ds_price_format($refund_amount);
  71. $refund_array['goods_num'] = $goods_num;
  72. $refund_array['buyer_message'] = input('post.buyer_message');
  73. $refund_array['add_time'] = TIMESTAMP;
  74. $state = $vrrefund_model->addVrrefund($refund_array, $order);
  75. if ($state) {
  76. ds_json_encode(10000, lang('ds_common_op_succ'));
  77. } else {
  78. ds_json_encode(10001, lang('ds_common_op_fail'));
  79. }
  80. }
  81. /**
  82. * @api {POST} api/Membervrrefund/refund_form 获取退款信息
  83. * @apiVersion 1.0.0
  84. * @apiGroup Membervrrefund
  85. *
  86. * @apiHeader {String} X-DS-KEY 用户授权token
  87. *
  88. * @apiParam {Int} order_id 订单id
  89. *
  90. * @apiSuccess {String} code 返回码,10000为成功
  91. * @apiSuccess {String} message 返回消息
  92. * @apiSuccess {Object} result 返回数据
  93. * @apiSuccess {Object} result.order 虚拟订单信息 (返回字段参考vrorder表)
  94. * @apiSuccess {Object[]} result.code_list 可兑换的兑换码列表 (返回字段参考vrordercode表)
  95. */
  96. public function refund_form() {
  97. $vrrefund_model = model('vrrefund');
  98. $order_id = intval(input('param.order_id'));
  99. if ($order_id < 1) {//参数验证
  100. ds_json_encode(10001, lang('param_error'));
  101. }
  102. $condition = array();
  103. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  104. $condition[] = array('order_id','=',$order_id);
  105. $order_info = $vrrefund_model->getRightVrorderList($condition,$order_id);
  106. $order = $order_info['order_info'];
  107. if (!$order['if_refund']) {//检查状态,防止页面刷新不及时造成数据错误
  108. ds_json_encode(10001, lang('param_error'));
  109. }
  110. $code_list = $order['code_list'];
  111. ds_json_encode(10000, '', array('order' => $order, 'code_list' => $code_list));
  112. }
  113. /**
  114. * @api {POST} api/Membervrrefund/index 退款记录列表
  115. * @apiVersion 1.0.0
  116. * @apiGroup Membervrrefund
  117. *
  118. * @apiHeader {String} X-DS-KEY 用户授权token
  119. *
  120. * @apiParam {Int} page 页码
  121. * @apiParam {Int} per_page 每页数量
  122. * @apiParam {String} type 查询字段 order_sn订单号 refund_sn退款单号 goods_name商品名
  123. * @apiParam {String} key 查询关键词
  124. * @apiParam {String} add_time_from 时间从 YYYY-MM-DD
  125. * @apiParam {String} add_time_to 时间到 YYYY-MM-DD
  126. *
  127. * @apiSuccess {String} code 返回码,10000为成功
  128. * @apiSuccess {String} message 返回消息
  129. * @apiSuccess {Object} result 返回数据
  130. * @apiSuccess {Object[]} result.refund_list 退款列表 (返回字段参考vrrefund表)
  131. * @apiSuccess {String} result.refund_list.goods_image_url 商品图片完整路径
  132. * @apiSuccess {String} result.refund_list.admin_state_text 管理员处理状态描述
  133. * @apiSuccess {Int} result.page_total 总页数
  134. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  135. */
  136. public function index() {
  137. $condition = array();
  138. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  139. $keyword_type = array('order_sn', 'refund_sn', 'goods_name');
  140. if (trim(input('param.key')) != '' && in_array(input('param.type'), $keyword_type)) {
  141. $type = input('param.type');
  142. $condition[] = array($type, 'like', '%' . input('param.key') . '%');
  143. }
  144. if (trim(input('param.add_time_from')) != '' || trim(input('param.add_time_to')) != '') {
  145. $add_time_from = input('param.add_time_from');
  146. $add_time_to = input('param.add_time_to');
  147. if ($add_time_from !== false || $add_time_to !== false) {
  148. $condition[] = array('add_time', 'between time', array($add_time_from, $add_time_to));
  149. }
  150. }
  151. $vrrefund_model = model('vrrefund');
  152. $refund_list = $vrrefund_model->getVrrefundList($condition, 10);
  153. foreach ($refund_list as $key => $val) {
  154. $refund_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
  155. $admin_state = $this->getRefundStateArray('admin');
  156. $refund_list[$key]['admin_state_text'] = $admin_state[$val['admin_state']];
  157. }
  158. $result = array_merge(array('refund_list' => $refund_list), mobile_page($vrrefund_model->page_info));
  159. ds_json_encode(10000, '', $result);
  160. }
  161. /**
  162. * @api {POST} api/Membervrrefund/view 退款记录查看
  163. * @apiVersion 1.0.0
  164. * @apiGroup Membervrrefund
  165. *
  166. * @apiHeader {String} X-DS-KEY 用户授权token
  167. *
  168. * @apiParam {Int} refund_id 退款ID
  169. *
  170. * @apiSuccess {String} code 返回码,10000为成功
  171. * @apiSuccess {String} message 返回消息
  172. * @apiSuccess {Object} result 返回数据
  173. * @apiSuccess {String[]} result.code_array 退款兑换码列表
  174. * @apiSuccess {Object} result.refund 退款信息 (返回字段参考vrrefund表)
  175. * @apiSuccess {Object} result.order 退款信息 (返回字段参考vrorder表)
  176. */
  177. public function view() {
  178. $vrrefund_model = model('vrrefund');
  179. $condition = array();
  180. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  181. $condition[] = array('refund_id','=',intval(input('param.refund_id')));
  182. $refund = $vrrefund_model->getOneVrrefund($condition);
  183. if(!$refund){
  184. ds_json_encode(10001, lang('param_error'));
  185. }
  186. $code_array = explode(',', $refund['redeemcode_sn']);
  187. $condition = array();
  188. $condition[] = array('order_id','=',$refund['order_id']);
  189. $order_info = $vrrefund_model->getRightVrorderList($condition,$refund['order_id']);
  190. ds_json_encode(10000, '', array('code_array' => $code_array, 'refund' => $refund, 'order' => $order_info['order_info']));
  191. }
  192. /* 退款审核状态 */
  193. function getRefundStateArray($type = '') {
  194. if ($type == 'admin') {
  195. $admin_array = array(
  196. '1' => lang('refund_state_confirm'), '2' => lang('refund_state_yes'), '3' => lang('refund_state_no')
  197. );
  198. return $admin_array;
  199. }
  200. }
  201. }