Membervrrefund.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 虚拟退款控制器
  10. */
  11. class Membervrrefund extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberrefund.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Membervrrefund/add_refund 添加兑换码退款
  20. * @apiVersion 1.0.0
  21. * @apiGroup Membervrrefund
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiParam {Int} orderId 订单id
  26. * @apiParam {Array} rec_id 订单商品id
  27. * @apiParam {String} buyer_message 买家留言
  28. *
  29. * @apiSuccess {String} code 返回码,10000为成功
  30. * @apiSuccess {String} message 返回消息
  31. * @apiSuccess {Object} result 返回数据
  32. */
  33. public function add_refund()
  34. {
  35. $vrrefund_model = model('vrrefund');
  36. $order_id = intval(input('param.order_id'));
  37. if ($order_id < 1) { //参数验证
  38. ds_json_encode(10001, lang('param_error'));
  39. }
  40. $condition = array();
  41. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  42. $condition[] = array('order_id', '=', $order_id);
  43. $order_info = $vrrefund_model->getRightVrorderList($condition, $order_id);
  44. $order = $order_info['order_info'];
  45. if (!$order['if_refund']) { //检查状态,防止页面刷新不及时造成数据错误
  46. ds_json_encode(10001, lang('param_error'));
  47. }
  48. $code_list = $order['code_list'];
  49. $refund_array = array();
  50. $goods_num = 0; //兑换码数量
  51. $refund_amount = 0; //退款金额
  52. $redeemcode_sn = '';
  53. $rec_id_array = input('post.rec_id/a');
  54. if (!empty($rec_id_array) && is_array($rec_id_array)) { //选择退款的兑换码
  55. foreach ($rec_id_array as $key => $value) {
  56. $code = $code_list[$value];
  57. if (!empty($code)) {
  58. $goods_num += 1;
  59. $refund_amount += $code['pay_price']; //实际支付金额
  60. $redeemcode_sn .= $code['vr_code'] . ','; //兑换码编号
  61. }
  62. }
  63. }
  64. if ($goods_num < 1) {
  65. ds_json_encode(10001, lang('param_error'));
  66. }
  67. $refund_array['redeemcode_sn'] = rtrim($redeemcode_sn, ',');
  68. $refund_array['admin_state'] = '1'; //状态:1为待审核,2为同意,3为不同意
  69. $refund_array['refund_amount'] = ds_price_format($refund_amount);
  70. $refund_array['goods_num'] = $goods_num;
  71. $refund_array['buyer_message'] = input('post.buyer_message');
  72. $refund_array['add_time'] = TIMESTAMP;
  73. $state = $vrrefund_model->addVrrefund($refund_array, $order);
  74. if ($state) {
  75. ds_json_encode(10000, lang('ds_common_op_succ'));
  76. } else {
  77. ds_json_encode(10001, lang('ds_common_op_fail'));
  78. }
  79. }
  80. /**
  81. * @api {POST} api/Membervrrefund/refund_form 获取退款信息
  82. * @apiVersion 1.0.0
  83. * @apiGroup Membervrrefund
  84. *
  85. * @apiHeader {String} X-DS-KEY 用户授权token
  86. *
  87. * @apiParam {Int} order_id 订单id
  88. *
  89. * @apiSuccess {String} code 返回码,10000为成功
  90. * @apiSuccess {String} message 返回消息
  91. * @apiSuccess {Object} result 返回数据
  92. * @apiSuccess {Object} result.order 虚拟订单信息 (返回字段参考vrorder表)
  93. * @apiSuccess {Object[]} result.code_list 可兑换的兑换码列表 (返回字段参考vrordercode表)
  94. */
  95. public function refund_form()
  96. {
  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. {
  138. $condition = array();
  139. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  140. $keyword_type = array('order_sn', 'refund_sn', 'goods_name');
  141. if (trim(input('param.key')) != '' && in_array(input('param.type'), $keyword_type)) {
  142. $type = input('param.type');
  143. $condition[] = array($type, 'like', '%' . input('param.key') . '%');
  144. }
  145. if (trim(input('param.add_time_from')) != '' || trim(input('param.add_time_to')) != '') {
  146. $add_time_from = input('param.add_time_from');
  147. $add_time_to = input('param.add_time_to');
  148. if ($add_time_from !== false || $add_time_to !== false) {
  149. $condition[] = array('add_time', 'between time', array($add_time_from, $add_time_to));
  150. }
  151. }
  152. $vrrefund_model = model('vrrefund');
  153. $refund_list = $vrrefund_model->getVrrefundList($condition, 10);
  154. foreach ($refund_list as $key => $val) {
  155. $refund_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
  156. $admin_state = $this->getRefundStateArray('admin');
  157. $refund_list[$key]['admin_state_text'] = $admin_state[$val['admin_state']];
  158. }
  159. $result = array_merge(array('refund_list' => $refund_list), mobile_page($vrrefund_model->page_info));
  160. ds_json_encode(10000, '', $result);
  161. }
  162. /**
  163. * @api {POST} api/Membervrrefund/view 退款记录查看
  164. * @apiVersion 1.0.0
  165. * @apiGroup Membervrrefund
  166. *
  167. * @apiHeader {String} X-DS-KEY 用户授权token
  168. *
  169. * @apiParam {Int} refund_id 退款ID
  170. *
  171. * @apiSuccess {String} code 返回码,10000为成功
  172. * @apiSuccess {String} message 返回消息
  173. * @apiSuccess {Object} result 返回数据
  174. * @apiSuccess {String[]} result.code_array 退款兑换码列表
  175. * @apiSuccess {Object} result.refund 退款信息 (返回字段参考vrrefund表)
  176. * @apiSuccess {Object} result.order 退款信息 (返回字段参考vrorder表)
  177. */
  178. public function view()
  179. {
  180. $vrrefund_model = model('vrrefund');
  181. $condition = array();
  182. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  183. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  184. $refund = $vrrefund_model->getOneVrrefund($condition);
  185. if (!$refund) {
  186. ds_json_encode(10001, lang('param_error'));
  187. }
  188. $code_array = explode(',', $refund['redeemcode_sn']);
  189. $condition = array();
  190. $condition[] = array('order_id', '=', $refund['order_id']);
  191. $order_info = $vrrefund_model->getRightVrorderList($condition, $refund['order_id']);
  192. ds_json_encode(10000, '', array('code_array' => $code_array, 'refund' => $refund, 'order' => $order_info['order_info']));
  193. }
  194. /* 退款审核状态 */
  195. function getRefundStateArray($type = '')
  196. {
  197. if ($type == 'admin') {
  198. $admin_array = array(
  199. '1' => lang('refund_state_confirm'), '2' => lang('refund_state_yes'), '3' => lang('refund_state_no')
  200. );
  201. return $admin_array;
  202. }
  203. }
  204. }