request->post('time/s', date('Y-m')); $result['count'] = $monuyModel::getCountMonthBalance($time); $result['list'] = $monuyModel ->with('users') ->where('status', MonuyModel::STATUS_NORMAL) ->whereMonth('create_date', $time) ->order('id desc') ->paginate(10); $this->success('ok', $result); } //记账统计 public function getCount(MonuyModel $monuyModel) { $type = $this->request->post('type/d, 1'); $time = $this->request->post('time/s', date('Y-m')); //月统计 if($type == 1){ $result = $monuyModel::getCountMonthBalance($time); //日均支出 $day = getDaysOfMonth($time); $result['day_expenditure'] = ($result['expenditure'] > 0)? bcdiv($result['expenditure'], $day, 2): 0; }else{ $result = $monuyModel::getCountYearBalance($time); //日均支出 $day = getDaysOfYear($time); $result['day_expenditure'] = ($result['expenditure'] > 0)? bcdiv($result['expenditure'], $day, 2): 0; } $this->success('ok', $result); } //添加记账 public function money(MonuyModel $monuyModel) { $data = $this->request->post(); $result = false; Db::startTrans(); try { validate(MoneyValidate::class)->scene('add')->check($data); //发货数据 $data['user_id'] = $this->userinfo['id']; $result = $monuyModel::create($data); Db::commit(); }catch (ValidateException $e) { Db::rollback(); return $this->error($e->getError()); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('没有新增任何数据')); } $this->success(); } //账单编辑 public function moneyedit(MonuyModel $monuyModel) { $data = $this->request->post(); $result = false; Db::startTrans(); try { validate(MoneyValidate::class)->scene('edit')->check($data); $rows = $monuyModel->where('id', $data['id'])->where('user_id', $this->userinfo['id'])->whereDay('createtime')->where('status', $monuyModel::STATUS_NORMAL)->find(); if(!$rows) $this->error('数据不存在'); //发货数据 $result = $rows->save($data); Db::commit(); }catch (ValidateException $e) { Db::rollback(); return $this->error($e->getError()); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('没有更新任何数据')); } $this->success(); } //删除账单 public function moneydel(MonuyModel $monuyModel) { $id = $this->request->post('id/d'); $result = false; Db::startTrans(); try { $rows = $monuyModel->where('id', $id)->where('user_id', $this->userinfo['id'])->whereDay('createtime')->where('status', $monuyModel::STATUS_NORMAL)->find(); if(!$rows) $this->error('数据不存在'); //发货数据 $rows->status = $monuyModel::STATUS_HIDDEN; $result = $rows->save(); Db::commit(); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('没有删除任何数据')); } $this->success(); } /** * @return void 全部类型图标 */ public function getConfig() { $type = $this->request->post('type/s', 'bank_account'); if(!in_array($type, ['bank_account', 'money_in_type', 'money_out_type'])) $this->error('参数有误'); $this->success('提交成功', site_config('addonsd.'.$type)); } }