| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace app\api\controller;
- use DateTime;
- use app\common\model\MoneyLog as MonuyModel;
- use app\common\model\StockLog;
- use think\exception\ValidateException;
- use app\api\validate\Money as MoneyValidate;
- use app\common\model\StockDetail;
- use think\facade\Db;
- //记账记录表
- class MoneyLog extends Base
- {
- //记账记录
- public function moneylog(MonuyModel $monuyModel)
- {
- $time = $this->request->post('time/s', date('Y-m'));
- $result['count'] = $monuyModel::getCountMonthBalance($this->userinfo['id'], $time);
- $result['list'] = $monuyModel->where('user_id', $this->userinfo['id'])
- ->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($this->userinfo['id'], $time);
- //日均支出
- $day = getDaysOfMonth($time);
- $result['day_expenditure'] = ($result['expenditure'] > 0)? bcdiv($result['expenditure'], $day, 2): 0;
- }else{
- $result = $monuyModel::getCountYearBalance($this->userinfo['id'], $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'])->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'])->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));
- }
-
-
- }
|