Membervrrefund.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 虚拟退款控制器
  15. */
  16. class Membervrrefund extends MobileMember {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberrefund.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Membervrrefund/add_refund 添加兑换码退款
  23. * @apiVersion 1.0.0
  24. * @apiGroup Membervrrefund
  25. *
  26. * @apiHeader {String} X-DS-KEY 用户授权token
  27. *
  28. * @apiParam {Int} orderId 订单id
  29. * @apiParam {Array} rec_id 订单商品id
  30. * @apiParam {String} buyer_message 买家留言
  31. *
  32. * @apiSuccess {String} code 返回码,10000为成功
  33. * @apiSuccess {String} message 返回消息
  34. * @apiSuccess {Object} result 返回数据
  35. */
  36. public function add_refund() {
  37. $vrrefund_model = model('vrrefund');
  38. $order_id = intval(input('param.order_id'));
  39. if ($order_id < 1) {//参数验证
  40. ds_json_encode(10001, lang('param_error'));
  41. }
  42. $condition = array();
  43. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  44. $condition[] = array('order_id','=',$order_id);
  45. $order_info = $vrrefund_model->getRightVrorderList($condition,$order_id);
  46. $order = $order_info['order_info'];
  47. if (!$order['if_refund']) {//检查状态,防止页面刷新不及时造成数据错误
  48. ds_json_encode(10001, lang('param_error'));
  49. }
  50. $code_list = $order['code_list'];
  51. $refund_array = array();
  52. $goods_num = 0; //兑换码数量
  53. $refund_amount = 0; //退款金额
  54. $redeemcode_sn = '';
  55. $rec_id_array = input('post.rec_id/a');
  56. if (!empty($rec_id_array) && is_array($rec_id_array)) {//选择退款的兑换码
  57. foreach ($rec_id_array as $key => $value) {
  58. $code = $code_list[$value];
  59. if (!empty($code)) {
  60. $goods_num += 1;
  61. $refund_amount += $code['pay_price']; //实际支付金额
  62. $redeemcode_sn .= $code['vr_code'] . ','; //兑换码编号
  63. }
  64. }
  65. }
  66. if ($goods_num < 1) {
  67. ds_json_encode(10001, lang('param_error'));
  68. }
  69. $refund_array['redeemcode_sn'] = rtrim($redeemcode_sn, ',');
  70. $refund_array['admin_state'] = '1'; //状态:1为待审核,2为同意,3为不同意
  71. $refund_array['refund_amount'] = ds_price_format($refund_amount);
  72. $refund_array['goods_num'] = $goods_num;
  73. $refund_array['buyer_message'] = input('post.buyer_message');
  74. $refund_array['add_time'] = TIMESTAMP;
  75. $state = $vrrefund_model->addVrrefund($refund_array, $order);
  76. if ($state) {
  77. ds_json_encode(10000, lang('ds_common_op_succ'));
  78. } else {
  79. ds_json_encode(10001, lang('ds_common_op_fail'));
  80. }
  81. }
  82. /**
  83. * @api {POST} api/Membervrrefund/refund_form 获取退款信息
  84. * @apiVersion 1.0.0
  85. * @apiGroup Membervrrefund
  86. *
  87. * @apiHeader {String} X-DS-KEY 用户授权token
  88. *
  89. * @apiParam {Int} order_id 订单id
  90. *
  91. * @apiSuccess {String} code 返回码,10000为成功
  92. * @apiSuccess {String} message 返回消息
  93. * @apiSuccess {Object} result 返回数据
  94. * @apiSuccess {Object} result.order 虚拟订单信息 (返回字段参考vrorder表)
  95. * @apiSuccess {Object[]} result.code_list 可兑换的兑换码列表 (返回字段参考vrordercode表)
  96. */
  97. public function refund_form() {
  98. $vrrefund_model = model('vrrefund');
  99. $order_id = intval(input('param.order_id'));
  100. if ($order_id < 1) {//参数验证
  101. ds_json_encode(10001, lang('param_error'));
  102. }
  103. $condition = array();
  104. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  105. $condition[] = array('order_id','=',$order_id);
  106. $order_info = $vrrefund_model->getRightVrorderList($condition,$order_id);
  107. $order = $order_info['order_info'];
  108. if (!$order['if_refund']) {//检查状态,防止页面刷新不及时造成数据错误
  109. ds_json_encode(10001, lang('param_error'));
  110. }
  111. $code_list = $order['code_list'];
  112. ds_json_encode(10000, '', array('order' => $order, 'code_list' => $code_list));
  113. }
  114. /**
  115. * @api {POST} api/Membervrrefund/index 退款记录列表
  116. * @apiVersion 1.0.0
  117. * @apiGroup Membervrrefund
  118. *
  119. * @apiHeader {String} X-DS-KEY 用户授权token
  120. *
  121. * @apiParam {Int} page 页码
  122. * @apiParam {Int} per_page 每页数量
  123. * @apiParam {String} type 查询字段 order_sn订单号 refund_sn退款单号 goods_name商品名
  124. * @apiParam {String} key 查询关键词
  125. * @apiParam {String} add_time_from 时间从 YYYY-MM-DD
  126. * @apiParam {String} add_time_to 时间到 YYYY-MM-DD
  127. *
  128. * @apiSuccess {String} code 返回码,10000为成功
  129. * @apiSuccess {String} message 返回消息
  130. * @apiSuccess {Object} result 返回数据
  131. * @apiSuccess {Object[]} result.refund_list 退款列表 (返回字段参考vrrefund表)
  132. * @apiSuccess {String} result.refund_list.goods_image_url 商品图片完整路径
  133. * @apiSuccess {String} result.refund_list.admin_state_text 管理员处理状态描述
  134. * @apiSuccess {Int} result.page_total 总页数
  135. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  136. */
  137. public function index() {
  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. $vrrefund_model = model('vrrefund');
  180. $condition = array();
  181. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  182. $condition[] = array('refund_id','=',intval(input('param.refund_id')));
  183. $refund = $vrrefund_model->getOneVrrefund($condition);
  184. if(!$refund){
  185. ds_json_encode(10001, lang('param_error'));
  186. }
  187. $code_array = explode(',', $refund['redeemcode_sn']);
  188. $condition = array();
  189. $condition[] = array('order_id','=',$refund['order_id']);
  190. $order_info = $vrrefund_model->getRightVrorderList($condition,$refund['order_id']);
  191. ds_json_encode(10000, '', array('code_array' => $code_array, 'refund' => $refund, 'order' => $order_info['order_info']));
  192. }
  193. /* 退款审核状态 */
  194. function getRefundStateArray($type = '') {
  195. if ($type == 'admin') {
  196. $admin_array = array(
  197. '1' => lang('refund_state_confirm'), '2' => lang('refund_state_yes'), '3' => lang('refund_state_no')
  198. );
  199. return $admin_array;
  200. }
  201. }
  202. }