MoneyLog.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 index(StockLog $stockLog)
  15. {
  16. $data= $stockLog->where('user_id', $this->userinfo['id'])
  17. ->field('type,count(id) as count')
  18. ->group('type')
  19. ->select();
  20. $this->success('ok', $data);
  21. }
  22. //记账
  23. public function money(StockConfig $stockConfig, MonuyModel $monuyModel)
  24. {
  25. $data = $this->request->post();
  26. $result = false;
  27. Db::startTrans();
  28. try {
  29. validate(MoneyValidate::class)->scene('add')->check($data);
  30. //发货数据
  31. $data['user_id'] = $this->userinfo['id'];
  32. $result = $monuyModel::create($data);
  33. Db::commit();
  34. }catch (ValidateException $e) {
  35. Db::rollback();
  36. return $this->error($e->getError());
  37. } catch (\Exception $e) {
  38. Db::rollback();
  39. $this->error($e->getMessage());
  40. }
  41. if ($result === false) {
  42. $this->error(__('没有新增任何数据'));
  43. }
  44. $this->success();
  45. //MoneyValidate
  46. $result = [];
  47. $list = $stockConfig->where('status', $stockConfig::StatusNormal)->field('id,type_id,title')
  48. ->orderRaw("field('variety_name','packing_box','material')")->select();
  49. $this->success('ok', $result);
  50. }
  51. /**
  52. * @return void 全部类型图标
  53. */
  54. public function getConfig()
  55. {
  56. $type = $this->request->post('type/s', 'bank_account');
  57. if(!in_array($type, ['bank_account', 'money_in_type', 'money_out_type'])) $this->error('参数有误');
  58. $this->success('提交成功', site_config('addonsd.'.$type));
  59. }
  60. }