OrderReceipt.php 4.1 KB

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