Memberinvoice.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Memberinvoice extends BaseMember {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinvoice.lang.php');
  20. }
  21. /*
  22. * 收货地址列表
  23. */
  24. public function index() {
  25. $invoice_model = model('invoice');
  26. $invoice_list = $invoice_model->getInvoiceList(array('member_id' => session('member_id')));
  27. View::assign('invoice_list', $invoice_list);
  28. /* 设置买家当前菜单 */
  29. $this->setMemberCurMenu('member_invoice');
  30. /* 设置买家当前栏目 */
  31. $this->setMemberCurItem('my_invoice');
  32. return View::fetch($this->template_dir . 'index');
  33. }
  34. private function get_data() {
  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. if (!request()->isPost()) {
  54. $invoice = $this->get_data();
  55. $invoice['invoice_state']=1;
  56. View::assign('invoice', $invoice);
  57. /* 设置买家当前菜单 */
  58. $this->setMemberCurMenu('member_invoice');
  59. /* 设置买家当前栏目 */
  60. $this->setMemberCurItem('my_invoice_add');
  61. return View::fetch($this->template_dir . 'form');
  62. } else {
  63. $data = $this->get_data();
  64. $data['member_id'] = session('member_id');
  65. $memberinvoice_validate = ds_validate('invoice');
  66. $scene='';
  67. if($data['invoice_state']==1){
  68. $scene = 'invoice_1_update';
  69. }else{
  70. $scene = 'invoice_2_update';
  71. }
  72. if (!$memberinvoice_validate->scene($scene)->check($data)) {
  73. ds_json_encode(10001, $memberinvoice_validate->getError());
  74. }
  75. $invoice_model = model('invoice');
  76. $result = $invoice_model->addInvoice($data);
  77. if ($result) {
  78. ds_json_encode(10000, lang('ds_common_save_succ'));
  79. } else {
  80. ds_json_encode(10001, lang('ds_common_save_fail'));
  81. }
  82. }
  83. }
  84. public function edit() {
  85. $invoice_id = intval(input('param.invoice_id'));
  86. if (0 >= $invoice_id) {
  87. ds_json_encode(10001, lang('param_error'));
  88. }
  89. $invoice_model = model('invoice');
  90. $invoice = $invoice_model->getInvoiceInfo(array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
  91. if (empty($invoice)) {
  92. ds_json_encode(10001, lang('invoice_does_not_exist'));
  93. }
  94. if (!request()->isPost()) {
  95. View::assign('invoice', $invoice);
  96. /* 设置买家当前菜单 */
  97. $this->setMemberCurMenu('member_invoice');
  98. /* 设置买家当前栏目 */
  99. $this->setMemberCurItem('my_invoice_edit');
  100. return View::fetch($this->template_dir . 'form');
  101. } else {
  102. $data = $this->get_data();
  103. $memberinvoice_validate = ds_validate('invoice');
  104. $scene='';
  105. if($data['invoice_state']==1){
  106. $scene = 'invoice_1_update';
  107. }else{
  108. $scene = 'invoice_2_update';
  109. }
  110. if (!$memberinvoice_validate->scene($scene)->check($data)) {
  111. ds_json_encode(10001, $memberinvoice_validate->getError());
  112. }
  113. $result = $invoice_model->editInvoice($data, array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
  114. if ($result) {
  115. ds_json_encode(10000, lang('ds_common_save_succ'));
  116. } else {
  117. ds_json_encode(10001, lang('ds_common_save_fail'));
  118. }
  119. }
  120. }
  121. public function drop() {
  122. $invoice_id = intval(input('param.invoice_id'));
  123. if (0 >= $invoice_id) {
  124. ds_json_encode(10001, lang('empty_error'));
  125. }
  126. $invoice_model = model('invoice');
  127. $result = $invoice_model->delInvoice(array('invoice_id' => $invoice_id,'member_id'=>session('member_id')));
  128. if ($result) {
  129. ds_json_encode(10000, lang('ds_common_del_succ'));
  130. } else {
  131. ds_json_encode(10001, lang('ds_common_del_fail'));
  132. }
  133. }
  134. /**
  135. * 栏目菜单
  136. */
  137. function getMemberItemList() {
  138. $item_list = array(
  139. array(
  140. 'name' => 'my_invoice',
  141. 'text' => lang('my_invoice'),
  142. 'url' => (string)url('Memberinvoice/index'),
  143. ),
  144. array(
  145. 'name' => 'my_invoice_add',
  146. 'text' => lang('new_invoice'),
  147. 'url' => (string)url('Memberinvoice/add'),
  148. ),
  149. );
  150. if (request()->action() == 'edit') {
  151. $item_list[] = array(
  152. 'name' => 'my_invoice_edit',
  153. 'text' => lang('edit_invoice'),
  154. 'url' => "javascript:void(0)",
  155. );
  156. }
  157. return $item_list;
  158. }
  159. }
  160. ?>