OrderReceipt.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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. * 列表
  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','uid']);
  35. $where['mer_id'] = $this->request->merId();
  36. return app('json')->success($this->repository->getList($where, $page, $limit));
  37. }
  38. /**
  39. * 平台列表
  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','nickname','order_type','keyword','mer_id','uid','phone']);
  48. return app('json')->success($this->repository->getList($where, $page, $limit));
  49. }
  50. /**
  51. * 设置收据
  52. *
  53. * @return \think\response\Json
  54. */
  55. public function setRecipt()
  56. {
  57. // 获取请求参数中的 ids
  58. $ids = $this->request->param('ids');
  59. if (!$ids) return app('json')->fail('请选择需要合并的发票');
  60. $this->repository->merExists($ids, $this->request->merId());
  61. return app('json')->success($this->repository->setRecipt($ids, $this->request->merId()));
  62. }
  63. /**
  64. * 开票
  65. * @return mixed
  66. * @author Qinii
  67. * @day 2020-10-17
  68. */
  69. public function saveRecipt()
  70. {
  71. $data = $this->request->param(['ids','receipt_sn','receipt_price','receipt_no','mer_mark']);
  72. $this->repository->merExists($data['ids'],$this->request->merId());
  73. if(!is_numeric($data['receipt_price']) || $data['receipt_price'] < 0)
  74. return app('json')->fail('发票信息金额格式错误');
  75. //if(!$data['receipt_no'])return app('json')->fail('请填写发票号');
  76. $this->repository->save($data);
  77. return app('json')->success('开票成功');
  78. }
  79. /**
  80. * 备注form
  81. * @param $id
  82. * @return mixed
  83. * @author Qinii
  84. * @day 2020-10-17
  85. */
  86. public function markForm($id)
  87. {
  88. return app('json')->success(formToData($this->repository->markForm($id)));
  89. }
  90. /**
  91. * 备注
  92. * @param $id
  93. * @return mixed
  94. * @author Qinii
  95. * @day 2020-10-17
  96. */
  97. public function mark($id)
  98. {
  99. if(!$this->repository->getWhereCount(['order_receipt_id' => $id,'mer_id' => $this->request->merId()]))
  100. return app('json')->fail('数据不存在');
  101. $data = $this->request->params(['mer_mark']);
  102. $this->repository->update($id,$data);
  103. return app('json')->success('备注成功');
  104. }
  105. /**
  106. * 获取发票详情
  107. * @param int $id 发票ID
  108. * @return \think\response\Json
  109. */
  110. public function detail($id)
  111. {
  112. // 获取商家ID
  113. $mer_id = $this->request->merId();
  114. // 构建查询条件
  115. $where = [$this->repository->getPk() => $id];
  116. if ($mer_id) $where['mer_id'] = $mer_id;
  117. // 根据条件查询发票信息
  118. $data = $this->repository->getSearch($where)->find();
  119. // 判断发票是否存在
  120. if (!$data) return app('json')->fail('数据不存在');
  121. // 根据发票类型设置标题
  122. if ($data['receipt_info']->receipt_type == 1) {
  123. $title = $data['receipt_info']->receipt_title_type == 1 ? '个人电子普通发票' : '企业电子普通发票';
  124. } else {
  125. $title = '企业专用纸质发票';
  126. }
  127. $data['title'] = $title;
  128. // 返回发票信息
  129. return app('json')->success($data);
  130. }
  131. /**
  132. * 更新发票信息
  133. * @param int $id 发票ID
  134. * @return \think\response\Json
  135. */
  136. public function update($id)
  137. {
  138. // 获取参数
  139. $data = $this->request->params(['receipt_no', 'mer_mark']);
  140. // 如果发票号码不为空,则将状态设置为已付款
  141. if (!empty($data['receipt_no'])) $data['status'] = 1;
  142. $where = [$this->repository->getPk() => $id, 'mer_id' => $this->request->merId()];
  143. $res = $this->repository->getSearch($where)->find();
  144. if (!$res) return app('json')->fail('数据不存在');
  145. // 更新发票信息
  146. $this->repository->updateBySn($res['receipt_sn'], $data);
  147. // 返回操作结果
  148. return app('json')->success('编辑成功');
  149. }
  150. }