MoneyController.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\FrontController;
  4. use App\Models\MoneyDetail;
  5. use App\Servers\CommonServer;
  6. use App\Servers\MoneyDetailServer;
  7. class MoneyController extends FrontController
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. /**
  14. * 获取会员收支统计
  15. * @return \Illuminate\Http\JsonResponse
  16. */
  17. function getMoneyStatistics()
  18. {
  19. $date = request()->input('date', '');
  20. if (empty($date)) $date = date('Y-m-01');
  21. if (!strtotime($date)) {
  22. return $this->apiResponseError('查询日期不合法');
  23. }
  24. $money_type = request()->input('money_type', '1');
  25. if (!in_array($money_type, [3, 1, 2])) {
  26. return $this->apiResponseError('资金类型错误');
  27. }
  28. $m_id = request()->member['id'];
  29. $money = MoneyDetailServer::creatServer()->getMoney($m_id, $money_type);
  30. $date_arr = CommonServer::creatServer()->getNextMonth($date);
  31. $income_info = MoneyDetailServer::creatServer()->getMoneyIncome($m_id, $money_type, $date_arr);
  32. $income_info['money'] = $money;
  33. $income_info['date'] = $date;
  34. return $this->apiResponseSuccess('获取信息成功', $income_info);
  35. }
  36. /**
  37. * 获取资金流水类型
  38. */
  39. function getWaterType()
  40. {
  41. $money_type = request()->input('money_type', '1');
  42. if (!in_array($money_type, [3, 1, 2])) {
  43. return $this->apiResponseError('资金类型错误');
  44. }
  45. $water_type = MoneyDetailServer::creatServer()->getWaterType($money_type);
  46. array_unshift($water_type, ['water_key' => '0', 'water_name' => '全部']);
  47. return $this->apiResponseSuccess('获取信息成功', $water_type);
  48. }
  49. /**
  50. * 获取流水明细
  51. * @return \Illuminate\Http\JsonResponse
  52. */
  53. function getWaterList()
  54. {
  55. $money_type = request()->input('money_type', '1');
  56. if (!in_array($money_type, [3, 1, 2])) {
  57. return $this->apiResponseError('资金类型错误');
  58. }
  59. $water_key = request()->input('water_key', '');
  60. $m_id = request()->member['id'];
  61. $shop_id = request()->input('shop_id', '');
  62. $where = [['m_id', $m_id], ['type', $money_type]];
  63. if ($water_key) $where[] = ['status', $water_key];
  64. if ($shop_id) $where[] = ['shop_id', $shop_id];
  65. $date = request()->input('date', '');
  66. if (empty($date)) $date = date('Y-m-01');
  67. if (!strtotime($date)) {
  68. return $this->apiResponseError('查询日期不合法');
  69. }
  70. $date_arr = CommonServer::creatServer()->getNextMonth($date);
  71. $list = MoneyDetail::where($where)
  72. ->whereBetween('created_at', $date_arr)
  73. ->select(['id', 'price', 'status', 'remainder', 'add_reduce', 'created_at', 'mark'])
  74. ->orderBy('id', 'desc')
  75. ->paginate(20);
  76. foreach ($list as $item) {
  77. $item->{'status_str'} = MoneyDetailServer::creatServer()->getStatusArr($item->{'status'});
  78. $item->{'price'} =CommonServer::creatServer()->setFormatNum($item->{'price'},2);
  79. }
  80. return $this->apiResponseSuccess('获取数据成功', ['date' => $date, 'total_num' => $list->total(), 'items' => $list->items()]);
  81. }
  82. }