123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace app\common\model;
- use think\facade\Db;
- class Trade extends BaseModel {
-
- public function getMaxDay($day_type = 'all') {
- $max_data = array(
- 'order_refund' => 7,
- 'refund_confirm' => 7,
- 'return_confirm' => 7,
- 'return_delay' => 5
- );
- if ($day_type == 'all')
- return $max_data;
- if (intval($max_data[$day_type]) < 1)
- $max_data[$day_type] = 1;
- return $max_data[$day_type];
- }
-
- public function getOrderState($type = 'all') {
- $state_data = array(
- 'order_cancel' => ORDER_STATE_CANCEL,
- 'order_default' => ORDER_STATE_NEW,
- 'order_paid' => ORDER_STATE_PAY,
- 'order_shipped' => ORDER_STATE_SEND,
- 'order_completed' => ORDER_STATE_SUCCESS
- );
- if ($type == 'all')
- return $state_data;
- return $state_data[$type];
- }
-
- public function editRefundConfirm($member_id = 0, $store_id = 0) {
- $refund_confirm = $this->getMaxDay('refund_confirm');
- $day = TIMESTAMP - $refund_confirm * 60 * 60 * 24;
- $condition = " seller_state=1 and add_time<" . $day;
- $condition_sql = "";
- if ($member_id > 0) {
- $condition_sql = " buyer_id = '" . $member_id . "' and ";
- }
- if ($store_id > 0) {
- $condition_sql = " store_id = '" . $store_id . "' and ";
- }
- $condition_sql = $condition_sql . $condition;
- $refund_array = array();
- $refund_array['refund_state'] = '2';
- $refund_array['seller_state'] = '2';
- $refund_array['return_type'] = '1';
- $refund_array['seller_time'] = TIMESTAMP;
- $refund_array['seller_message'] = '超过' . $refund_confirm . '天未处理退款退货申请,按同意处理。';
- $refund = Db::name('refundreturn')->field('refund_id,refund_sn,store_id,order_sn,refund_amount,order_lock,refund_type')->where($condition_sql)->select()->toArray();
- Db::name('refundreturn')->where($condition_sql)->update($refund_array);
-
- foreach ((array) $refund as $val) {
-
- $message = array();
- $message['type'] = $val['order_lock'] == 2 ? '售前' : '售后';
- $message['refund_sn'] = $val['refund_sn'];
- $ten_message = array($message['type'],$message['refund_sn']);
- $weixin_param = array(
- 'url' => config('ds_config.h5_store_site_url').'/pages/seller/refund/RefundView?refund_id='.$val['refund_id'].'&refund_type='.$val['refund_type'],
- 'data'=>array(
- "keyword1" => array(
- "value" => $val['order_sn'],
- "color" => "#333"
- ),
- "keyword2" => array(
- "value" => $val['refund_amount'],
- "color" => "#333"
- )
- )
- );
- if (intval($val['refund_type']) == 1) {
- $this->sendStoremsg('refund_auto_process', $val['store_id'], $message,$weixin_param, $message,$ten_message);
- } else {
- $this->sendStoremsg('return_auto_process', $val['store_id'], $message,$weixin_param, $message,$ten_message);
- }
- }
- $return_confirm = $this->getMaxDay('return_confirm');
- $day = TIMESTAMP - $return_confirm * 60 * 60 * 24;
- $condition = " seller_state=2 and goods_state=2 and return_type=2 and delay_time<" . $day;
- $condition_sql = "";
- if ($member_id > 0) {
- $condition_sql = " buyer_id = '" . $member_id . "' and ";
- }
- if ($store_id > 0) {
- $condition_sql = " store_id = '" . $store_id . "' and ";
- }
- $condition_sql = $condition_sql . $condition;
- $refund_array = array();
- $refund_array['refund_state'] = '2';
- $refund_array['return_type'] = '1';
- $refund_array['seller_message'] = '超过' . $return_confirm . '天未处理收货,按弃货处理';
- $refund = Db::name('refundreturn')->field('refund_id,refund_sn,store_id,order_sn,refund_amount,order_lock,refund_type')->where($condition_sql)->select()->toArray();
- Db::name('refundreturn')->where($condition_sql)->update($refund_array);
-
- foreach ((array) $refund as $val) {
-
- $message = array();
- $message['type'] = $val['order_lock'] == 2 ? '售前' : '售后';
- $message['refund_sn'] = $val['refund_sn'];
- $ten_message=array($message['type'],$message['refund_sn']);
- $weixin_param = array(
- 'url' => config('ds_config.h5_store_site_url').'/pages/seller/refund/RefundView?refund_id='.$val['refund_id'].'&refund_type='.$val['refund_type'],
- 'data'=>array(
- "keyword1" => array(
- "value" => $val['order_sn'],
- "color" => "#333"
- ),
- "keyword2" => array(
- "value" => $val['refund_amount'],
- "color" => "#333"
- )
- )
- );
- $this->sendStoremsg('return_auto_receipt', $val['store_id'], $message,$weixin_param, $message,$ten_message);
- }
- }
-
- private function sendStoremsg($code, $store_id, $message,$weixin_param=array(),$ali_param=array(),$ten_param=array()) {
- 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))));
- }
- }
- ?>
|