Financial.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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\system\financial;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\system\financial\FinancialRepository;
  14. use app\common\repositories\system\merchant\MerchantRepository;
  15. use app\validate\merchant\MerchantFinancialAccountValidate;
  16. use crmeb\basic\BaseController;
  17. use crmeb\services\ExcelService;
  18. use think\App;
  19. class Financial extends BaseController
  20. {
  21. /**
  22. * @var FinancialRepository
  23. */
  24. protected $repository;
  25. /**
  26. * Merchant constructor.
  27. * @param App $app
  28. * @param FinancialRepository $repository
  29. */
  30. public function __construct(App $app, FinancialRepository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. }
  35. /**
  36. * 转账信息Form
  37. * @param $id
  38. * @return \think\response\Json
  39. * @author Qinii
  40. * @day 3/18/21
  41. */
  42. public function accountForm()
  43. {
  44. return app('json')->success(formToData($this->repository->financialAccountForm($this->request->merId())));
  45. }
  46. /**
  47. * 转账信息保存
  48. * @param MerchantFinancialAccountValidate $accountValidate
  49. * @return \think\response\Json
  50. * @author Qinii
  51. * @day 3/18/21
  52. */
  53. public function accountSave(MerchantFinancialAccountValidate $accountValidate)
  54. {
  55. $data = $this->request->params(['account','financial_type','name','bank','bank_code','wechat','wechat_code','alipay','alipay_code']); //idcard
  56. $accountValidate->check($data);
  57. $this->repository->saveAccount($this->request->merId(),$data);
  58. return app('json')->success('保存成功');
  59. }
  60. /**
  61. * 申请转账form
  62. * @return \think\response\Json
  63. * @author Qinii
  64. * @day 3/19/21
  65. */
  66. public function createForm()
  67. {
  68. return app('json')->success(formToData($this->repository->applyForm($this->request->merId())));
  69. }
  70. /**
  71. * 申请转账保存
  72. * @return \think\response\Json
  73. * @author Qinii
  74. * @day 3/19/21
  75. */
  76. public function createSave()
  77. {
  78. $data = $this->request->param(['extract_money','financial_type','mark']);
  79. $data['mer_admin_id'] = $this->request->adminId();
  80. $this->repository->saveApply($this->request->merId(),$data);
  81. return app('json')->success('保存成功');
  82. }
  83. /**
  84. * 退保金额
  85. *
  86. * @return \Illuminate\Http\JsonResponse
  87. */
  88. public function refundMargin()
  89. {
  90. // 调用 repository 中的 checkRefundMargin 方法,传入当前商户 ID 和管理员 ID,返回结果并转化为 JSON 格式
  91. return app('json')->success($this->repository->checkRefundMargin($this->request->merId(), $this->request->adminId()));
  92. }
  93. /**
  94. * 退保金额申请
  95. *
  96. * @return \Illuminate\Http\JsonResponse
  97. */
  98. public function refundMarginApply()
  99. {
  100. // 从请求参数中获取 type、name、code、pic 四个字段的值
  101. $data = $this->request->params(['type', 'name', 'code', 'pic']);
  102. // 调用 repository 中的 refundMargin 方法,传入当前商户 ID、管理员 ID 和请求参数 data,无返回值
  103. $this->repository->refundMargin($this->request->merId(), $this->request->adminId(), $data);
  104. // 返回一个成功的 JSON 响应,消息为 '提交成功'
  105. return app('json')->success('提交成功');
  106. }
  107. /**
  108. * 列表
  109. * @author Qinii
  110. * @day 3/19/21
  111. */
  112. public function lst()
  113. {
  114. [$page, $limit] = $this->getPage();
  115. $where = $this->request->params(['date','status','financial_type','financial_status','keyword']);
  116. $where['keywords_'] = $where['keyword'];
  117. unset($where['keyword']);
  118. $where['mer_id'] = $this->request->merId();
  119. $data = $this->repository->getAdminList($where,$page,$limit);
  120. return app('json')->success($data);
  121. }
  122. /**
  123. * 取消申请
  124. * @param $id
  125. * @return \think\response\Json
  126. * @author Qinii
  127. * @day 3/19/21
  128. */
  129. public function delete($id)
  130. {
  131. $this->repository->cancel($this->request->merId(),$id,['is_del' => 1]);
  132. return app('json')->success('取消申请');
  133. }
  134. /**
  135. *
  136. * @param $id
  137. * @return \think\response\Json
  138. * @author Qinii
  139. * @day 3/19/21
  140. */
  141. public function detail($id)
  142. {
  143. $data = $this->repository->detail($id,$this->request->merId());
  144. if(!$data) return app('json')->fail('数据不存在');
  145. return app('json')->success($data);
  146. }
  147. /**
  148. * 标记表单
  149. *
  150. * @param int $id 表单ID
  151. * @return \think\response\Json
  152. */
  153. public function markForm($id)
  154. {
  155. // 调用 formToData 方法将表单转换为数据并返回 JSON 格式的成功响应
  156. return app('json')->success(formToData($this->repository->markForm($id)));
  157. }
  158. /**
  159. * 标记
  160. *
  161. * @param int $id 表单ID
  162. * @return \think\response\Json
  163. */
  164. public function mark($id)
  165. {
  166. // 根据主键和商家ID获取表单数据
  167. $ret = $this->repository->getWhere([$this->repository->getPk() => $id, 'mer_id' => $this->request->merId()]);
  168. // 如果数据不存在则返回 JSON 格式的失败响应
  169. if (!$ret) return app('json')->fail('数据不存在');
  170. // 获取备注数据
  171. $data = $this->request->params(['mark']);
  172. // 更新表单数据
  173. $this->repository->update($id, $data);
  174. // 返回 JSON 格式的成功响应
  175. return app('json')->success('备注成功');
  176. }
  177. /**
  178. * 导出财务日志
  179. *
  180. * @return \think\response\Json
  181. */
  182. public function export()
  183. {
  184. $where = $this->request->params(['date', 'status', 'financial_type', 'financial_status', 'keyword']);
  185. // 将关键字转换为小写并添加前缀
  186. $where['keywords_'] = $where['keyword'];
  187. // 删除原有的关键字
  188. unset($where['keyword']);
  189. // 添加商家ID
  190. $where['mer_id'] = $this->request->merId();
  191. // 获取分页参数
  192. [$page, $limit] = $this->getPage();
  193. $data = app()->make(ExcelService::class)->financialLog($where, $page, $limit);
  194. // 返回成功状态和数据
  195. return app('json')->success($data);
  196. }
  197. }