Memberrefund.php 29 KB

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