<?php namespace Phpcmf\Controllers\Admin;
class Shipping extends \Phpcmf\Table
{
public function __construct(...$params)
{
parent::__construct(...$params);
$this->name = dr_lang('运费策略');
$this->is_data = 0;
$this->tpl_prefix = 'shipping_';
$this->_init([
'table' => SITE_ID.'_store_shipping',
'order_by' => 'id asc',
]);
\Phpcmf\Service::V()->assign([
'menu' => \Phpcmf\Service::M('Auth')->_admin_menu(
[
'运费策略' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-ambulance'],
'添加' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
]
),
'valuation_type' => \Phpcmf\Service::M('Mall', 'store')->get_valuation(),
]);
}
public function index() {
list($tpl) = $this->_List([], -1);
\Phpcmf\Service::V()->display($tpl);
}
public function add() {
list($tpl) = $this->_Post(0);
$freight_id = $free_id = 0;
\Phpcmf\Service::V()->assign([
'free_id' => $free_id,
'valuation' => 1,
'freight_id' => $freight_id,
]);
\Phpcmf\Service::V()->display($tpl);
}
public function edit() {
list($tpl, $data) = $this->_Post(intval(\Phpcmf\Service::L('Input')->get('id')));
\Phpcmf\Service::V()->assign([
'free_id' => count($data['free']),
'freight_id' => count($data['freight']),
]);
\Phpcmf\Service::V()->display($tpl);
}
public function city_index() {
if (IS_AJAX_POST) {
$city = (int)$_POST['data']['city'];
!$city && $this->_json(0, dr_lang('全国地区'));
$this->_json($city, dr_linkagepos(FC_ADDRESS_CITY, $city, ' » '));
exit;
}
\Phpcmf\Service::V()->assign('city', dr_fieldform([
'fieldname' => 'city',
'fieldtype' => 'Linkage',
'setting' => [ 'option' => [ 'linkage' => FC_ADDRESS_CITY, ], ]
]));
\Phpcmf\Service::V()->display('shipping_city.html');exit;
}
public function del() {
$this->_Del(
\Phpcmf\Service::L('Input')->get_post_ids(),
null,
null,
\Phpcmf\Service::M()->dbprefix($this->init['table'])
);
}
protected function _Data($id = 0) {
$row = parent::_Data($id);
if ($row) {
$row['freight'] = dr_string2array($row['freight']);
$row['free'] = dr_string2array($row['free']);
}
return $row;
}
protected function _Format_Data($id, $data, $old) {
$data['freight'] = dr_array2string($data['freight']);
$data['free'] = dr_array2string($data['free']);
return $data;
}
}