order_helper.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/9/28
  6. * Time: 上午12:09
  7. */
  8. class order_helper
  9. {
  10. private $mOrders;
  11. private $mod_refund;
  12. private $mod_order;
  13. public function __construct($order_list)
  14. {
  15. $this->mOrders = $order_list;
  16. $this->mod_order = Model('order');
  17. $this->mod_refund = Model('refund_return');
  18. }
  19. private function action_title($key)
  20. {
  21. static $actions = array("if_cancel" => "取消订单",
  22. "if_refund_cancel" => "退款",
  23. "if_receive" => "确认收货",
  24. "if_deliver" => "查看物流",
  25. "if_evaluation" => "评价",
  26. "if_delete" => "删除订单",
  27. "if_refund_return" => "退货");
  28. return $actions[$key];
  29. }
  30. private function actions($order)
  31. {
  32. //显示取消订单
  33. $state['if_cancel'] = $this->mod_order->getOrderOperateState('buyer_cancel', $order);
  34. //显示退款取消订单
  35. $state['if_refund_cancel'] = $this->mod_order->getOrderOperateState('refund_cancel', $order);
  36. //显示收货
  37. $state['if_receive'] = $this->mod_order->getOrderOperateState('receive', $order);
  38. //显示物流跟踪
  39. $state['if_deliver'] = $this->mod_order->getOrderOperateState('deliver', $order);
  40. //显示评价
  41. $state['if_evaluation'] = $this->mod_order->getOrderOperateState('evaluation', $order);
  42. //显示删除
  43. $state['if_delete'] = $this->mod_order->getOrderOperateState('delete', $order);
  44. //订单是否能退货
  45. $state['if_refund_return'] = $this->mod_refund->getRefundState($order) == '0' ? false : true;
  46. $actions = [];
  47. foreach ($state as $key => $value) {
  48. if ($value == true) {
  49. $actions['action'] = $key;
  50. $actions['title'] = $this->action_title($key);
  51. }
  52. }
  53. return $actions;
  54. }
  55. private function order_info($order)
  56. {
  57. $result["order_id"] = intval($order["order_id"]);
  58. $result["order_sn"] = $order["order_sn"];
  59. $result["pay_sn"] = $order["pay_sn"];
  60. $result["add_time"] = intval($order["add_time"]);
  61. $result["payment_code"] = $order["payment_code"];
  62. $result["payment_time"] = intval($order["payment_time"]);
  63. $result["finnshed_time"] = intval($order["finnshed_time"]);
  64. $result["goods_amount"] = doubleval($order["goods_amount"]);
  65. $result["order_amount"] = doubleval($order["order_amount"]);
  66. $result["rcb_amount"] = doubleval($order["rcb_amount"]);
  67. $result["pd_amount"] = doubleval($order["pd_amount"]);
  68. $result["shipping_fee"] = doubleval($order["shipping_fee"]);
  69. $result["evaluation_state"] = intval($order["evaluation_state"]);
  70. $result["order_state"] = intval($order["order_state"]);
  71. $result["refund_state"] = intval($order["refund_state"]);
  72. $result["refund_amount"] = doubleval($order["refund_amount"]);
  73. $result["delay_time"] = intval($order["delay_time"]);
  74. $result["shipping_code"] = $order["shipping_code"];
  75. $result["trade_no"] = $order["trade_no"];
  76. $result["state_desc"] = $order["state_desc"];
  77. $refund_state = 0;
  78. $order['refund_id'] = intval($this->mod_refund->getRefundId($order,$refund_state));
  79. $result["refund_state"] = intval($refund_state);
  80. return $result;
  81. }
  82. private function order_goods($order)
  83. {
  84. $result = [];
  85. $order_goods = $order['extend_order_goods'];
  86. foreach ($order_goods as $val)
  87. {
  88. $goods["rec_id"] = intval($val["rec_id"]);
  89. $goods["order_id"] = intval($val["order_id"]);
  90. $goods["goods_id"] = intval($val["goods_id"]);
  91. $goods["goods_name"] = $val["goods_name"];
  92. $goods["goods_price"] = doubleval($val["goods_price"]);
  93. $goods["goods_num"] = intval($val["goods_num"]);
  94. $goods["goods_image"] = cthumb($val['goods_image'], 480, $val['store_id']);
  95. $goods["goods_pay_price"] = doubleval($val["goods_pay_price"]);
  96. $goods["store_id"] = intval($val["store_id"]);
  97. $goods["buyer_id"] = intval($val["buyer_id"]);
  98. $goods["goods_type"] = intval($val["goods_type"]);
  99. $goods["promotions_id"] = intval($val["promotions_id"]);
  100. $goods["gc_id"] = intval($val["gc_id"]);
  101. $goods["goods_spec"] = $val["goods_spec"];
  102. $refund_state = 0;
  103. $goods['refund_id'] = intval($this->mod_refund->getRefundIdForGood($val,$refund_state));
  104. $goods['refund_state'] = intval($refund_state);
  105. $result[] = $goods;
  106. }
  107. return $result;
  108. }
  109. private function reciver_info($order)
  110. {
  111. $info = $order['reciver_info'];
  112. $info['reciver_name'] = $order['reciver_name'];
  113. return $info;
  114. }
  115. public function format()
  116. {
  117. $result = [];
  118. foreach ($this->mOrders as $order) {
  119. $item['order_info'] = $this->order_info($order);
  120. $actions = $this->actions($order);
  121. $item['actions'] = $actions;
  122. $item['order_goods'] = $this->order_goods($order);
  123. $item['reciver_info'] = $this->reciver_info($order);
  124. $result[] = $item;
  125. }
  126. return $result;
  127. }
  128. }