MoneyLog.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\StockConfig;
  4. use app\common\model\MoneyLog as MonuyModel;
  5. use app\common\model\StockLog;
  6. use think\exception\ValidateException;
  7. use app\api\validate\Money as MoneyValidate;
  8. use app\common\model\StockDetail;
  9. use think\facade\Db;
  10. //记账记录表
  11. class MoneyLog extends Base
  12. {
  13. //记账记录
  14. public function moneylog(MonuyModel $monuyModel)
  15. {
  16. $time = $this->request->post('time/d', date('Y-m'));
  17. $result['count'] = $monuyModel::getCountBalance($this->userinfo['id'], $time);
  18. $result['list'] = $monuyModel->where('user_id', $this->userinfo['id'])
  19. ->whereMonth('create_date', $time)
  20. ->order('id desc')
  21. //->group('create_date')
  22. ->paginate(10);
  23. $this->success('ok', $result);
  24. }
  25. //添加记账
  26. public function money(MonuyModel $monuyModel)
  27. {
  28. $data = $this->request->post();
  29. $result = false;
  30. Db::startTrans();
  31. try {
  32. validate(MoneyValidate::class)->scene('add')->check($data);
  33. //发货数据
  34. $data['user_id'] = $this->userinfo['id'];
  35. $result = $monuyModel::create($data);
  36. Db::commit();
  37. }catch (ValidateException $e) {
  38. Db::rollback();
  39. return $this->error($e->getError());
  40. } catch (\Exception $e) {
  41. Db::rollback();
  42. $this->error($e->getMessage());
  43. }
  44. if ($result === false) {
  45. $this->error(__('没有新增任何数据'));
  46. }
  47. $this->success();
  48. }
  49. /**
  50. * @return void 全部类型图标
  51. */
  52. public function getConfig()
  53. {
  54. $type = $this->request->post('type/s', 'bank_account');
  55. if(!in_array($type, ['bank_account', 'money_in_type', 'money_out_type'])) $this->error('参数有误');
  56. $this->success('提交成功', site_config('addonsd.'.$type));
  57. }
  58. }