<?php namespace Phpcmf\Controllers\Admin;
class Service extends \Phpcmf\Table {
public function __construct(...$params)
{
parent::__construct(...$params);
$this->name = dr_lang('售后服务');
$this->my_field = array(
'sn' => array(
'ismain' => 1,
'name' => dr_lang('订单'),
'fieldname' => 'sn',
'fieldtype' => 'Text',
),
'title' => array(
'ismain' => 1,
'name' => dr_lang('商品'),
'fieldname' => 'title',
'fieldtype' => 'Text',
),
'username' => array(
'ismain' => 1,
'name' => dr_lang('账户'),
'fieldname' => 'username',
'fieldtype' => 'Text',
),
'uid' => array(
'ismain' => 1,
'name' => dr_lang('uid'),
'fieldname' => 'uid',
'fieldtype' => 'Text',
),
);
$this->_init([
'table' => SITE_ID.'_store_order_service',
'field' => $this->my_field,
'order_by' => 'inputtime desc',
'date_field' => 'inputtime',
]);
\Phpcmf\Service::V()->assign([
'menu' => \Phpcmf\Service::M('Auth')->_admin_menu(
[
'售后服务' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-user-md'],
'详情' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
]
),
'field' => $this->my_field,
]);
}
public function index() {
$this->_List();
\Phpcmf\Service::V()->display('service_list.html');
}
public function edit() {
$id = (int)\Phpcmf\Service::L('input')->get('id');
list($tpl, $data) = $this->_Show($id);
!$data && $this->_admin_msg(0, dr_lang('售后订单不存在'));
$order = \Phpcmf\Service::M('Order', 'store')->info($data['oid']);
!$order && $this->_admin_msg(0, dr_lang('订单不存在'));
$data['images'] = dr_string2array($data['images']);
$data['system'] = dr_string2array($data['system']);
$data['myinfo'] = dr_string2array($data['myinfo']);
if (IS_POST) {
$data['status'] == 3 && $this->_json(0, dr_lang('本订单已完成'));
$post = \Phpcmf\Service::L('input')->post('data',true);
$system = \Phpcmf\Service::L('input')->post('system',true);
$status = (int)\Phpcmf\Service::L('input')->post('status');
!$status && $this->_json(0, dr_lang('请选择处理状态'));
$post['status'] = $data['status'];
switch ($data['type']) {
case 1:
if ($status == 1) {
$post['status'] = 3;
$this->_tuikuan($post['money'], $data);
} else {
$post['status'] = 4;
}
break;
case 2:
if ($data['status'] == 5 || $data['myinfo']['kdmc']) {
if ($status == 1) {
$post['status'] = 3;
$this->_tuikuan($post['money'], $data);
} else {
$post['status'] = 4;
}
} else {
if ($status == 1) {
$post['status'] = 2;
} else {
$post['status'] = 4;
}
}
break;
case 3:
if ($data['status'] == 5 || $data['myinfo']['kdmc']) {
if ($status == 1) {
$post['status'] = 3;
} else {
$post['status'] = 4;
}
} else {
if ($status == 1) {
$post['status'] = 2;
} else {
$post['status'] = 4;
}
}
break;
}
$rt = \Phpcmf\Service::M()->table_site('store_order_service')->update($id, [
'status' => $post['status'],
'sysnote' => $post['sysnote'],
'money' => $post['money'],
'system' => dr_array2string($system),
]);
!$rt['code'] && $this->_json(0, $rt['msg']);
\Phpcmf\Service::M('member')->delete_admin_notice('store/service/edit:id/'.$id, SITE_ID);
if (in_array($post['status'], [2,3,4])) {
$data['status'] = $post['status'];
$data['sysnote'] = $post['sysnote'];
$data['money'] = $post['money'];
$data['system'] = $system;
\Phpcmf\Service::L('Notice')->send_notice('store_service_status_'.$post['status'], $data);
}
$this->_json(1, dr_lang('操作成功'));
}
\Phpcmf\Service::V()->assign([
'item' => $data,
'order' => $order,
'delivery_corp' => \Phpcmf\Service::M('Order', 'store')->get_delivery_corp(),
'address' => $data['system']['address'] ? $data['system']['address'] : $this->mall_info['order']['tui_address'],
]);
\Phpcmf\Service::V()->display('service_edit.html');
}
private function _tuikuan($value, $item) {
if ($value > 0) {
$rt = \Phpcmf\Service::M('Pay')->add_money($item['uid'], $value);
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $item['uid'],
'username' => $item['username'],
'touid' => '0',
'tousername' => '',
'mid' => 'order',
'title' => dr_lang('商品['.$item['title'].']退款成功'),
'value' => $value,
'type' => 'system',
'status' => 1,
'result' => '订单编号:'.$item['sn'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
$item['money'] = $value;
\Phpcmf\Service::L('Notice')->send_notice('store_service_tuikuan', $item);
}
}
public function del() {
$this->_Del(\Phpcmf\Service::L('Input')->get_post_ids(), null, function($rows) {
foreach ($rows as $t) {
\Phpcmf\Service::M('member')->delete_admin_notice('store/service/edit:id/'.$t['id'], SITE_ID);
}
return dr_return_data(1, 'ok');
});
}
}