Trade.php 8.1 KB

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