OrderReceipt.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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->merchantGetList($where, $page, $limit));
  37. }
  38. public function setRecipt()
  39. {
  40. $ids = $this->request->param('ids');
  41. if(!$ids) return app('json')->fail('请选择需要合并的发票');
  42. $this->repository->merExists($ids,$this->request->merId());
  43. return app('json')->success($this->repository->setRecipt($ids,$this->request->merId()));
  44. }
  45. /**
  46. * TODO 开票
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-10-17
  50. */
  51. public function saveRecipt()
  52. {
  53. $data = $this->request->param(['ids','receipt_sn','receipt_price','receipt_no','mer_mark']);
  54. $this->repository->merExists($data['ids'],$this->request->merId());
  55. if(!is_numeric($data['receipt_price']) || $data['receipt_price'] < 0)
  56. return app('json')->fail('发票信息金额格式错误');
  57. //if(!$data['receipt_no'])return app('json')->fail('请填写发票号');
  58. $this->repository->save($data);
  59. return app('json')->success('开票成功');
  60. }
  61. /**
  62. * TODO 备注form
  63. * @param $id
  64. * @return mixed
  65. * @author Qinii
  66. * @day 2020-10-17
  67. */
  68. public function markForm($id)
  69. {
  70. return app('json')->success(formToData($this->repository->markForm($id)));
  71. }
  72. /**
  73. * TODO 备注
  74. * @param $id
  75. * @return mixed
  76. * @author Qinii
  77. * @day 2020-10-17
  78. */
  79. public function mark($id)
  80. {
  81. if(!$this->repository->getWhereCount(['order_receipt_id' => $id,'mer_id' => $this->request->merId()]))
  82. return app('json')->fail('数据不存在');
  83. $data = $this->request->params(['mer_mark']);
  84. $this->repository->update($id,$data);
  85. return app('json')->success('备注成功');
  86. }
  87. public function detail($id)
  88. {
  89. $where = [$this->repository->getPk() => $id,'mer_id' => $this->request->merId()];
  90. $data = $this->repository->getSearch($where)->find();
  91. if(!$data) return app('json')->fail('数据不存在');
  92. if($data['receipt_type'] == 1 ){
  93. $title = $data['receipt_title_type'] == 1 ? '个人电子普通发票' : '企业电子普通发票';
  94. }else{
  95. $title = '企业专用纸质发票';
  96. }
  97. $data['title'] = $title;
  98. return app('json')->success($data);
  99. }
  100. public function update($id)
  101. {
  102. $data = $this->request->params(['receipt_no','mer_mark']);
  103. if(!empty($data['receipt_no'])) $data['status'] = 1;
  104. $where = [$this->repository->getPk() => $id,'mer_id' => $this->request->merId()];
  105. $res = $this->repository->getSearch($where)->find();
  106. if(!$res) return app('json')->fail('数据不存在');
  107. $this->repository->updateBySn($res['receipt_sn'],$data);
  108. return app('json')->success('编辑成功');
  109. }
  110. }