123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Memberinvoice extends BaseMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinvoice.lang.php');
- }
- /*
- * 收货地址列表
- */
- public function index()
- {
- $invoice_model = model('invoice');
- $invoice_list = $invoice_model->getInvoiceList(array('member_id' => session('member_id')));
- View::assign('invoice_list', $invoice_list);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_invoice');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('my_invoice');
- return View::fetch($this->template_dir . 'index');
- }
- private function get_data()
- {
- $data = array();
- $data['invoice_state'] = input('post.invoice_state');
- $data['invoice_title'] = input('post.invoice_title');
- $data['invoice_content'] = input('post.invoice_content');
- $data['invoice_code'] = input('post.invoice_code');
- $data['invoice_company'] = input('post.invoice_company');
- $data['invoice_company_code'] = input('post.invoice_company_code');
- $data['invoice_reg_addr'] = input('post.invoice_reg_addr');
- $data['invoice_reg_phone'] = input('post.invoice_reg_phone');
- $data['invoice_reg_bname'] = input('post.invoice_reg_bname');
- $data['invoice_reg_baccount'] = input('post.invoice_reg_baccount');
- // $data['invoice_rec_name'] = input('post.invoice_rec_name');
- // $data['invoice_rec_mobphone'] = input('post.invoice_rec_mobphone');
- // $data['invoice_rec_province'] = input('post.area_info');
- // $data['invoice_goto_addr'] = input('post.invoice_goto_addr');
- return $data;
- }
- public function add()
- {
- if (!request()->isPost()) {
- $invoice = $this->get_data();
- $invoice['invoice_state'] = 1;
- View::assign('invoice', $invoice);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_invoice');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('my_invoice_add');
- return View::fetch($this->template_dir . 'form');
- } else {
- $data = $this->get_data();
- $data['member_id'] = session('member_id');
- $memberinvoice_validate = ds_validate('invoice');
- $scene = '';
- if ($data['invoice_state'] == 1) {
- $scene = 'invoice_1_update';
- } else {
- $scene = 'invoice_2_update';
- }
- if (!$memberinvoice_validate->scene($scene)->check($data)) {
- ds_json_encode(10001, $memberinvoice_validate->getError());
- }
- $invoice_model = model('invoice');
- $result = $invoice_model->addInvoice($data);
- if ($result) {
- ds_json_encode(10000, lang('ds_common_save_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_save_fail'));
- }
- }
- }
- public function edit()
- {
- $invoice_id = intval(input('param.invoice_id'));
- if (0 >= $invoice_id) {
- ds_json_encode(10001, lang('param_error'));
- }
- $invoice_model = model('invoice');
- $invoice = $invoice_model->getInvoiceInfo(array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
- if (empty($invoice)) {
- ds_json_encode(10001, lang('invoice_does_not_exist'));
- }
- if (!request()->isPost()) {
- View::assign('invoice', $invoice);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_invoice');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('my_invoice_edit');
- return View::fetch($this->template_dir . 'form');
- } else {
- $data = $this->get_data();
- $memberinvoice_validate = ds_validate('invoice');
- $scene = '';
- if ($data['invoice_state'] == 1) {
- $scene = 'invoice_1_update';
- } else {
- $scene = 'invoice_2_update';
- }
- if (!$memberinvoice_validate->scene($scene)->check($data)) {
- ds_json_encode(10001, $memberinvoice_validate->getError());
- }
- $result = $invoice_model->editInvoice($data, array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
- if ($result) {
- ds_json_encode(10000, lang('ds_common_save_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_save_fail'));
- }
- }
- }
- public function drop()
- {
- $invoice_id = intval(input('param.invoice_id'));
- if (0 >= $invoice_id) {
- ds_json_encode(10001, lang('empty_error'));
- }
- $invoice_model = model('invoice');
- $result = $invoice_model->delInvoice(array('invoice_id' => $invoice_id, 'member_id' => session('member_id')));
- if ($result) {
- ds_json_encode(10000, lang('ds_common_del_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- }
- }
- /**
- * 栏目菜单
- */
- function getMemberItemList()
- {
- $item_list = array(
- array(
- 'name' => 'my_invoice',
- 'text' => lang('my_invoice'),
- 'url' => (string)url('Memberinvoice/index'),
- ),
- array(
- 'name' => 'my_invoice_add',
- 'text' => lang('new_invoice'),
- 'url' => (string)url('Memberinvoice/add'),
- ),
- );
- if (request()->action() == 'edit') {
- $item_list[] = array(
- 'name' => 'my_invoice_edit',
- 'text' => lang('edit_invoice'),
- 'url' => "javascript:void(0)",
- );
- }
- return $item_list;
- }
- }
|