Memberrefund.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 退款控制器
  10. */
  11. class Memberrefund 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/Memberrefund/refund_all_form 全部退款获取订单信息
  20. * @apiVersion 1.0.0
  21. * @apiGroup Memberrefund
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiParam {Int} orderId 订单id
  26. *
  27. * @apiSuccess {String} code 返回码,10000为成功
  28. * @apiSuccess {String} message 返回消息
  29. * @apiSuccess {Object} result 返回数据
  30. * @apiSuccess {Object} result.order 订单信息
  31. * @apiSuccess {Int} result.order.order_id 订单ID
  32. * @apiSuccess {Float} result.order.order_amount 订单金额
  33. * @apiSuccess {String} result.order.order_sn 订单编号
  34. * @apiSuccess {String} result.order.store_name 店铺名称
  35. * @apiSuccess {Int} result.order.store_id 店铺ID
  36. * @apiSuccess {Float} result.order.allow_refund_amount 允许退款金额
  37. * @apiSuccess {Float} result.order.book_amount 已退款金额
  38. * @apiSuccess {Object[]} result.goods_list 订单商品信息
  39. * @apiSuccess {Int} result.goods_list.goods_id 商品ID
  40. * @apiSuccess {String} result.goods_list.goods_name 商品名称
  41. * @apiSuccess {Float} result.goods_list.goods_price 商品价格
  42. * @apiSuccess {Int} result.goods_list.goods_num 购买数量
  43. * @apiSuccess {String} result.goods_list.goods_img_480 商品缩略图完整路径
  44. * @apiSuccess {String} result.goods_list.goods_type 商品类型
  45. * @apiSuccess {Object[]} result.gift_list 订单信息
  46. */
  47. public function refund_all_form()
  48. {
  49. $refundreturn_model = model('refundreturn');
  50. $member_id = $this->member_info['member_id'];
  51. $order_id = intval(input('param.order_id'));
  52. $trade_model = model('trade');
  53. $order_paid = $trade_model->getOrderState('order_paid'); //订单状态20:已付款
  54. $order_model = model('order');
  55. $condition = array();
  56. $condition[] = array('buyer_id', '=', $member_id);
  57. $condition[] = array('order_id', '=', $order_id);
  58. $condition[] = array('order_state', '=', $order_paid);
  59. $order_info = $order_model->getOrderInfo($condition);
  60. if (!empty($order_info) && is_array($order_info)) {
  61. $order = $refundreturn_model->getRightOrderList($condition);
  62. $book_amount = $order_info['refund_amount']; //退款金额
  63. $order = array();
  64. $order['order_id'] = $order_info['order_id'];
  65. //$order['order_type'] = $order_info['order_type'];
  66. $order['order_amount'] = ds_price_format($order_info['order_amount'] - $order_info['presell_deposit_amount']);
  67. $order['order_sn'] = $order_info['order_sn'];
  68. $order['store_name'] = $order_info['store_name'];
  69. $order['store_id'] = $order_info['store_id'];
  70. $order['allow_refund_amount'] = ds_price_format($order_info['order_amount'] - $book_amount); //可退款金额
  71. $order['book_amount'] = ds_price_format($book_amount);
  72. $goods_list = array();
  73. $gift_list = array();
  74. $order_model = model('order');
  75. $condition = array();
  76. $condition[] = array('order_id', '=', $order_id);
  77. $order_goods_list = $order_model->getOrdergoodsList($condition);
  78. foreach ($order_goods_list as $key => $value) {
  79. $goods = array();
  80. $goods['goods_id'] = $value['goods_id'];
  81. $goods['goods_name'] = $value['goods_name'];
  82. $goods['goods_price'] = $value['goods_price'];
  83. $goods['goods_num'] = $value['goods_num'];
  84. //$goods['goods_spec'] = $value['goods_spec'];
  85. $goods['goods_img_480'] = goods_thumb($value, 480);
  86. $goods['goods_type'] = get_order_goodstype($value['goods_type']);
  87. if ($value['goods_type'] == 5) { //赠品商品
  88. $gift_list[] = $goods;
  89. } else {
  90. $goods_list[] = $goods;
  91. }
  92. }
  93. ds_json_encode(10000, '', array('order' => $order, 'goods_list' => $goods_list, 'gift_list' => $gift_list));
  94. } else {
  95. ds_json_encode(10001, lang('param_error'));
  96. }
  97. }
  98. /**
  99. * @api {POST} api/Memberrefund/refund_all_post 全部退款保存数据
  100. * @apiVersion 1.0.0
  101. * @apiGroup Memberrefund
  102. *
  103. * @apiHeader {String} X-DS-KEY 用户授权token
  104. *
  105. * @apiParam {Int} orderId 订单id
  106. * @apiParam {String} buyer_message 退款理由
  107. * @apiParam {Array} refund_pic 退款凭证
  108. *
  109. * @apiSuccess {String} code 返回码,10000为成功
  110. * @apiSuccess {String} message 返回消息
  111. */
  112. public function refund_all_post()
  113. {
  114. $refundreturn_model = model('refundreturn');
  115. $member_id = $this->member_info['member_id'];
  116. $order_id = intval(input('post.order_id'));
  117. $trade_model = model('trade');
  118. $order_paid = $trade_model->getOrderState('order_paid'); //订单状态20:已付款
  119. $order_model = model('order');
  120. $condition = array();
  121. $condition[] = array('buyer_id', '=', $member_id);
  122. $condition[] = array('order_id', '=', $order_id);
  123. $condition[] = array('order_state', 'in', [ORDER_STATE_PAY, ORDER_STATE_PICKUP]);
  124. $order_info = $order_model->getOrderInfo($condition);
  125. $payment_code = $order_info['payment_code']; //支付方式
  126. $condition = array();
  127. $condition[] = array('buyer_id', '=', $member_id);
  128. $condition[] = array('order_id', '=', $order_id);
  129. $condition[] = array('goods_id', '=', '0');
  130. $condition[] = array('refund_state', '<', '3');
  131. $refund = $refundreturn_model->getRefundreturnInfo($condition);
  132. if (empty($order_info) || $payment_code == 'offline' || $refund['refund_id'] > 0) { //检查数据,防止页面刷新不及时造成数据错误
  133. ds_json_encode(10001, lang('param_error'));
  134. } else {
  135. $book_amount = $order_info['refund_amount']; //退款金额
  136. $allow_refund_amount = ds_price_format($order_info['order_amount'] - $order_info['presell_deposit_amount'] - $book_amount); //可退款金额
  137. $refund_array = array();
  138. $refund_array['refund_type'] = '1'; //类型:1为退款,2为退货
  139. $refund_array['seller_state'] = '1'; //状态:1为待审核,2为同意,3为不同意
  140. $refund_array['order_lock'] = '2'; //锁定类型:1为不用锁定,2为需要锁定
  141. $refund_array['goods_id'] = '0';
  142. $refund_array['order_goods_id'] = '0';
  143. $refund_array['reason_id'] = '0';
  144. $refund_array['reason_info'] = lang('refund_notice4');
  145. $refund_array['goods_name'] = lang('all_orders_refunded');
  146. $refund_array['refund_amount'] = ds_price_format($allow_refund_amount);
  147. $refund_array['buyer_message'] = input('post.buyer_message');
  148. $refund_array['add_time'] = TIMESTAMP;
  149. $pic_array = array();
  150. $pic_array['buyer'] = input('post.refund_pic/a'); //上传凭证 获取数组
  151. $info = serialize($pic_array);
  152. $refund_array['pic_info'] = $info;
  153. $state = $refundreturn_model->addRefundreturn($refund_array, $order_info);
  154. if ($state) {
  155. $refundreturn_model->editOrderLock($order_id);
  156. //自提点订单锁定
  157. $chain_order_model = model('chain_order');
  158. $chain_order_model->editChainOrderLock($order_id);
  159. ds_json_encode(10000, lang('ds_common_op_succ'), 1);
  160. } else {
  161. ds_json_encode(10001, lang('ds_common_op_fail'));
  162. }
  163. }
  164. }
  165. /**
  166. * @api {POST} api/Memberrefund/refund_form 部分退款获取订单信息
  167. * @apiVersion 1.0.0
  168. * @apiGroup Memberrefund
  169. *
  170. * @apiHeader {String} X-DS-KEY 用户授权token
  171. *
  172. * @apiParam {Int} order_id 订单id
  173. * @apiParam {Int} order_goods_id 订单商品id
  174. *
  175. * @apiSuccess {String} code 返回码,10000为成功
  176. * @apiSuccess {String} message 返回消息
  177. * @apiSuccess {Object} result 返回数据
  178. * @apiSuccess {Object} result.order 订单信息
  179. * @apiSuccess {Int} result.order.order_id 订单ID
  180. * @apiSuccess {Float} result.order.order_amount 订单金额
  181. * @apiSuccess {String} result.order.order_sn 订单编号
  182. * @apiSuccess {String} result.order.store_name 店铺名称
  183. * @apiSuccess {Int} result.order.store_id 店铺ID
  184. * @apiSuccess {Float} result.order.allow_refund_amount 允许退款金额
  185. * @apiSuccess {Float} result.order.book_amount 已退款金额
  186. * @apiSuccess {Object[]} result.goods_list 订单商品信息
  187. * @apiSuccess {Int} result.goods_list.goods_id 商品ID
  188. * @apiSuccess {Int} result.goods_list.store_id 店铺ID
  189. * @apiSuccess {Int} result.goods_list.order_goods_id 订单商品ID
  190. * @apiSuccess {String} result.goods_list.goods_name 商品名称
  191. * @apiSuccess {Float} result.goods_list.goods_price 商品价格
  192. * @apiSuccess {Float} result.goods_list.goods_pay_price 实际支付价格
  193. * @apiSuccess {Int} result.goods_list.goods_num 购买数量
  194. * @apiSuccess {String} result.goods_list.goods_img_480 商品缩略图完整路径
  195. * @apiSuccess {String} result.goods_list.goods_type 商品类型
  196. * @apiSuccess {Object[]} result.reason_list 退款理由列表
  197. * @apiSuccess {Int} result.reason_list.reason_id 退款理由ID
  198. * @apiSuccess {String} result.reason_list.reason_info 退款理由
  199. */
  200. public function refund_form()
  201. {
  202. $refundreturn_model = model('refundreturn');
  203. $condition = array();
  204. $reason_list = $refundreturn_model->getReasonList($condition, '', '', 'reason_id,reason_info'); //退款退货原因
  205. $member_id = $this->member_info['member_id'];
  206. $order_id = intval(input('param.order_id'));
  207. $goods_id = intval(input('param.order_goods_id')); //订单商品表编号
  208. $order_model = model('order');
  209. $condition = array();
  210. $condition[] = array('buyer_id', '=', $member_id);
  211. $condition[] = array('order_id', '=', $order_id);
  212. $order_info = $refundreturn_model->getRightOrderList($condition, $goods_id);
  213. //halt($order_info);
  214. $refund_state = $refundreturn_model->getRefundState($order_info); //根据订单状态判断是否可以退款退货
  215. if ($refund_state == 1 && $goods_id > 0) {
  216. $order = array();
  217. $order['order_id'] = $order_info['order_id'];
  218. //$order['order_type'] = $order_info['order_type'];
  219. $order['order_amount'] = ds_price_format($order_info['order_amount']);
  220. $order['order_sn'] = $order_info['order_sn'];
  221. $order['store_name'] = $order_info['store_name'];
  222. $order['store_id'] = $order_info['store_id'];
  223. $goods = array();
  224. $goods_list = $order_info['goods_list'];
  225. $goods_info = $goods_list[0];
  226. $goods['store_id'] = $goods_info['store_id'];
  227. $goods['order_goods_id'] = $goods_info['rec_id'];
  228. $goods['goods_id'] = $goods_info['goods_id'];
  229. $goods['goods_name'] = $goods_info['goods_name'];
  230. $goods['goods_type'] = get_order_goodstype($goods_info['goods_type']);
  231. $goods['goods_img_480'] = goods_thumb($goods_info, 480);
  232. $goods['goods_price'] = ds_price_format($goods_info['goods_price']);
  233. //$goods['goods_spec'] = $goods_info['goods_spec'];
  234. $goods['goods_num'] = $goods_info['goods_num'];
  235. $goods_pay_price = $goods_info['goods_pay_price']; //商品实际成交价
  236. $goods_pay_price -= $order_info['presell_deposit_amount'];
  237. $order_amount = $order_info['order_amount']; //订单金额
  238. $order_refund_amount = $order_info['refund_amount']; //订单退款金额
  239. if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
  240. $goods_pay_price = $order_amount - $order_refund_amount;
  241. }
  242. $goods['goods_pay_price'] = ds_price_format($goods_pay_price);
  243. $reason_list = array_values($reason_list);
  244. ds_json_encode(10000, '', array('order' => $order, 'goods' => $goods, 'reason_list' => $reason_list));
  245. } else {
  246. ds_json_encode(10001, lang('param_error'));
  247. }
  248. }
  249. /**
  250. * @api {POST} api/Memberrefund/refund_post 部分退款保存数据
  251. * @apiVersion 1.0.0
  252. * @apiGroup Memberrefund
  253. *
  254. * @apiHeader {String} X-DS-KEY 用户授权token
  255. *
  256. * @apiParam {Int} order_id 订单id
  257. * @apiParam {Int} order_goods_id 订单商品id
  258. * @apiParam {Float} refund_amount 退款金额
  259. * @apiParam {Int} goods_num 退货数量
  260. * @apiParam {Int} reason_id 退款理由id
  261. * @apiParam {Int} refund_type 类型 1退款 2退货
  262. * @apiParam {String} buyer_message 退款理由
  263. * @apiParam {Array} refund_pic 退款凭证
  264. *
  265. * @apiSuccess {String} code 返回码,10000为成功
  266. * @apiSuccess {String} message 返回消息
  267. */
  268. public function refund_post()
  269. {
  270. $member_id = $this->member_info['member_id'];
  271. $order_id = intval(input('post.order_id'));
  272. $goods_id = intval(input('post.order_goods_id')); //订单商品表编号
  273. $order_model = model('order');
  274. $refundreturn_model = model('refundreturn');
  275. $condition = array();
  276. $condition[] = array('buyer_id', '=', $member_id);
  277. $condition[] = array('order_id', '=', $order_id);
  278. $order_info = $refundreturn_model->getRightOrderList($condition, $goods_id);
  279. $refund_state = $refundreturn_model->getRefundState($order_info); //根据订单状态判断是否可以退款退货
  280. $condition = array();
  281. $condition[] = array('buyer_id', '=', $member_id);
  282. $condition[] = array('order_id', '=', $order_id);
  283. $condition[] = array('order_goods_id', '=', $goods_id);
  284. $condition[] = array('refund_state', '<', '3');
  285. $refund = $refundreturn_model->getRefundreturnInfo($condition);
  286. if ($refund_state == 1 && $goods_id > 0 && empty($refund)) {
  287. $goods_list = $order_info['goods_list'];
  288. $goods_info = $goods_list[0];
  289. $refund_array = array();
  290. $goods_pay_price = $goods_info['goods_pay_price']; //商品实际成交价
  291. $goods_pay_price -= $order_info['presell_deposit_amount'];
  292. $order_amount = $order_info['order_amount']; //订单金额
  293. $order_refund_amount = $order_info['refund_amount']; //订单退款金额
  294. if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
  295. $goods_pay_price = $order_amount - $order_refund_amount;
  296. }
  297. $refund_amount = floatval(input('post.refund_amount')); //退款金额
  298. if (($refund_amount < 0) || ($refund_amount > $goods_pay_price)) {
  299. $refund_amount = $goods_pay_price;
  300. }
  301. $goods_num = !empty(input('post.goods_num')) ? intval(input('post.goods_num')) : 1; //退货数量
  302. if (($goods_num < 0) || ($goods_num > $goods_info['goods_num'])) {
  303. $goods_num = 1;
  304. }
  305. $reason_list = $refundreturn_model->getReasonList(array(), '', '', 'reason_id,reason_info'); //退款退货原因
  306. $refund_array['reason_info'] = '';
  307. $reason_id = intval(input('post.reason_id')); //退货退款原因
  308. $refund_array['reason_id'] = $reason_id;
  309. $reason_array = array();
  310. $reason_array['reason_info'] = lang('other');
  311. $reason_list[0] = $reason_array;
  312. if (!empty($reason_list[$reason_id])) {
  313. $reason_array = $reason_list[$reason_id];
  314. $refund_array['reason_info'] = $reason_array['reason_info'];
  315. }
  316. $pic_array = array();
  317. $pic_array['buyer'] = input('post.refund_pic/a'); //上传凭证 获取数组
  318. $info = serialize($pic_array);
  319. $refund_array['pic_info'] = $info;
  320. $trade_model = model('trade');
  321. $order_shipped = $trade_model->getOrderState('order_shipped'); //订单状态30:已发货
  322. $refund_array['order_lock'] = '1';
  323. if ($order_info['order_state'] == $order_shipped) {
  324. $refund_array['order_lock'] = '2'; //锁定类型:1为不用锁定,2为需要锁定
  325. }
  326. $refund_array['refund_type'] = input('post.refund_type'); //类型:1为退款,2为退货
  327. $refund_array['return_type'] = '2'; //退货类型:1为不用退货,2为需要退货
  328. if ($refund_array['refund_type'] != '2') {
  329. $refund_array['refund_type'] = '1';
  330. $refund_array['return_type'] = '1';
  331. }
  332. $refund_array['seller_state'] = '1'; //状态:1为待审核,2为同意,3为不同意
  333. $refund_array['refund_amount'] = ds_price_format($refund_amount);
  334. $refund_array['goods_num'] = $goods_num;
  335. $refund_array['buyer_message'] = input('post.buyer_message');
  336. $refund_array['add_time'] = TIMESTAMP;
  337. $state = $refundreturn_model->addRefundreturn($refund_array, $order_info, $goods_info);
  338. if ($state) {
  339. if ($order_info['order_state'] == $order_shipped) {
  340. $refundreturn_model->editOrderLock($order_id);
  341. }
  342. //自提点订单锁定
  343. $chain_order_model = model('chain_order');
  344. $chain_order_model->editChainOrderLock($order_id);
  345. ds_json_encode(10000, lang('ds_common_op_succ'), 1);
  346. } else {
  347. ds_json_encode(10001, lang('ds_common_op_fail'));
  348. }
  349. } else {
  350. ds_json_encode(10001, lang('param_error'));
  351. }
  352. }
  353. /**
  354. * @api {POST} api/Memberrefund/refund_all_post 上传凭证
  355. * @apiVersion 1.0.0
  356. * @apiGroup Memberrefund
  357. *
  358. * @apiHeader {String} X-DS-KEY 用户授权token
  359. *
  360. * @apiParam {File} refund_pic 退款凭证
  361. *
  362. * @apiSuccess {String} code 返回码,10000为成功
  363. * @apiSuccess {String} message 返回消息
  364. * @apiSuccess {Object} result 返回数据
  365. * @apiSuccess {String} result.file_name 文件名称
  366. * @apiSuccess {String} result.pic 文件完整路径
  367. */
  368. public function upload_pic()
  369. {
  370. if (empty($_FILES['refund_pic']['name'])) {
  371. ds_json_encode(10001, lang('file_empty'));
  372. }
  373. $res = ds_upload_pic(ATTACH_PATH . DIRECTORY_SEPARATOR . 'refund', 'refund_pic');
  374. if ($res['code']) {
  375. $file_name = $res['data']['file_name'];
  376. $pic = ds_get_pic(ATTACH_PATH . '/refund', $file_name);
  377. ds_json_encode(10000, '', array('file_name' => $file_name, 'pic' => $pic));
  378. } else {
  379. ds_json_encode(10001, $res['msg']);
  380. }
  381. }
  382. /**
  383. * @api {POST} api/Memberrefund/get_refund_list 退款记录列表
  384. * @apiVersion 1.0.0
  385. * @apiGroup Memberrefund
  386. *
  387. * @apiHeader {String} X-DS-KEY 用户授权token
  388. *
  389. * @apiParam {Int} page 页码
  390. * @apiParam {Int} per_page 每页数量
  391. * @apiParam {String} type 查询字段 order_sn订单号 refund_sn退款单号 goods_name商品名
  392. * @apiParam {String} k 查询关键词
  393. * @apiParam {String} add_time_from 时间从 YYYY-MM-DD
  394. * @apiParam {String} add_time_to 时间到 YYYY-MM-DD
  395. *
  396. * @apiSuccess {String} code 返回码,10000为成功
  397. * @apiSuccess {String} message 返回消息
  398. * @apiSuccess {Object} result 返回数据
  399. * @apiSuccess {Object[]} result.refund_list 退款列表
  400. * @apiSuccess {Int} result.refund_list.add_time 添加时间
  401. * @apiSuccess {String} result.refund_list.admin_state 管理员状态描述
  402. * @apiSuccess {Int} result.refund_list.admin_state_v 管理员处理状态 1:待审核 2:同意 3:不同意
  403. * @apiSuccess {Object[]} result.refund_list.goods_list 商品列表
  404. * @apiSuccess {Int} result.refund_list.goods_list.goods_id 商品ID
  405. * @apiSuccess {String} result.refund_list.goods_list.goods_img_480 商品缩略图完整路径
  406. * @apiSuccess {String} result.refund_list.goods_list.goods_name 商品名称
  407. * @apiSuccess {Int} result.refund_list.order_id 订单ID
  408. * @apiSuccess {String} result.refund_list.order_sn 订单编号
  409. * @apiSuccess {Float} result.refund_list.refund_amount 退款金额
  410. * @apiSuccess {Int} result.refund_list.refund_id 退款ID
  411. * @apiSuccess {String} result.refund_list.refund_sn 退款编号
  412. * @apiSuccess {String} result.refund_list.seller_state 卖家处理状态描述 1:待审核,2:同意,3:不同意
  413. * @apiSuccess {Int} result.refund_list.seller_state_v 卖家状态
  414. * @apiSuccess {Int} result.refund_list.store_id 店铺ID
  415. * @apiSuccess {String} result.refund_list.store_name 店铺描述
  416. * @apiSuccess {Int} result.page_total 总页数
  417. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  418. */
  419. public function get_refund_list()
  420. {
  421. $order_model = model('order');
  422. $refundreturn_model = model('refundreturn');
  423. $member_id = $this->member_info['member_id'];
  424. $refund_list = array();
  425. $condition = array();
  426. $condition[] = array('refund_type', '=', 1);
  427. $condition[] = array('buyer_id', '=', $member_id);
  428. $keyword_type = array('order_sn', 'refund_sn', 'goods_name');
  429. if (trim(input('param.k')) != '' && in_array(input('param.type'), $keyword_type)) {
  430. $type = input('param.type');
  431. $condition[] = array($type, 'like', '%' . input('param.k') . '%');
  432. }
  433. if (trim(input('param.add_time_from')) != '' || trim(input('param.add_time_to')) != '') {
  434. $add_time_from = strtotime(trim(input('param.add_time_from')));
  435. $add_time_to = strtotime(trim(input('param.add_time_to')));
  436. if ($add_time_from !== false || $add_time_to !== false) {
  437. $condition[] = array('add_time', 'time', array($add_time_from, $add_time_to));
  438. }
  439. }
  440. $list = $refundreturn_model->getRefundList($condition, $this->pagesize);
  441. if (!empty($list) && is_array($list)) {
  442. $seller_state = $this->getRefundStateArray('seller');
  443. $admin_state = $this->getRefundStateArray('admin');
  444. foreach ($list as $k => $v) {
  445. $val = array();
  446. $val['refund_id'] = $v['refund_id'];
  447. $val['order_id'] = $v['order_id'];
  448. $val['refund_amount'] = ds_price_format($v['refund_amount']);
  449. $val['refund_sn'] = $v['refund_sn'];
  450. $val['order_sn'] = $v['order_sn'];
  451. $val['add_time'] = date("Y-m-d H:i:s", $v['add_time']);
  452. $val['seller_state_v'] = $v['seller_state'];
  453. $val['seller_state'] = $seller_state[$v['seller_state']];
  454. $val['admin_state_v'] = $v['refund_state'];
  455. $val['admin_state'] = $admin_state[$v['refund_state']];
  456. $val['store_id'] = $v['store_id'];
  457. $val['store_name'] = $v['store_name'];
  458. $goods_list = array();
  459. if ($v['goods_id'] > 0) {
  460. $goods = array();
  461. $goods['goods_id'] = $v['goods_id'];
  462. $goods['goods_name'] = $v['goods_name'];
  463. $condition = array();
  464. $condition[] = array('rec_id', '=', $v['order_goods_id']);
  465. $order_goods_list = $order_model->getOrdergoodsList($condition);
  466. //$goods['goods_spec'] = $order_goods_list[0]['goods_spec'];
  467. $goods['goods_img_480'] = goods_thumb($v, 480);
  468. $goods_list[] = $goods;
  469. } else {
  470. $condition = array();
  471. $condition[] = array('order_id', '=', $v['order_id']);
  472. $order_goods_list = $order_model->getOrdergoodsList($condition);
  473. foreach ($order_goods_list as $key => $value) {
  474. $goods = array();
  475. $goods['goods_id'] = $value['goods_id'];
  476. $goods['goods_name'] = $value['goods_name'];
  477. //$goods['goods_spec'] = $value['goods_spec'];
  478. $goods['goods_img_480'] = goods_thumb($value, 480);
  479. $goods_list[] = $goods;
  480. }
  481. }
  482. $val['goods_list'] = $goods_list;
  483. $refund_list[] = $val;
  484. }
  485. }
  486. $result = array_merge(array('refund_list' => $refund_list), mobile_page($refundreturn_model->page_info));
  487. ds_json_encode(10000, '', $result);
  488. }
  489. /**
  490. * 查看退款信息
  491. *
  492. */
  493. public function get_refund_info()
  494. {
  495. $refundreturn_model = model('refundreturn');
  496. $member_id = $this->member_info['member_id'];
  497. $condition = array();
  498. $condition[] = array('buyer_id', '=', $member_id);
  499. $condition[] = array('refund_id', '=', intval(input('param.refund_id')));
  500. $refund_info = $refundreturn_model->getRefundreturnInfo($condition);
  501. if (!empty($refund_info) && is_array($refund_info)) {
  502. $seller_state = $this->getRefundStateArray('seller');
  503. $admin_state = $this->getRefundStateArray('admin');
  504. $refund = array();
  505. $refund['refund_id'] = $refund_info['refund_id'];
  506. $refund['goods_id'] = $refund_info['goods_id'];
  507. $refund['goods_name'] = $refund_info['goods_name'];
  508. $refund['order_id'] = $refund_info['order_id'];
  509. $refund['refund_amount'] = ds_price_format($refund_info['refund_amount']);
  510. $refund['refund_sn'] = $refund_info['refund_sn'];
  511. $refund['order_sn'] = $refund_info['order_sn'];
  512. $refund['add_time'] = date("Y-m-d H:i:s", $refund_info['add_time']);
  513. $refund['goods_img_480'] = goods_thumb($refund_info, 480);
  514. $refund['seller_state'] = $seller_state[$refund_info['seller_state']];
  515. $refund['admin_state'] = $admin_state[$refund_info['refund_state']];
  516. $refund['store_id'] = $refund_info['store_id'];
  517. $refund['store_name'] = $refund_info['store_name'];
  518. $refund['reason_info'] = $refund_info['reason_info'];
  519. $refund['buyer_message'] = $refund_info['buyer_message'];
  520. $refund['seller_message'] = $refund_info['seller_message'];
  521. $refund['admin_message'] = $refund_info['admin_message'];
  522. $info['buyer'] = array();
  523. if (!empty($refund_info['pic_info'])) {
  524. $info = unserialize($refund_info['pic_info']);
  525. }
  526. $pic_list = array();
  527. if (is_array($info['buyer'])) {
  528. foreach ($info['buyer'] as $k => $v) {
  529. if (!empty($v)) {
  530. $pic_list[] = ds_get_pic(ATTACH_PATH . '/refund', $v);
  531. }
  532. }
  533. }
  534. ds_json_encode(10000, '', array('refund' => $refund, 'pic_list' => $pic_list));
  535. } else {
  536. ds_json_encode(10001, lang('param_error'));
  537. }
  538. }
  539. /* 退款审核状态 */
  540. function getRefundStateArray($type = '')
  541. {
  542. if ($type == 'seller') {
  543. $state_array = array(
  544. '1' => lang('refund_state_confirm'), '2' => lang('refund_state_yes'), '3' => lang('refund_state_no')
  545. ); //卖家处理状态:1为待审核,2为同意,3为不同意
  546. return $state_array;
  547. };
  548. if ($type == 'admin') {
  549. $admin_array = array(
  550. '1' => lang('in_processing'), '2' => lang('to_be_processed'), '3' => lang('has_been_completed'), '4' => lang('refund_state_no')
  551. ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
  552. return $admin_array;
  553. }
  554. }
  555. }