Trade.php 8.0 KB

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