OrderReceipt.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\merchant\store\order;
  12. use think\App;
  13. use crmeb\basic\BaseController;
  14. use app\common\repositories\store\order\StoreOrderReceiptRepository;
  15. use app\common\repositories\user\UserReceiptRepository;
  16. use app\common\repositories\store\order\StoreOrderRepository;
  17. class OrderReceipt extends BaseController
  18. {
  19. protected $repository;
  20. public function __construct(App $app, StoreOrderReceiptRepository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. }
  25. /**
  26. * TODO 列表
  27. * @return mixed
  28. * @author Qinii
  29. * @day 2020-10-17
  30. */
  31. public function Lst()
  32. {
  33. [$page, $limit] = $this->getPage();
  34. $where = $this->request->params(['status', 'date', 'receipt_sn','username','order_type','keyword']);
  35. $where['mer_id'] = $this->request->merId();
  36. return app('json')->success($this->repository->getList($where, $page, $limit));
  37. }
  38. /**
  39. * TODO 平台列表
  40. * @return mixed
  41. * @author Qinii
  42. * @day 2020-10-17
  43. */
  44. public function getList()
  45. {
  46. [$page, $limit] = $this->getPage();
  47. $where = $this->request->params(['status', 'date', 'receipt_sn','username','order_type','keyword','mer_id']);
  48. return app('json')->success($this->repository->getList($where, $page, $limit));
  49. }
  50. public function setRecipt()
  51. {
  52. $ids = $this->request->param('ids');
  53. if(!$ids) return app('json')->fail('请选择需要合并的发票');
  54. $this->repository->merExists($ids,$this->request->merId());
  55. return app('json')->success($this->repository->setRecipt($ids,$this->request->merId()));
  56. }
  57. /**
  58. * TODO 开票
  59. * @return mixed
  60. * @author Qinii
  61. * @day 2020-10-17
  62. */
  63. public function saveRecipt()
  64. {
  65. $data = $this->request->param(['ids','receipt_sn','receipt_price','receipt_no','mer_mark']);
  66. $this->repository->merExists($data['ids'],$this->request->merId());
  67. if(!is_numeric($data['receipt_price']) || $data['receipt_price'] < 0)
  68. return app('json')->fail('发票信息金额格式错误');
  69. //if(!$data['receipt_no'])return app('json')->fail('请填写发票号');
  70. $this->repository->save($data);
  71. return app('json')->success('开票成功');
  72. }
  73. /**
  74. * TODO 备注form
  75. * @param $id
  76. * @return mixed
  77. * @author Qinii
  78. * @day 2020-10-17
  79. */
  80. public function markForm($id)
  81. {
  82. return app('json')->success(formToData($this->repository->markForm($id)));
  83. }
  84. /**
  85. * TODO 备注
  86. * @param $id
  87. * @return mixed
  88. * @author Qinii
  89. * @day 2020-10-17
  90. */
  91. public function mark($id)
  92. {
  93. if(!$this->repository->getWhereCount(['order_receipt_id' => $id,'mer_id' => $this->request->merId()]))
  94. return app('json')->fail('数据不存在');
  95. $data = $this->request->params(['mer_mark']);
  96. $this->repository->update($id,$data);
  97. return app('json')->success('备注成功');
  98. }
  99. public function detail($id)
  100. {
  101. $mer_id = $this->request->merId();
  102. $where = [$this->repository->getPk() => $id];
  103. if($mer_id) $where['mer_id'] = $mer_id;
  104. $data = $this->repository->getSearch($where)->find();
  105. if(!$data) return app('json')->fail('数据不存在');
  106. if($data['receipt_info']->receipt_type == 1 ){
  107. $title = $data['receipt_info']->receipt_title_type == 1 ? '个人电子普通发票' : '企业电子普通发票';
  108. }else{
  109. $title = '企业专用纸质发票';
  110. }
  111. $data['title'] = $title;
  112. return app('json')->success($data);
  113. }
  114. public function update($id)
  115. {
  116. $data = $this->request->params(['receipt_no','mer_mark']);
  117. if(!empty($data['receipt_no'])) $data['status'] = 1;
  118. $where = [$this->repository->getPk() => $id,'mer_id' => $this->request->merId()];
  119. $res = $this->repository->getSearch($where)->find();
  120. if(!$res) return app('json')->fail('数据不存在');
  121. $this->repository->updateBySn($res['receipt_sn'],$data);
  122. return app('json')->success('编辑成功');
  123. }
  124. }