trade.model.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 交易新模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class tradeModel extends Model{
  11. public function __construct() {
  12. parent::__construct();
  13. }
  14. /**
  15. * 订单处理天数
  16. *
  17. */
  18. public function getMaxDay($day_type = 'all') {
  19. $max_data = array(
  20. 'order_refund' => 15,//收货完成后可以申请退款退货
  21. 'refund_confirm' => 7,//卖家不处理退款退货申请时按同意处理
  22. 'return_confirm' => 7,//卖家不处理收货时按弃货处理
  23. 'return_delay' => 5//退货的商品发货多少天以后才可以选择没收到
  24. );
  25. if ($day_type == 'all') return $max_data;//返回所有
  26. if (intval($max_data[$day_type]) < 1) $max_data[$day_type] = 1;//最小的值设置为1
  27. return $max_data[$day_type];
  28. }
  29. /**
  30. * 订单状态
  31. *
  32. */
  33. public function getOrderState($type = 'all') {
  34. $state_data = array(
  35. 'order_cancel' => ORDER_STATE_CANCEL,//0:已取消
  36. 'order_default' => ORDER_STATE_NEW,//10:未付款
  37. 'order_paid' => ORDER_STATE_PAY,//20:已付款
  38. 'order_shipped' => ORDER_STATE_SEND,//30:已发货
  39. 'order_completed' => ORDER_STATE_SUCCESS //40:已收货
  40. );
  41. if ($type == 'all') return $state_data;//返回所有
  42. return $state_data[$type];
  43. }
  44. /**
  45. * 更新退款申请
  46. * @param int $member_id 会员编号
  47. * @param int $store_id 店铺编号
  48. */
  49. public function editRefundConfirm($member_id=0, $store_id=0) {
  50. $refund_confirm = $this->getMaxDay('refund_confirm');//卖家不处理退款申请时按同意并弃货处理
  51. $day = time()-$refund_confirm*60*60*24;
  52. $condition = " seller_state=1 and add_time<".$day;//状态:1为待审核,2为同意,3为不同意
  53. $condition_sql = "";
  54. if ($member_id > 0) {
  55. $condition_sql = " buyer_id = '".$member_id."' and ";
  56. }
  57. if ($store_id > 0) {
  58. $condition_sql = " store_id = '".$store_id."' and ";
  59. }
  60. $condition_sql = $condition_sql.$condition;
  61. $refund_array = array();
  62. $refund_array['refund_state'] = '2';//状态:1为处理中,2为待管理员处理,3为已完成
  63. $refund_array['seller_state'] = '2';//卖家处理状态:1为待审核,2为同意,3为不同意
  64. $refund_array['return_type'] = '1';//退货类型:1为不用退货,2为需要退货
  65. $refund_array['seller_time'] = time();
  66. $refund_array['seller_message'] = '超过'.$refund_confirm.'天未处理退款退货申请,按同意处理。';
  67. $refund = $this->table('refund_return')->field('refund_sn,store_id,order_lock,refund_type')->where($condition_sql)->select();
  68. $this->table('refund_return')->where($condition_sql)->update($refund_array);
  69. // 发送商家提醒
  70. foreach ((array)$refund as $val) {
  71. // 参数数组
  72. $param = array();
  73. $param['type'] = $val['order_lock'] == 2 ? '售前' : '售后';
  74. $param['refund_sn'] = $val['refund_sn'];
  75. if (intval($val['refund_type']) == 1) { // 退款
  76. $this->sendStoreMsg('refund_auto_process', $val['store_id'], $param);
  77. } else { // 退货
  78. $this->sendStoreMsg('return_auto_process', $val['store_id'], $param);
  79. }
  80. }
  81. $return_confirm = $this->getMaxDay('return_confirm');//卖家不处理收货时按弃货处理
  82. $day = time()-$return_confirm*60*60*24;
  83. $condition = " seller_state=2 and goods_state=2 and return_type=2 and delay_time<".$day;//物流状态:1为待发货,2为待收货,3为未收到,4为已收货
  84. $condition_sql = "";
  85. if ($member_id > 0) {
  86. $condition_sql = " buyer_id = '".$member_id."' and ";
  87. }
  88. if ($store_id > 0) {
  89. $condition_sql = " store_id = '".$store_id."' and ";
  90. }
  91. $condition_sql = $condition_sql.$condition;
  92. $refund_array = array();
  93. $refund_array['refund_state'] = '2';//状态:1为处理中,2为待管理员处理,3为已完成
  94. $refund_array['return_type'] = '1';//退货类型:1为不用退货,2为需要退货
  95. $refund_array['seller_message'] = '超过'.$return_confirm.'天未处理收货,按弃货处理';
  96. $refund = $this->table('refund_return')->field('refund_sn,store_id,order_lock,refund_type')->where($condition_sql)->select();
  97. $this->table('refund_return')->where($condition_sql)->update($refund_array);
  98. // 发送商家提醒
  99. foreach ((array)$refund as $val) {
  100. // 参数数组
  101. $param = array();
  102. $param['type'] = $val['order_lock'] == 2 ? '售前' : '售后';
  103. $param['refund_sn'] = $val['refund_sn'];
  104. $this->sendStoreMsg('return_auto_receipt', $val['store_id'], $param);
  105. }
  106. }
  107. /**
  108. * 发送店铺消息
  109. * @param string $code
  110. * @param int $store_id
  111. * @param array $param
  112. */
  113. private function sendStoreMsg($code, $store_id, $param) {
  114. QueueClient::push('sendStoreMsg', array('code' => $code, 'store_id' => $store_id, 'param' => $param));
  115. }
  116. }
  117. ?>