Memberinvoice.php 6.5 KB

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