Memberinvoice.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Memberinvoice extends BaseMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinvoice.lang.php');
  18. }
  19. /*
  20. * 收货地址列表
  21. */
  22. public function index()
  23. {
  24. $invoice_model = model('invoice');
  25. $invoice_list = $invoice_model->getInvoiceList(array('member_id' => session('member_id')));
  26. View::assign('invoice_list', $invoice_list);
  27. /* 设置买家当前菜单 */
  28. $this->setMemberCurMenu('member_invoice');
  29. /* 设置买家当前栏目 */
  30. $this->setMemberCurItem('my_invoice');
  31. return View::fetch($this->template_dir . 'index');
  32. }
  33. private function get_data()
  34. {
  35. $data = array();
  36. $data['invoice_state'] = input('post.invoice_state');
  37. $data['invoice_title'] = input('post.invoice_title');
  38. $data['invoice_content'] = input('post.invoice_content');
  39. $data['invoice_code'] = input('post.invoice_code');
  40. $data['invoice_company'] = input('post.invoice_company');
  41. $data['invoice_company_code'] = input('post.invoice_company_code');
  42. $data['invoice_reg_addr'] = input('post.invoice_reg_addr');
  43. $data['invoice_reg_phone'] = input('post.invoice_reg_phone');
  44. $data['invoice_reg_bname'] = input('post.invoice_reg_bname');
  45. $data['invoice_reg_baccount'] = input('post.invoice_reg_baccount');
  46. // $data['invoice_rec_name'] = input('post.invoice_rec_name');
  47. // $data['invoice_rec_mobphone'] = input('post.invoice_rec_mobphone');
  48. // $data['invoice_rec_province'] = input('post.area_info');
  49. // $data['invoice_goto_addr'] = input('post.invoice_goto_addr');
  50. return $data;
  51. }
  52. public function add()
  53. {
  54. if (!request()->isPost()) {
  55. $invoice = $this->get_data();
  56. $invoice['invoice_state'] = 1;
  57. View::assign('invoice', $invoice);
  58. /* 设置买家当前菜单 */
  59. $this->setMemberCurMenu('member_invoice');
  60. /* 设置买家当前栏目 */
  61. $this->setMemberCurItem('my_invoice_add');
  62. return View::fetch($this->template_dir . 'form');
  63. } else {
  64. $data = $this->get_data();
  65. $data['member_id'] = session('member_id');
  66. $memberinvoice_validate = ds_validate('invoice');
  67. $scene = '';
  68. if ($data['invoice_state'] == 1) {
  69. $scene = 'invoice_1_update';
  70. } else {
  71. $scene = 'invoice_2_update';
  72. }
  73. if (!$memberinvoice_validate->scene($scene)->check($data)) {
  74. ds_json_encode(10001, $memberinvoice_validate->getError());
  75. }
  76. $invoice_model = model('invoice');
  77. $result = $invoice_model->addInvoice($data);
  78. if ($result) {
  79. ds_json_encode(10000, lang('ds_common_save_succ'));
  80. } else {
  81. ds_json_encode(10001, lang('ds_common_save_fail'));
  82. }
  83. }
  84. }
  85. public function edit()
  86. {
  87. $invoice_id = intval(input('param.invoice_id'));
  88. if (0 >= $invoice_id) {
  89. ds_json_encode(10001, lang('param_error'));
  90. }
  91. $invoice_model = model('invoice');
  92. $invoice = $invoice_model->getInvoiceInfo(array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
  93. if (empty($invoice)) {
  94. ds_json_encode(10001, lang('invoice_does_not_exist'));
  95. }
  96. if (!request()->isPost()) {
  97. View::assign('invoice', $invoice);
  98. /* 设置买家当前菜单 */
  99. $this->setMemberCurMenu('member_invoice');
  100. /* 设置买家当前栏目 */
  101. $this->setMemberCurItem('my_invoice_edit');
  102. return View::fetch($this->template_dir . 'form');
  103. } else {
  104. $data = $this->get_data();
  105. $memberinvoice_validate = ds_validate('invoice');
  106. $scene = '';
  107. if ($data['invoice_state'] == 1) {
  108. $scene = 'invoice_1_update';
  109. } else {
  110. $scene = 'invoice_2_update';
  111. }
  112. if (!$memberinvoice_validate->scene($scene)->check($data)) {
  113. ds_json_encode(10001, $memberinvoice_validate->getError());
  114. }
  115. $result = $invoice_model->editInvoice($data, array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
  116. if ($result) {
  117. ds_json_encode(10000, lang('ds_common_save_succ'));
  118. } else {
  119. ds_json_encode(10001, lang('ds_common_save_fail'));
  120. }
  121. }
  122. }
  123. public function drop()
  124. {
  125. $invoice_id = intval(input('param.invoice_id'));
  126. if (0 >= $invoice_id) {
  127. ds_json_encode(10001, lang('empty_error'));
  128. }
  129. $invoice_model = model('invoice');
  130. $result = $invoice_model->delInvoice(array('invoice_id' => $invoice_id, 'member_id' => session('member_id')));
  131. if ($result) {
  132. ds_json_encode(10000, lang('ds_common_del_succ'));
  133. } else {
  134. ds_json_encode(10001, lang('ds_common_del_fail'));
  135. }
  136. }
  137. /**
  138. * 栏目菜单
  139. */
  140. function getMemberItemList()
  141. {
  142. $item_list = array(
  143. array(
  144. 'name' => 'my_invoice',
  145. 'text' => lang('my_invoice'),
  146. 'url' => (string)url('Memberinvoice/index'),
  147. ),
  148. array(
  149. 'name' => 'my_invoice_add',
  150. 'text' => lang('new_invoice'),
  151. 'url' => (string)url('Memberinvoice/add'),
  152. ),
  153. );
  154. if (request()->action() == 'edit') {
  155. $item_list[] = array(
  156. 'name' => 'my_invoice_edit',
  157. 'text' => lang('edit_invoice'),
  158. 'url' => "javascript:void(0)",
  159. );
  160. }
  161. return $item_list;
  162. }
  163. }