<?php namespace Xcx;
class Module extends \Xcx\Member
{
protected $form;
protected $_is_post;
protected $_is_edit;
protected $_is_delete;
public function __construct(...$params)
{
parent::__construct(...$params);
define('XCX_MID', \Phpcmf\Service::L('Router')->class);
$cache = \Phpcmf\Service::L('cache')->get('form-'.SITE_ID);
$this->form = $cache['xcx_'.APP_DIR.'_'.XCX_MID];
!$this->form && $this->_admin_msg(0, dr_lang('小程序模块【%s】不存在', XCX_MID));
$this->is_data = 1;
$this->tpl_prefix = XCX_MID.'_';
$this->tpl_name = $this->form['table'];
$this->name = dr_lang('小程序模块(%s)', $this->form['name']);
$sysfield = ['inputtime', 'displayorder'];
$this->_init([
'table' => SITE_ID.'_form_'.$this->form['table'],
'field' => $this->form['field'],
'sys_field' => $sysfield,
'date_field' => 'inputtime',
'show_field' => 'title',
'list_field' => $this->form['setting']['list_field'],
'order_by' => 'inputtime desc',
'where_list' => 'xid='.$this->xcx['id'],
]);
$this->edit_where = $this->delete_where = 'xid='.$this->xcx['id'];
if (!dr_member_auth(
$this->member_authid,
$this->member_cache['auth_site'][SITE_ID]['form'][$this->form['table']]['add'])
) {
$this->_is_post = 0;
} else {
$this->_is_post = 1;
}
if (!dr_member_auth(
$this->member_authid,
$this->member_cache['auth_site'][SITE_ID]['form'][$this->form['table']]['edit'])
) {
$this->_is_edit = 0;
} else {
$this->_is_edit = 1;
}
if (!dr_member_auth(
$this->member_authid,
$this->member_cache['auth_site'][SITE_ID]['form'][$this->form['table']]['del'])
) {
$this->_is_delete = 0;
} else {
$this->_is_delete = 1;
}
$this->is_post_code = dr_member_auth(
$this->member_authid,
$this->member_cache['auth_site'][SITE_ID]['form'][$this->form['table']]['code']
);
\Phpcmf\Service::V()->assign([
'cat' => \Phpcmf\Service::C()->_get_category(XCX_ID, XCX_MID),
'field' => $this->init['field'],
'form_list' => $cache,
'form_name' => $this->form['name'],
'form_table' => $this->form['table'],
'is_delete' => $this->_is_delete,
'is_post' => $this->_is_post,
'is_edit' => $this->_is_edit,
'is_post_code' => $this->is_post_code,
]);
}
public function add() {
list($tpl) = $this->_Post(0);
\Phpcmf\Service::V()->display($tpl);
}
public function edit() {
$id = intval(\Phpcmf\Service::L('input')->get('id'));
list($tpl, $data) = $this->_Post($id);
!$data && $this->_msg(0, dr_lang('数据不存在: '.$id));
\Phpcmf\Service::V()->display($tpl);
}
public function show() {
$id = intval(\Phpcmf\Service::L('input')->get('id'));
list($tpl, $data) = $this->_Show($id);
!$data && $this->_msg(0, dr_lang('数据不存在: '.$id));
\Phpcmf\Service::V()->display($tpl);
}
public function index() {
list($tpl) = $this->_List();
\Phpcmf\Service::V()->display($tpl);
}
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('form/'.$this->form['table'].'_verify/edit:id/'.$t['id'], SITE_ID);
\Phpcmf\Service::M('member')->delete_admin_notice('form/'.$this->form['table'].'/edit:id/'.$t['id'], SITE_ID);
\Phpcmf\Service::L('cache')->clear('from_'.$this->form['table'].'_show_id_'.$t['id']);
}
},
\Phpcmf\Service::M()->dbprefix($this->init['table'])
);
}
public function order() {
$this->_Display_Order(
intval(\Phpcmf\Service::L('input')->get('id')),
intval(\Phpcmf\Service::L('input')->get('value'))
);
}
protected function _Data($id = 0) {
$data = parent::_Data($id);
if ($data && $data['uid'] != $this->uid) {
return [];
}
return $data;
}
protected function _Format_Data($id, $data, $old) {
$data[1]['status'] = 1;
if (!$old) {
$day_post = $this->_member_value(
$this->member_authid,
$this->member_cache['auth_site'][SITE_ID]['form'][$this->form['table']]['day_post']
);
if ($day_post && \Phpcmf\Service::M()->db
->table($this->init['table'])
->where('uid', $this->uid)
->where('DATEDIFF(from_unixtime(inputtime),now())=0')
->countAllResults() >= $day_post) {
$this->_json(0, dr_lang('每天发布数量不能超过%s个', $day_post));
}
$total_post = $this->_member_value(
$this->member_authid,
$this->member_cache['auth_site'][SITE_ID]['form'][$this->form['table']]['total_post']
);
if ($total_post && \Phpcmf\Service::M()->db
->table($this->init['table'])
->where('uid', $this->uid)
->countAllResults() >= $total_post) {
$this->_json(0, dr_lang('发布数量不能超过%s个', $total_post));
}
$data[0]['uid'] = $data[1]['uid'] = (int)$this->member['uid'];
$data[1]['author'] = $this->member['username'];
$data[1]['inputip'] = \Phpcmf\Service::L('input')->ip_address();
$data[1]['xid'] = XCX_ID;
$data[1]['tableid'] = 0;
}
return $data;
}
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
return parent::_Save($id, $data, $old, null,
function ($id, $data, $old) {
if (!$old) {
}
$this->_json(1, dr_lang('操作成功'));
}
);
}
}