Memberinvoice.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Memberinvoice extends BaseMember {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinvoice.lang.php');
  21. }
  22. /*
  23. * 收货地址列表
  24. */
  25. public function index() {
  26. $invoice_model = model('invoice');
  27. $invoice_list = $invoice_model->getInvoiceList(array('member_id' => session('member_id')));
  28. View::assign('invoice_list', $invoice_list);
  29. /* 设置买家当前菜单 */
  30. $this->setMemberCurMenu('member_invoice');
  31. /* 设置买家当前栏目 */
  32. $this->setMemberCurItem('my_invoice');
  33. return View::fetch($this->template_dir . 'index');
  34. }
  35. private function get_data() {
  36. $data = array();
  37. $data['invoice_state'] = input('post.invoice_state');
  38. $data['invoice_title'] = input('post.invoice_title');
  39. $data['invoice_content'] = input('post.invoice_content');
  40. $data['invoice_code'] = input('post.invoice_code');
  41. $data['invoice_company'] = input('post.invoice_company');
  42. $data['invoice_company_code'] = input('post.invoice_company_code');
  43. $data['invoice_reg_addr'] = input('post.invoice_reg_addr');
  44. $data['invoice_reg_phone'] = input('post.invoice_reg_phone');
  45. $data['invoice_reg_bname'] = input('post.invoice_reg_bname');
  46. $data['invoice_reg_baccount'] = input('post.invoice_reg_baccount');
  47. // $data['invoice_rec_name'] = input('post.invoice_rec_name');
  48. // $data['invoice_rec_mobphone'] = input('post.invoice_rec_mobphone');
  49. // $data['invoice_rec_province'] = input('post.area_info');
  50. // $data['invoice_goto_addr'] = input('post.invoice_goto_addr');
  51. return $data;
  52. }
  53. public function add() {
  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. $invoice_id = intval(input('param.invoice_id'));
  87. if (0 >= $invoice_id) {
  88. ds_json_encode(10001, lang('param_error'));
  89. }
  90. $invoice_model = model('invoice');
  91. $invoice = $invoice_model->getInvoiceInfo(array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
  92. if (empty($invoice)) {
  93. ds_json_encode(10001, lang('invoice_does_not_exist'));
  94. }
  95. if (!request()->isPost()) {
  96. View::assign('invoice', $invoice);
  97. /* 设置买家当前菜单 */
  98. $this->setMemberCurMenu('member_invoice');
  99. /* 设置买家当前栏目 */
  100. $this->setMemberCurItem('my_invoice_edit');
  101. return View::fetch($this->template_dir . 'form');
  102. } else {
  103. $data = $this->get_data();
  104. $memberinvoice_validate = ds_validate('invoice');
  105. $scene='';
  106. if($data['invoice_state']==1){
  107. $scene = 'invoice_1_update';
  108. }else{
  109. $scene = 'invoice_2_update';
  110. }
  111. if (!$memberinvoice_validate->scene($scene)->check($data)) {
  112. ds_json_encode(10001, $memberinvoice_validate->getError());
  113. }
  114. $result = $invoice_model->editInvoice($data, array('member_id' => session('member_id'), 'invoice_id' => $invoice_id));
  115. if ($result) {
  116. ds_json_encode(10000, lang('ds_common_save_succ'));
  117. } else {
  118. ds_json_encode(10001, lang('ds_common_save_fail'));
  119. }
  120. }
  121. }
  122. public function drop() {
  123. $invoice_id = intval(input('param.invoice_id'));
  124. if (0 >= $invoice_id) {
  125. ds_json_encode(10001, lang('empty_error'));
  126. }
  127. $invoice_model = model('invoice');
  128. $result = $invoice_model->delInvoice(array('invoice_id' => $invoice_id,'member_id'=>session('member_id')));
  129. if ($result) {
  130. ds_json_encode(10000, lang('ds_common_del_succ'));
  131. } else {
  132. ds_json_encode(10001, lang('ds_common_del_fail'));
  133. }
  134. }
  135. /**
  136. * 栏目菜单
  137. */
  138. function getMemberItemList() {
  139. $item_list = array(
  140. array(
  141. 'name' => 'my_invoice',
  142. 'text' => lang('my_invoice'),
  143. 'url' => (string)url('Memberinvoice/index'),
  144. ),
  145. array(
  146. 'name' => 'my_invoice_add',
  147. 'text' => lang('new_invoice'),
  148. 'url' => (string)url('Memberinvoice/add'),
  149. ),
  150. );
  151. if (request()->action() == 'edit') {
  152. $item_list[] = array(
  153. 'name' => 'my_invoice_edit',
  154. 'text' => lang('edit_invoice'),
  155. 'url' => "javascript:void(0)",
  156. );
  157. }
  158. return $item_list;
  159. }
  160. }
  161. ?>