<?php namespace Phpcmf\Controllers\Member;
class Service extends \Phpcmf\Table {
public function index() {
$type = [
0 => [
'name' => dr_lang('全部'),
'url' => dr_member_url('store/service/index', ['tid' => 0]),
],
];
$otype = dr_store_order_service_type();
foreach ($otype as $i => $t) {
$type[$i] = [
'name' => $t,
'url' => dr_member_url('store/service/index', ['tid' => $i]),
];
}
$tid = (int)$_GET['tid'];
$where = $tid ? '`uid`='.$this->uid.' AND `type` = '.$tid : '`uid`='.$this->uid;
$this->my_field = array(
'title' => array(
'ismain' => 1,
'name' => dr_lang('商品'),
'fieldname' => 'title',
'fieldtype' => 'Text',
),
'remark' => array(
'ismain' => 1,
'name' => dr_lang('说明'),
'fieldname' => 'remark',
'fieldtype' => 'Text',
),
);
$this->_init([
'table' => SITE_ID.'_store_order_service',
'field' => $this->my_field,
'order_by' => 'inputtime desc',
'date_field' => 'inputtime',
'where_list' => $where,
]);
$this->_List(['tid' => $tid]);
\Phpcmf\Service::V()->assign([
'type' => $type,
'field' => $this->my_field,
]);
\Phpcmf\Service::V()->display('service_list.html');
}
public function show() {
$id = (int)\Phpcmf\Service::L('input')->get('id');
$service = \Phpcmf\Service::M('Order', 'store')->service_id($id);
!$service && $this->_msg(0, dr_lang('售后订单不存在'));
$service['uid'] != $this->uid && $this->_msg(0, dr_lang('无权限查看此订单'));
$order = \Phpcmf\Service::M('Order', 'store')->info($service['oid']);
!$order && $this->_msg(0, dr_lang('订单不存在'));
if (IS_POST) {
if ($service['status'] == 2) {
$post = \Phpcmf\Service::L('input')->post('data',true);
!$post['kdmc'] && $this->_json(0, dr_lang('快递名称必须填写'));
$rt = \Phpcmf\Service::M()->table_site('order_service')->update($id, [
'status' => 5,
'myinfo' => dr_array2string($post),
]);
!$rt['code'] && $this->_json(0, $rt['msg']);
} else {
$this->_json(0, dr_lang('状态异常'));
}
$this->_json(1, dr_lang('提交成功,等待平台处理'), [
'url' => dr_member_url('store/service/show', ['id' => $id]),
]);
}
\Phpcmf\Service::V()->assign([
'item' => $service,
'order' => $order,
'delivery' => \Phpcmf\Service::M('Order', 'store')->service_deliver_info($service['system']['id']),
]);
\Phpcmf\Service::V()->display('service_show.html');
}
public function order() {
$id = (int)\Phpcmf\Service::L('input')->get('id');
$order = \Phpcmf\Service::M('Order', 'store')->info($id);
!$order && $this->_msg(0, dr_lang('订单不存在'));
$order['uid'] != $this->uid && $this->_msg(0, dr_lang('无权限查看此订单'));
!$order['status'] && $this->_msg(0, dr_lang('该订单状态不支持售后'));
$goods = \Phpcmf\Service::M('Order', 'store')->goods($id);
!$goods && $this->_msg(0, dr_lang('此订单无可用商品'));
foreach ($goods as $i => $item) {
$goods[$i]['service'] = \Phpcmf\Service::M('Order', 'store')->service($item['id']);
}
\Phpcmf\Service::V()->assign([
'order' => $order,
'goods' => $goods,
]);
\Phpcmf\Service::V()->display('service_order.html');
}
public function add() {
$id = (int)\Phpcmf\Service::L('input')->get('id');
$oid = (int)\Phpcmf\Service::L('input')->get('oid');
$type = (int)\Phpcmf\Service::L('input')->get('type');
$item = \Phpcmf\Service::M('Order', 'store')->item($id);
if (!$item) {
$this->_msg(0, dr_lang('订单商品不存在'));
} elseif ($item['uid'] != $this->uid) {
$this->_msg(0, dr_lang('无权限查看此订单'));
}
$order = \Phpcmf\Service::M('Order', 'store')->info($oid);
if (!$order) {
$this->_msg(0, dr_lang('订单不存在'));
} elseif (!$order['status']) {
$this->_msg(0, dr_lang('该订单状态不支持售后'));
}
if ($this->mall_info['order']['service_endtime']) {
if ($order['receipt_time']) {
$etime = $order['receipt_time'] + (int)$this->mall_info['order']['service_endtime'] * 3600 * 24;
if ($etime < SYS_TIME) {
$this->_msg(0, dr_lang('已经超过售后申请的时间'));
}
}
}
$service = \Phpcmf\Service::M('Order', 'store')->service($item['id']);
if ($service) {
IS_POST && $this->_json(0, dr_lang('已经提交过申请'));
$url = dr_member_url('store/service/show', ['id'=>$service['id']]);
dr_redirect($url);exit;
}
$images = [
'ismain' => 1,
'fieldtype' => 'Files',
'fieldname' => 'images',
'setting' => array(
'option' => array(
'ext' => 'jpg,png,jpeg,gif',
'input' => 1,
'size' => 10,
'count' => 5,
),
)
];
if (IS_POST) {
$post = \Phpcmf\Service::L('input')->post('data', true);
!$post['remark'] && $this->_json(0, dr_lang('申请理由未填写'));
$image = [];
if ($post['images']) {
$attach = [
'del' => [],
'add' => []
]; #用于附件UI当
foreach ($post['images']['title'] as $fid => $title) {
$image['file'][$fid] = $post['images']['id'][$fid] ? $post['images']['id'][$fid] : $post['images']['file'][$fid];
$image['title'][$fid] = $title;
}
$attach['add'] = dr_array2array($attach['add'], $post['images']['id']);
}
$rt = \Phpcmf\Service::M('Order', 'store')->post_service($item, [
'type' => $type,
'remark' => $post['remark'],
'images' => $image,
'sn' => $order['sn'],
]);
if ($image) {
SYS_ATTACHMENT_DB && $attach && \Phpcmf\Service::M('Attachment')->handle(
$this->member['id'],
\Phpcmf\Service::M()->dbprefix(SITE_ID.'_store_order_service').'-'.$rt['code'],
$attach
);
}
$this->_json(1, dr_lang('提交成功,等待平台处理'), [
'url' => dr_member_url('store/service/show', ['id' => $rt['code']]),
]);
}
\Phpcmf\Service::V()->assign([
'item' => $item,
'type' => $type,
'order' => $order,
'type_name' => dr_store_order_service_type($type),
'images_field' => dr_field_form($images, ''),
]);
\Phpcmf\Service::V()->display('service_add.html');
}
}