Trade.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 数据层模型
  13. */
  14. class Trade extends BaseModel {
  15. /**
  16. * 订单处理天数
  17. * @access public
  18. * @author csdeshang
  19. * @param type $day_type 天数类型
  20. * @return int
  21. */
  22. public function getMaxDay($day_type = 'all') {
  23. $max_data = array(
  24. 'order_refund' => 7, //收货完成后可以申请退款退货
  25. 'refund_confirm' => 7, //卖家不处理退款退货申请时按同意处理
  26. 'return_confirm' => 7, //卖家不处理收货时按弃货处理
  27. 'return_delay' => 5 //退货的商品发货多少天以后才可以选择没收到
  28. );
  29. if ($day_type == 'all')
  30. return $max_data; //返回所有
  31. if (intval($max_data[$day_type]) < 1)
  32. $max_data[$day_type] = 1; //最小的值设置为1
  33. return $max_data[$day_type];
  34. }
  35. /**
  36. * 订单状态
  37. * @access public
  38. * @author csdeshang
  39. * @param type $type 类型
  40. * @return type
  41. */
  42. public function getOrderState($type = 'all') {
  43. $state_data = array(
  44. 'order_cancel' => ORDER_STATE_CANCEL, //0:已取消
  45. 'order_default' => ORDER_STATE_NEW, //10:未付款
  46. 'order_paid' => ORDER_STATE_PAY, //20:已付款
  47. 'order_shipped' => ORDER_STATE_SEND, //30:已发货
  48. 'order_completed' => ORDER_STATE_SUCCESS //40:已收货
  49. );
  50. if ($type == 'all')
  51. return $state_data; //返回所有
  52. return $state_data[$type];
  53. }
  54. /**
  55. * 更新退款申请
  56. * @access public
  57. * @author csdeshang
  58. * @param int $member_id 会员编号
  59. * @param int $store_id 店铺编号
  60. * @return type
  61. */
  62. public function editRefundConfirm($member_id = 0, $store_id = 0) {
  63. $refund_confirm = $this->getMaxDay('refund_confirm'); //卖家不处理退款申请时按同意并弃货处理
  64. $day = TIMESTAMP - $refund_confirm * 60 * 60 * 24;
  65. $condition = " seller_state=1 and add_time<" . $day; //状态:1为待审核,2为同意,3为不同意
  66. $condition_sql = "";
  67. if ($member_id > 0) {
  68. $condition_sql = " buyer_id = '" . $member_id . "' and ";
  69. }
  70. if ($store_id > 0) {
  71. $condition_sql = " store_id = '" . $store_id . "' and ";
  72. }
  73. $condition_sql = $condition_sql . $condition;
  74. $refund_array = array();
  75. $refund_array['refund_state'] = '2'; //状态:1为处理中,2为待管理员处理,3为已完成
  76. $refund_array['seller_state'] = '2'; //卖家处理状态:1为待审核,2为同意,3为不同意
  77. $refund_array['return_type'] = '1'; //退货类型:1为不用退货,2为需要退货
  78. $refund_array['seller_time'] = TIMESTAMP;
  79. $refund_array['seller_message'] = '超过' . $refund_confirm . '天未处理退款退货申请,按同意处理。';
  80. $refund = Db::name('refundreturn')->field('refund_id,refund_sn,store_id,order_sn,refund_amount,order_lock,refund_type')->where($condition_sql)->select()->toArray();
  81. Db::name('refundreturn')->where($condition_sql)->update($refund_array);
  82. // 发送商家提醒
  83. foreach ((array) $refund as $val) {
  84. // 参数数组
  85. $message = array();
  86. $message['type'] = $val['order_lock'] == 2 ? '售前' : '售后';
  87. $message['refund_sn'] = $val['refund_sn'];
  88. $ten_message = array($message['type'],$message['refund_sn']);
  89. $weixin_param = array(
  90. 'url' => config('ds_config.h5_store_site_url').'/pages/seller/refund/RefundView?refund_id='.$val['refund_id'].'&refund_type='.$val['refund_type'],
  91. 'data'=>array(
  92. "keyword1" => array(
  93. "value" => $val['order_sn'],
  94. "color" => "#333"
  95. ),
  96. "keyword2" => array(
  97. "value" => $val['refund_amount'],
  98. "color" => "#333"
  99. )
  100. )
  101. );
  102. if (intval($val['refund_type']) == 1) {
  103. // 退款
  104. $this->sendStoremsg('refund_auto_process', $val['store_id'], $message,$weixin_param, $message,$ten_message);
  105. } else {
  106. // 退货
  107. $this->sendStoremsg('return_auto_process', $val['store_id'], $message,$weixin_param, $message,$ten_message);
  108. }
  109. }
  110. $return_confirm = $this->getMaxDay('return_confirm'); //卖家不处理收货时按弃货处理
  111. $day = TIMESTAMP - $return_confirm * 60 * 60 * 24;
  112. $condition = " seller_state=2 and goods_state=2 and return_type=2 and delay_time<" . $day; //物流状态:1为待发货,2为待收货,3为未收到,4为已收货
  113. $condition_sql = "";
  114. if ($member_id > 0) {
  115. $condition_sql = " buyer_id = '" . $member_id . "' and ";
  116. }
  117. if ($store_id > 0) {
  118. $condition_sql = " store_id = '" . $store_id . "' and ";
  119. }
  120. $condition_sql = $condition_sql . $condition;
  121. $refund_array = array();
  122. $refund_array['refund_state'] = '2'; //状态:1为处理中,2为待管理员处理,3为已完成
  123. $refund_array['return_type'] = '1'; //退货类型:1为不用退货,2为需要退货
  124. $refund_array['seller_message'] = '超过' . $return_confirm . '天未处理收货,按弃货处理';
  125. $refund = Db::name('refundreturn')->field('refund_id,refund_sn,store_id,order_sn,refund_amount,order_lock,refund_type')->where($condition_sql)->select()->toArray();
  126. Db::name('refundreturn')->where($condition_sql)->update($refund_array);
  127. // 发送商家提醒
  128. foreach ((array) $refund as $val) {
  129. // 参数数组
  130. $message = array();
  131. $message['type'] = $val['order_lock'] == 2 ? '售前' : '售后';
  132. $message['refund_sn'] = $val['refund_sn'];
  133. $ten_message=array($message['type'],$message['refund_sn']);
  134. $weixin_param = array(
  135. 'url' => config('ds_config.h5_store_site_url').'/pages/seller/refund/RefundView?refund_id='.$val['refund_id'].'&refund_type='.$val['refund_type'],
  136. 'data'=>array(
  137. "keyword1" => array(
  138. "value" => $val['order_sn'],
  139. "color" => "#333"
  140. ),
  141. "keyword2" => array(
  142. "value" => $val['refund_amount'],
  143. "color" => "#333"
  144. )
  145. )
  146. );
  147. $this->sendStoremsg('return_auto_receipt', $val['store_id'], $message,$weixin_param, $message,$ten_message);
  148. }
  149. }
  150. /**
  151. * 发送店铺消息
  152. * @access public
  153. * @author csdeshang
  154. * @param string $code 编码
  155. * @param int $store_id 店铺ID
  156. * @param array $message 消息
  157. */
  158. private function sendStoremsg($code, $store_id, $message,$weixin_param=array(),$ali_param=array(),$ten_param=array()) {
  159. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendStoremsg','cron_value'=>serialize(array('code' => $code, 'store_id' => $store_id, 'param' => $message,'weixin_param'=>$weixin_param,'ali_param'=>$ali_param,'ten_param'=>$ten_param))));
  160. }
  161. }