Invoice.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace addons\shopro\controller\user;
  3. use addons\shopro\controller\Common;
  4. use app\admin\model\shopro\user\Invoice as UserInvoiceModel;
  5. use think\Db;
  6. class Invoice extends Common
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = ['*'];
  10. public function index()
  11. {
  12. $user = auth_user();
  13. $userInvoices = UserInvoiceModel::where('user_id', $user->id)
  14. ->order('id', 'asc')
  15. ->select();
  16. $this->success('获取成功', $userInvoices);
  17. }
  18. /**
  19. * 添加发票抬头
  20. *
  21. * @return \think\Response
  22. */
  23. public function add()
  24. {
  25. $user = auth_user();
  26. $params = $this->request->only([
  27. 'type', 'name', 'tax_no', 'address', 'mobile', 'bank_name', 'bank_no'
  28. ]);
  29. $params['user_id'] = $user->id;
  30. $this->svalidate($params, ".add");
  31. Db::transaction(function () use ($user, $params) {
  32. $userInvoice = new UserInvoiceModel();
  33. $userInvoice->save($params);
  34. });
  35. $this->success('保存成功');
  36. }
  37. /**
  38. * 发票详情
  39. *
  40. * @param $id
  41. * @return \think\Response
  42. */
  43. public function detail()
  44. {
  45. $user = auth_user();
  46. $id = $this->request->param('id');
  47. $userInvoice = UserInvoiceModel::where('user_id', $user->id)->where('id', $id)->find();
  48. if (!$userInvoice) {
  49. $this->error(__('No Results were found'));
  50. }
  51. $this->success('获取成功', $userInvoice);
  52. }
  53. /**
  54. * 编辑发票
  55. *
  56. * @return \think\Response
  57. */
  58. public function edit()
  59. {
  60. $user = auth_user();
  61. $id = $this->request->param('id');
  62. $params = $this->request->only([
  63. 'type', 'name', 'tax_no', 'address', 'mobile', 'bank_name', 'bank_no'
  64. ]);
  65. $this->svalidate($params, ".edit");
  66. $userInvoice = UserInvoiceModel::where('user_id', $user->id)->where('id', $id)->find();
  67. if (!$userInvoice) {
  68. $this->error(__('No Results were found'));
  69. }
  70. Db::transaction(function () use ($params, $userInvoice) {
  71. $userInvoice->save($params);
  72. });
  73. $this->success('保存成功');
  74. }
  75. /**
  76. * 删除发票
  77. *
  78. * @param string $id 要删除的发票
  79. * @return void
  80. */
  81. public function delete()
  82. {
  83. $user = auth_user();
  84. $id = $this->request->param('id');
  85. $userInvoice = UserInvoiceModel::where('user_id', $user->id)->where('id', $id)->find();
  86. if (!$userInvoice) {
  87. $this->error(__('No Results were found'));
  88. }
  89. $userInvoice->delete();
  90. $this->success('删除成功');
  91. }
  92. }