12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\FrontController;
- use App\Models\MoneyDetail;
- use App\Servers\CommonServer;
- use App\Servers\MoneyDetailServer;
- class MoneyController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 获取会员收支统计
- * @return \Illuminate\Http\JsonResponse
- */
- function getMoneyStatistics()
- {
- $date = request()->input('date', '');
- if (empty($date)) $date = date('Y-m-01');
- if (!strtotime($date)) {
- return $this->apiResponseError('查询日期不合法');
- }
- $money_type = request()->input('money_type', '1');
- if (!in_array($money_type, [3, 1, 2])) {
- return $this->apiResponseError('资金类型错误');
- }
- $m_id = request()->member['id'];
- $money = MoneyDetailServer::creatServer()->getMoney($m_id, $money_type);
- $date_arr = CommonServer::creatServer()->getNextMonth($date);
- $income_info = MoneyDetailServer::creatServer()->getMoneyIncome($m_id, $money_type, $date_arr);
- $income_info['money'] = $money;
- $income_info['date'] = $date;
- return $this->apiResponseSuccess('获取信息成功', $income_info);
- }
- /**
- * 获取资金流水类型
- */
- function getWaterType()
- {
- $money_type = request()->input('money_type', '1');
- if (!in_array($money_type, [3, 1, 2])) {
- return $this->apiResponseError('资金类型错误');
- }
- $water_type = MoneyDetailServer::creatServer()->getWaterType($money_type);
- array_unshift($water_type, ['water_key' => '0', 'water_name' => '全部']);
- return $this->apiResponseSuccess('获取信息成功', $water_type);
- }
- /**
- * 获取流水明细
- * @return \Illuminate\Http\JsonResponse
- */
- function getWaterList()
- {
- $money_type = request()->input('money_type', '1');
- if (!in_array($money_type, [3, 1, 2])) {
- return $this->apiResponseError('资金类型错误');
- }
- $water_key = request()->input('water_key', '');
- $m_id = request()->member['id'];
- $shop_id = request()->input('shop_id', '');
- $where = [['m_id', $m_id], ['type', $money_type]];
- if ($water_key) $where[] = ['status', $water_key];
- if ($shop_id) $where[] = ['shop_id', $shop_id];
- $date = request()->input('date', '');
- if (empty($date)) $date = date('Y-m-01');
- if (!strtotime($date)) {
- return $this->apiResponseError('查询日期不合法');
- }
- $date_arr = CommonServer::creatServer()->getNextMonth($date);
- $list = MoneyDetail::where($where)
- ->whereBetween('created_at', $date_arr)
- ->select(['id', 'price', 'status', 'remainder', 'add_reduce', 'created_at', 'mark'])
- ->orderBy('id', 'desc')
- ->paginate(20);
- foreach ($list as $item) {
- $item->{'status_str'} = MoneyDetailServer::creatServer()->getStatusArr($item->{'status'});
- $item->{'price'} =CommonServer::creatServer()->setFormatNum($item->{'price'},2);
- }
- return $this->apiResponseSuccess('获取数据成功', ['date' => $date, 'total_num' => $list->total(), 'items' => $list->items()]);
- }
- }
|