order_helper.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/9/28
  6. * Time: 上午12:09
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
  9. class refund_item
  10. {
  11. const REFUND_MONEY = 1;
  12. const RETURN_GOODS = 2;
  13. static $seller_state = array(1 => "待审核",2 => "同意", 3 => "不同意");
  14. static $refund_state = array(1 => "处理中",2 => "待管理员处理", 3 => "已完成");
  15. static $refund_type = array(1 => "退款",2 => "退货");
  16. static $return_type = array(1 => "不用退货",2 => "需要退货");
  17. static $order_goods_type = array(1 => "普通商品",2 => "团购商品",3 => "限时折扣商品",4 => "组合套装");
  18. static $goods_state = array(1 => "待发货",2 => "待收货",3 => "未收到",4 => "已收货");
  19. static $payments = array('bonus' => "红包支付","predeposit" => "红包支付","online" => "在线支付",
  20. "alipay" => "支付宝",'wxpay' => "微信支付",'cmbpay' => "一网通支付");
  21. public function __construct()
  22. {
  23. }
  24. static public function get_price($goods_info,$order_id,$goods_id,&$price,&$spec)
  25. {
  26. $price = 0.00;
  27. $spec = "";
  28. if($goods_id <= 0 || $order_id <= 0) {
  29. return false;
  30. }
  31. else
  32. {
  33. if(isset($goods_info[$order_id]))
  34. {
  35. $order_goods = $goods_info[$order_id];
  36. if(isset($order_goods[$goods_id])) {
  37. $goods = $order_goods[$goods_id];
  38. $price = doubleval($goods['goods_price']);
  39. $spec = $goods['goods_spec'];
  40. if(empty($spec)) $spec = "";
  41. }
  42. }
  43. }
  44. }
  45. static public function get_payment($order_infos,$order_id)
  46. {
  47. if($order_id <= 0) {
  48. return "";
  49. }
  50. else
  51. {
  52. if(isset($order_infos[$order_id]))
  53. {
  54. $order = $order_infos[$order_id];
  55. if(isset($order['payment_code'])) {
  56. return self::$payments[$order['payment_code']];
  57. }
  58. }
  59. }
  60. return "";
  61. }
  62. static public function format($info,$goods_info,$order_infos)
  63. {
  64. $result['refund_id'] = intval($info['refund_id']);
  65. $result['order_id'] = intval($info['order_id']);
  66. $result['order_sn'] = $info['order_sn'];
  67. $result['refund_sn'] = $info['refund_sn'];
  68. $result['refund_amount'] = doubleval($info['refund_amount']);
  69. $result['refund_step'] = self::refund_step($info);
  70. $result['refund_type'] = intval($info['refund_type']);
  71. $result['refund_type_desc'] = self::$refund_type[intval($info['refund_type'])];
  72. $result['add_time'] = intval($info['add_time']);
  73. $result['goods_name'] = empty($info['goods_name']) ? "" : $info['goods_name'];
  74. $image = empty($info['goods_image']) ? "" : $info['goods_image'];
  75. $result['goods_image'] = cthumb($image, 480, $info['store_id']);
  76. $result['goods_id'] = intval($info['goods_id']);
  77. $result['rec_id'] = intval($info['order_goods_id']);
  78. $result['goods_num'] = intval($info['goods_num']);
  79. $result['order_goods_type'] = self::$order_goods_type[intval($info['order_goods_type'])];
  80. $result['goods_state'] = self::$goods_state[intval($info['goods_state'])];
  81. self::get_price($goods_info,$result['order_id'],$result['goods_id'],$price,$spec);
  82. $result['goods_price'] = $price;
  83. $result['goods_spec'] = $spec;
  84. $result['payment_desc'] = self::get_payment($order_infos,$result['order_id']);
  85. $result['seller_state'] = self::$seller_state[intval($info['seller_state'])];
  86. $result['refund_state'] = self::$refund_state[intval($info['refund_state'])];
  87. $result['buyer_message'] = empty($info['buyer_message']) ? "" : $info['buyer_message'];
  88. $result['seller_message'] = empty($info['seller_message']) ? "" : $info['seller_message'];
  89. $result['admin_message'] = empty($info['admin_message']) ? "" : $info['admin_message'];
  90. //$result['return_type'] = intval($info['return_type']); //'退货类型:1为不用退货,2为需要退货,默认为1'
  91. //$result['order_lock'] = intval($info['order_lock']); //'订单锁定类型:1为不用锁定,2为需要锁定,默认为1',
  92. //$result['seller_time'] = intval($info['seller_time']);
  93. //$result['admin_time'] = intval($info['admin_time']);
  94. //$result['ship_time'] = intval($info['ship_time']);
  95. //$result['reason_id'] = intval($info['reason_id']);
  96. $result['shipping_code'] = empty($info['invoice_no']) ? "" : $info['invoice_no']; //物流编码
  97. $result['express_id'] = intval($info['express_id']);
  98. $result['delay_time'] = intval($info['delay_time']);
  99. $result['receive_time'] = intval($info['receive_time']);
  100. $result['receive_message'] = empty($info['receive_message']) ? "" : $info['receive_message'];
  101. $result['reason_info'] = empty($info['reason_info']) ? "" : $info['reason_info'];
  102. return $result;
  103. }
  104. private static function refund_step($info)
  105. {
  106. $state = 1;
  107. $type = intval($info['refund_type']);
  108. $seller_time = intval($info['seller_time']);
  109. $admin_time = intval($info['admin_time']);
  110. $ship_time = intval($info['ship_time']);
  111. $return_type = intval($info['return_type']);
  112. if($type == self::REFUND_MONEY)
  113. {
  114. if($seller_time > 0) {
  115. $state = 2;
  116. }
  117. if($admin_time > 0) {
  118. $state = 3;
  119. }
  120. }
  121. else if($type == self::RETURN_GOODS)
  122. {
  123. if($seller_time > 0) {
  124. $state = 2;
  125. }
  126. if($ship_time > 0 || $return_type == 1) {
  127. $state = 3;
  128. }
  129. if($admin_time > 0) {
  130. $state = 4;
  131. }
  132. }
  133. else
  134. {
  135. }
  136. return $state;
  137. }
  138. }
  139. class refund_helper
  140. {
  141. private $member_id;
  142. public function __construct($member_id)
  143. {
  144. $this->member_id = intval($member_id);
  145. }
  146. private function format($refund_list,$goods_info,$order_infos)
  147. {
  148. $result = [];
  149. foreach ($refund_list as $item) {
  150. $result[] = refund_item::format($item,$goods_info,$order_infos);
  151. }
  152. return $result;
  153. }
  154. private function goods_info($refund_list,&$order_infos)
  155. {
  156. $ids = [];
  157. foreach ($refund_list as $item) {
  158. $ids[] = intval($item['order_id']);
  159. }
  160. if(empty($ids)) return false;
  161. $model_order = Model('order');
  162. $order_list = $model_order->getNormalOrderList(array('order_id' => array('in',$ids)), $this->page_size, '*', 'order_id desc', '', array('order_goods'));
  163. $order_infos = [];
  164. $result = [];
  165. foreach ($order_list as $order)
  166. {
  167. $order_id = intval($order['order_id']);
  168. $order_goods = $order['extend_order_goods'];
  169. $ex_goods = [];
  170. foreach ($order_goods as $goods) {
  171. $goods_id = intval($goods['goods_id']);
  172. $ex_goods[$goods_id] = $goods;
  173. }
  174. $result[$order_id] = $ex_goods;
  175. $order_infos[$order_id]['payment_code'] = $order['payment_code'];
  176. }
  177. return $result;
  178. }
  179. public function list_all($page,&$total_page)
  180. {
  181. $model_refund = Model('refund_return');
  182. $condition = array();
  183. $condition['buyer_id'] = $this->member_id;
  184. $refund_list = $model_refund->getRefundReturnList($condition,$page);
  185. $total_page = $model_refund->gettotalpage();
  186. $goods_info = $this->goods_info($refund_list,$order_infos);
  187. return $this->format($refund_list,$goods_info,$order_infos);
  188. }
  189. public function view($refund_id,&$err)
  190. {
  191. $model_refund = Model('refund_return');
  192. $return_list = $model_refund->getRefundReturnList(array('buyer_id' => $this->member_id,'refund_id' => $refund_id));
  193. if(empty($return_list)) {
  194. $err = array('code' => errcode::ErrRefundNotExist,'msg' => '无此退款信息.');
  195. return false;
  196. }
  197. $goods_info = $this->goods_info($return_list,$order_infos);
  198. $refunds = $this->format($return_list,$goods_info,$order_infos);
  199. return $refunds[0];
  200. }
  201. public function ship($refund_id,$express_id,$invoice_no,&$err)
  202. {
  203. $model_refund = Model('refund_return');
  204. $condition = array();
  205. $condition['buyer_id'] = $this->member_id;
  206. $condition['refund_id'] = $refund_id;
  207. $return_list = $model_refund->getReturnList($condition);
  208. if(empty($return_list)) {
  209. $err = array('code' => errcode::ErrOrderRefundError,'msg' => "无此退款信息");
  210. return false;
  211. }
  212. $return = $return_list[0];
  213. if ($return['seller_state'] != '2' || $return['goods_state'] != '1') {
  214. $err = array('code' => errcode::ErrFrequentlyRequest,'msg' => "该申请已发货");
  215. return false;
  216. }
  217. $refund_array = array();
  218. $refund_array['ship_time'] = time();
  219. $refund_array['delay_time'] = time();
  220. $refund_array['express_id'] = $express_id;
  221. $refund_array['invoice_no'] = $invoice_no;
  222. $refund_array['goods_state'] = '2';
  223. $state = $model_refund->editRefundReturn($condition, $refund_array);
  224. if ($state) {
  225. return true;
  226. } else {
  227. $err = array('code' => errcode::ErrOrderRefundError,'msg' => "发货失败");
  228. return false;
  229. }
  230. }
  231. public function refund($order_sn,&$err)
  232. {
  233. $order_info = Model('order')->getOrderInfo(array('order_sn' => $order_sn));
  234. if (empty($order_info)) {
  235. $err = array("code" => errcode::ErrOrderNotExist,'msg' => errcode::msg(errcode::ErrOrderNotExist));
  236. return false;
  237. }
  238. $model_refund = Model('refund_return');
  239. $order_id = intval($order_info['order_id']);
  240. $order = $model_refund->getRightOrderList(array('buyer_id' => $this->member_id, 'order_id' => $order_id));
  241. $order_amount = $order['order_amount'];//订单金额
  242. $pd_amount = $order['pd_amount'];
  243. $order_amount -= $pd_amount;
  244. $condition = array();
  245. {
  246. $condition['buyer_id'] = $order['buyer_id'];
  247. $condition['order_id'] = $order['order_id'];
  248. $condition['goods_id'] = '0';
  249. $condition['seller_state'] = array('lt', '3'); //状态:1为待审核,2为同意,3为不同意
  250. }
  251. $refund_list = $model_refund->getRefundReturnList($condition);
  252. $refund = array();
  253. if (!empty($refund_list) && is_array($refund_list)) {
  254. $refund = $refund_list[0];
  255. }
  256. $model_trade = Model('trade');
  257. $order_paid = $model_trade->getOrderState('order_paid');
  258. $payment_code = $order['payment_code'];
  259. if ($refund['refund_id'] > 0 || $order['order_state'] != $order_paid || $payment_code == 'offline') {
  260. $err = array("code" => errcode::ErrOrderNotExist,'msg' => "只有付完款尚未发货的时才能退款。");
  261. return false;
  262. }
  263. $refund_array = array();
  264. $refund_array['refund_type'] = '1'; //类型:1为退款,2为退货
  265. $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
  266. $refund_array['order_lock'] = '2'; //锁定类型:1为不用锁定,2为需要锁定
  267. $refund_array['goods_id'] = '0';
  268. $refund_array['order_goods_id'] = '0';
  269. $refund_array['reason_id'] = '0';
  270. $refund_array['reason_info'] = '取消订单,全部退款';
  271. $refund_array['goods_name'] = '订单商品全部退款';
  272. $refund_array['refund_amount'] = ncPriceFormat($order_amount);
  273. $refund_array['buyer_message'] = remove_tags(urldecode($_POST['buyer_message']));
  274. $refund_array['add_time'] = time();
  275. $pic_array = array();
  276. $pic_array['buyer'] = array();
  277. $refund_array['pic_info'] = serialize($pic_array);
  278. $refund_id = $model_refund->addRefundReturn($refund_array, $order);
  279. if ($refund_id) {
  280. $model_refund->editOrderLock($order_id);
  281. return $refund_id;
  282. } else {
  283. $err = array("code" => errcode::ErrOrderRefundError, 'msg' => "退款失败.");
  284. return false;
  285. }
  286. }
  287. private function reason_list($model_refund)
  288. {
  289. $condition = array();
  290. $reason_data = $model_refund->getReasonList($condition, '', '', 'reason_id,reason_info');
  291. $reason_list = [];
  292. foreach ($reason_data as $data) {
  293. $reason_list[] = $data;
  294. }
  295. $reason_list[] = array('reason_id' => 0, 'reason_info' => '其他');
  296. return $reason_list;
  297. }
  298. private function reason_info($model_refund,$reason_id)
  299. {
  300. $reason_list = $this->reason_list($model_refund);
  301. $reasons = [];
  302. foreach ($reason_list as $data) {
  303. $reason_id = intval($data['reason_id']);
  304. $reason_info = $data['reason_info'];
  305. $reasons[$reason_id] = $reason_info;
  306. }
  307. if (isset($reasons[$reason_id])) {
  308. return $reasons[$reason_id];
  309. } else {
  310. return '其他';
  311. }
  312. }
  313. public function return_info($order_sn,$rec_id,&$err)
  314. {
  315. $order_info = Model('order')->getOrderInfo(array('order_sn' => $order_sn));
  316. if (empty($order_info)) {
  317. $err = array("code" => errcode::ErrOrderNotExist,'msg' => errcode::msg(errcode::ErrOrderNotExist));
  318. return false;
  319. }
  320. $order_id = intval($order_info['order_id']);
  321. if ($order_id < 1 || $rec_id < 1) {
  322. $err = array("code" => errcode::ErrParamter,'msg' => errcode::msg(errcode::ErrParamter));
  323. return false;
  324. }
  325. $model_refund = Model('refund_return');
  326. $reason_list = $this->reason_list($model_refund);
  327. $condition = array();
  328. $condition['buyer_id'] = $this->member_id;
  329. $condition['order_id'] = $order_id;
  330. $order = $model_refund->getRightOrderList($condition, $rec_id);
  331. $order_amount = $order['order_amount'];//订单金额
  332. $order_refund_amount = $order['refund_amount'];//订单退款金额
  333. $goods_list = $order['goods_list'];
  334. $goods = $goods_list[0];
  335. $goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
  336. if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
  337. $goods_pay_price = $order_amount - $order_refund_amount;
  338. $goods['goods_pay_price'] = $goods_pay_price;
  339. }
  340. $condition = array();
  341. $condition['buyer_id'] = $order['buyer_id'];
  342. $condition['order_id'] = $order['order_id'];
  343. $condition['order_goods_id'] = $rec_id;
  344. $condition['seller_state'] = array('lt', '3');
  345. $refund_list = $model_refund->getRefundReturnList($condition);
  346. $refund = array();
  347. if (!empty($refund_list) && is_array($refund_list)) {
  348. $refund = $refund_list[0];
  349. }
  350. $refund_state = $model_refund->getRefundState($order);//根据订单状态判断是否可以退款退货 '申请状态:1为处理中,2为待管理员处理,3为已完成,默认为1',
  351. if ($refund['refund_id'] > 0) {
  352. $err = array("code" => errcode::ErrOrderRefundError,'msg' => "不能重复退货");
  353. return false;
  354. }
  355. if ($refund_state != 1) {
  356. $err = array("code" => errcode::ErrOrderState,'msg' => '请确认订单状态,在已经付款后才能退款,已经发货后才能退货.');
  357. return false;
  358. }
  359. return array('reason_list' => (array)$reason_list, 'goods' => $goods);
  360. }
  361. public function return_goods($order_sn,$rec_id,$goods_num,$refund_amount,$reason_id,$buyer_msg,&$err)
  362. {
  363. $order_info = Model('order')->getOrderInfo(array('order_sn' => $order_sn));
  364. if (empty($order_info) || intval($order_info['order_id'] < 1)) {
  365. $err = array("code" => errcode::ErrOrderNotExist,'msg' => errcode::msg(errcode::ErrOrderNotExist));
  366. return false;
  367. }
  368. $order_id = intval($order_info['order_id']);
  369. $model_refund = Model('refund_return');
  370. $reson_info = $this->reason_info($model_refund,$reason_id);
  371. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  372. $condition = array();
  373. $condition['buyer_id'] = $this->member_id;
  374. $condition['order_id'] = $order_id;
  375. $order = $model_refund->getRightOrderList($condition, $rec_id);
  376. $order_id = $order['order_id'];
  377. $order_amount = $order['order_amount'];//订单金额
  378. $order_refund_amount = $order['refund_amount'];//订单退款金额
  379. $goods_list = $order['goods_list'];
  380. $goods = $goods_list[0];
  381. $goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
  382. if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
  383. $goods_pay_price = $order_amount - $order_refund_amount;
  384. $goods['goods_pay_price'] = $goods_pay_price;
  385. }
  386. $goods_id = $goods['rec_id'];
  387. $condition = array();
  388. $condition['buyer_id'] = $order['buyer_id'];
  389. $condition['order_id'] = $order['order_id'];
  390. $condition['order_goods_id'] = $goods_id;
  391. $condition['seller_state'] = array('lt', '3');
  392. $refund_list = $model_refund->getRefundReturnList($condition);
  393. $refund = array();
  394. if (!empty($refund_list) && is_array($refund_list)) {
  395. $refund = $refund_list[0];
  396. }
  397. $refund_state = $model_refund->getRefundState($order);
  398. if ($refund['refund_id'] > 0 || $refund_state != 1) {
  399. $err = array("code" => errcode::ErrOrderState,'msg' => errcode::msg(errcode::ErrOrderState));
  400. return false;
  401. }
  402. $refund_array = array();
  403. if (($refund_amount < 0) || ($refund_amount > $goods_pay_price)) {
  404. $refund_amount = $goods_pay_price;
  405. }
  406. if (($goods_num < 0) || ($goods_num > $goods['goods_num'])) {
  407. $goods_num = 1;
  408. }
  409. $refund_array['reason_info'] = $reson_info;
  410. $refund_array['reason_id'] = $reason_id;
  411. $refund_array['pic_info'] = serialize(array('buyer' => array()));
  412. $model_trade = Model('trade');
  413. $order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
  414. if ($order['order_state'] == $order_shipped) {
  415. $refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
  416. }
  417. $refund_array['refund_type'] = 2;//类型:1为退款,2为退货
  418. $refund_array['return_type'] = '2';//退货类型:1为不用退货,2为需要退货
  419. if ($refund_array['refund_type'] != '2') {
  420. $refund_array['refund_type'] = '1';
  421. $refund_array['return_type'] = '1';
  422. }
  423. $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
  424. $refund_array['refund_amount'] = ncPriceFormat($refund_amount);
  425. $refund_array['goods_num'] = $goods_num;
  426. $refund_array['buyer_message'] = $buyer_msg;
  427. $refund_array['add_time'] = time();
  428. $refund_id = $model_refund->addRefundReturn($refund_array, $order, $goods);
  429. if ($refund_id)
  430. {
  431. if ($order['order_state'] == $order_shipped) {
  432. $model_refund->editOrderLock($order_id);
  433. }
  434. return true;
  435. }
  436. else {
  437. $err = array("code" => errcode::ErrOrderRefundError,'msg' => "退货失败");
  438. return false;
  439. }
  440. }
  441. }
  442. class order_action
  443. {
  444. public function change_state($state_type,$order_id)
  445. {
  446. $model_order = Model('order');
  447. $condition = array();
  448. $condition['order_id'] = $order_id;
  449. $condition['buyer_id'] = $_SESSION['member_id'];
  450. $order_info = $model_order->getOrderInfo($condition);
  451. if($state_type == 'order_cancel') {
  452. $result = $this->order_cancel($order_info);
  453. } else if ($state_type == 'order_receive') {
  454. $result = $this->order_receive($order_info);
  455. } else if (in_array($state_type,array('order_delete','order_drop','order_restore'))){
  456. $result = $this->order_recycle($order_info, $state_type);
  457. } else {
  458. return false;
  459. }
  460. return $result['state'];
  461. }
  462. private function order_cancel($order_info)
  463. {
  464. $model_order = Model('order');
  465. $logic_order = Logic('order');
  466. $if_allow = $model_order->getOrderOperateState('buyer_cancel',$order_info);
  467. if (!$if_allow) {
  468. return callback(false,'无权操作');
  469. }
  470. return $logic_order->changeOrderStateCancel($order_info,'buyer', $_SESSION['member_name']);
  471. }
  472. private function order_receive($order_info)
  473. {
  474. $model_order = Model('order');
  475. $logic_order = Logic('order');
  476. $if_allow = $model_order->getOrderOperateState('receive',$order_info);
  477. if (!$if_allow) {
  478. return callback(false,'无权操作');
  479. }
  480. return $logic_order->changeOrderStateReceive($order_info,'buyer',$_SESSION['member_name']);
  481. }
  482. private function order_recycle($order_info, $state_type) {
  483. $model_order = Model('order');
  484. $logic_order = Logic('order');
  485. $state_type = str_replace(array('order_delete','order_drop','order_restore'), array('delete','drop','restore'), $state_type);
  486. $if_allow = $model_order->getOrderOperateState($state_type,$order_info);
  487. if (!$if_allow) {
  488. return callback(false,'无权操作');
  489. }
  490. return $logic_order->changeOrderStateRecycle($order_info,'buyer',$state_type);
  491. }
  492. }
  493. class order_helper
  494. {
  495. private $mOrders;
  496. private $mod_refund;
  497. private $mod_order;
  498. public function __construct($order_list)
  499. {
  500. $this->mod_order = Model('order');
  501. $this->mod_refund = Model('refund_return');
  502. $this->mOrders = $this->mod_refund->getGoodsRefundList($order_list);
  503. }
  504. private function action_title($key)
  505. {
  506. static $actions = array("if_cancel" => "取消订单",
  507. "if_refund_cancel" => "退款",
  508. "if_payment" => "立即支付",
  509. "if_receive" => "确认收货",
  510. "if_deliver" => "查看物流",
  511. "if_evaluation" => "评价赚红包",
  512. "if_delete" => "删除订单",
  513. "if_lock" => "退款退货中");
  514. return $actions[$key];
  515. }
  516. private function actions($order)
  517. {
  518. $state['if_payment'] = $this->mod_order->getOrderOperateState('payment',$order);
  519. //显示取消订单
  520. $state['if_cancel'] = $this->mod_order->getOrderOperateState('buyer_cancel', $order);
  521. //显示退款取消订单
  522. $state['if_refund_cancel'] = $this->mod_order->getOrderOperateState('refund_cancel', $order);
  523. //显示收货
  524. $state['if_receive'] = $this->mod_order->getOrderOperateState('receive', $order);
  525. //显示物流跟踪
  526. $state['if_deliver'] = $this->mod_order->getOrderOperateState('deliver', $order);
  527. //显示评价
  528. $state['if_evaluation'] = $this->mod_order->getOrderOperateState('evaluation', $order);
  529. //显示删除
  530. $state['if_delete'] = $this->mod_order->getOrderOperateState('delete', $order);
  531. $state['if_lock'] = $this->mod_order->getOrderOperateState('lock', $order);
  532. $actions = [];
  533. foreach ($state as $key => $value) {
  534. if ($value == true) {
  535. $item['action'] = $key;
  536. $item['title'] = $this->action_title($key);
  537. $actions[] = $item;
  538. }
  539. }
  540. return $actions;
  541. }
  542. private function payment_desc($payment_code)
  543. {
  544. static $payments = array('bonus' => "红包支付","predeposit" => "红包支付","online" => "在线支付",
  545. "alipay" => "支付宝",'wxpay' => "微信支付",'cmbpay' => "一网通银行卡支付");
  546. if(isset($payments[$payment_code])) {
  547. return $payments[$payment_code];
  548. } else {
  549. return "";
  550. }
  551. }
  552. private function order_info($order)
  553. {
  554. $result["order_id"] = intval($order["order_id"]);
  555. $result["order_sn"] = $order["order_sn"];
  556. $result["pay_sn"] = $order["pay_sn"];
  557. $result["add_time"] = intval($order["add_time"]);
  558. $result["payment_code"] = $order["payment_code"];
  559. $result["payment_desc"] = $this->payment_desc($order["payment_code"]);
  560. $result["payment_time"] = intval($order["payment_time"]);
  561. $result["finnshed_time"] = intval($order["finnshed_time"]);
  562. $result["goods_amount"] = $this->goods_amount($order);//doubleval($order["goods_amount"]);
  563. $result["order_amount"] = doubleval($order["order_amount"]);
  564. $result["rcb_amount"] = doubleval($order["rcb_amount"]);
  565. $result["pd_amount"] = doubleval($order["pd_amount"]);
  566. $result['bonus_rates'] = $this->formate_rates(unserialize($order["bonus_rate"]),doubleval($order["pd_amount"]));
  567. $result["shipping_fee"] = doubleval($order["shipping_fee"]);
  568. $result["evaluation_state"] = intval($order["evaluation_state"]);
  569. $result["order_state"] = intval($order["order_state"]);
  570. $result["refund_state"] = intval($order["refund_state"]);
  571. $result["refund_amount"] = doubleval($order["refund_amount"]);
  572. $result["delay_time"] = intval($order["delay_time"]);
  573. $result["shipping_code"] = empty($order["shipping_code"]) ? "" : $order["shipping_code"];
  574. $result["trade_no"] = $order["trade_no"];
  575. $result["state_desc"] = $order["state_desc"];
  576. $result['pay_cash'] = $result["order_amount"] - $result["pd_amount"];
  577. $result['full_discount'] = $result["goods_amount"] - $order["goods_amount"];
  578. $result['full_desc'] = $this->full_desc($order);
  579. if ($result['order_state'] == ORDER_STATE_NEW) {
  580. $result['cancel_time'] = $result['add_time'] + ORDER_AUTO_CANCEL_DAY * 24 * 3600;
  581. } else {
  582. $result['cancel_time'] = 0;
  583. }
  584. $refund_state = 0;
  585. $order['refund_id'] = intval($this->mod_refund->getRefundId($order,$refund_state));
  586. $result["refund_state"] = intval($refund_state);
  587. return $result;
  588. }
  589. private function formate_rates($rates,$pd_amount)
  590. {
  591. $result = [];
  592. if(empty($rates))
  593. {
  594. if(intval($pd_amount * 100 + 0.5) > 0) {
  595. $item['rate'] = 30;
  596. $item['total'] = $pd_amount;
  597. $result[] = $item;
  598. } else {
  599. return null;
  600. }
  601. }
  602. else
  603. {
  604. foreach ($rates as $rate => $val) {
  605. $item['rate'] = $rate;
  606. $item['total'] = $val;
  607. $result[] = $item;
  608. }
  609. }
  610. return $result;
  611. }
  612. private function full_desc($order)
  613. {
  614. $order_info = $order['extend_order_common'];
  615. $info = '';
  616. if(isset($order_info['promotion_info']))
  617. {
  618. $info = $order_info['promotion_info'];
  619. $ret = preg_match('#(.*?)<a.*?title=("|\')(.*?)\2.*?>.*?</a>#s',$info,$matches);
  620. if($ret != false && count($matches) == 4) {
  621. $info = $matches[1] . $matches[3];
  622. }
  623. }
  624. return (is_null($info) || empty($info)) ? "" : $info;
  625. }
  626. private function goods_amount($order)
  627. {
  628. $goods_amount = doubleval($order['goods_amount']);
  629. $goods_list = $order['extend_order_goods'];
  630. if(empty($goods_list) || !is_array($goods_list)) {
  631. return $goods_amount;
  632. } else {
  633. $goods_amount = 0.00;
  634. }
  635. foreach ($goods_list as $goods) {
  636. $goods_amount += doubleval($goods['goods_price']) * intval($goods['goods_num']);
  637. }
  638. return $goods_amount;
  639. }
  640. private function order_goods($order)
  641. {
  642. $result = [];
  643. $order_goods = $order['extend_order_goods'];
  644. foreach ($order_goods as $val)
  645. {
  646. $goods["rec_id"] = intval($val["rec_id"]);
  647. $goods["order_id"] = intval($val["order_id"]);
  648. $goods["goods_id"] = intval($val["goods_id"]);
  649. $commonid = goods_helper::common_id($goods["goods_id"]);
  650. if($commonid == false) {
  651. continue;
  652. }
  653. $goods["goods_commonid"] = $commonid;
  654. $goods["goods_name"] = $val["goods_name"];
  655. $goods["goods_price"] = doubleval($val["goods_price"]);
  656. $goods["goods_num"] = intval($val["goods_num"]);
  657. $goods["goods_image"] = cthumb($val['goods_image'], 480, $val['store_id']);
  658. $goods["goods_pay_price"] = doubleval($val["goods_pay_price"]);
  659. $goods["store_id"] = intval($val["store_id"]);
  660. $goods["buyer_id"] = intval($val["buyer_id"]);
  661. $goods["goods_type"] = intval($val["goods_type"]);
  662. $goods["type_desc"] = $this->type_desc($goods["goods_type"]);
  663. $goods["promotions_id"] = intval($val["promotions_id"]);
  664. $goods["gc_id"] = intval($val["gc_id"]);
  665. $goods["goods_spec"] = $val["goods_spec"] == null ? "" : $val["goods_spec"];
  666. $goods["refund"] = isset($val["refund"]) ? intval($val["refund"]) : 0;
  667. $refund_state = 0;
  668. $goods['refund_id'] = intval($this->mod_refund->getRefundIdForGood($val,$refund_state));
  669. $goods['refund_state'] = intval($refund_state);
  670. $result[] = $goods;
  671. }
  672. return $result;
  673. }
  674. private function type_desc($goods_type)
  675. {
  676. $descs = array(1 => "普通商品",2 => "抢购", 3 => "限购", 4 => "套装", 5 => "赠品");
  677. if($goods_type > 0 && $goods_type <= count($descs)) {
  678. return $descs[$goods_type];
  679. } else {
  680. return "";
  681. }
  682. }
  683. private function reciver_info($order)
  684. {
  685. $info = $order['reciver_info'];
  686. $info['reciver_name'] = $order['reciver_name'];
  687. return $info;
  688. }
  689. private function invoice_info($order)
  690. {
  691. $result = [];
  692. $result['inv_content'] = "";
  693. $result['inv_title'] = "";
  694. $result['inv_id'] = 0;
  695. if(isset($order['extend_order_common']))
  696. {
  697. $order_common = $order['extend_order_common'];
  698. if(isset($order_common['invoice_info']))
  699. {
  700. $invoice_info = $order_common['invoice_info'];
  701. foreach ($invoice_info as $key => $value)
  702. {
  703. if($key == '内容') {
  704. $result['inv_content'] = $value;
  705. }
  706. elseif($key == '抬头') {
  707. $item['inv_title'] = $value;
  708. }
  709. }
  710. }
  711. }
  712. return $result;
  713. }
  714. public function format()
  715. {
  716. $result = [];
  717. foreach ($this->mOrders as $order) {
  718. $item['order_info'] = $this->order_info($order);
  719. $actions = $this->actions($order);
  720. $item['actions'] = $actions;
  721. $order_goods = $this->order_goods($order);
  722. if($order_goods == false) {
  723. continue;
  724. }
  725. $item['order_goods'] = $order_goods;
  726. $item['reciver_info'] = $this->reciver_info($order);
  727. $item['invoice_info'] = $this->invoice_info($order);
  728. $result[] = $item;
  729. }
  730. return $result;
  731. }
  732. }