| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\api\controller;
- use app\common\model\StockConfig;
- 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 index(StockLog $stockLog)
- {
- $data= $stockLog->where('user_id', $this->userinfo['id'])
- ->field('type,count(id) as count')
- ->group('type')
- ->select();
- $this->success('ok', $data);
- }
- //记账
- public function money(StockConfig $stockConfig, 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();
- //MoneyValidate
- $result = [];
- $list = $stockConfig->where('status', $stockConfig::StatusNormal)->field('id,type_id,title')
- ->orderRaw("field('variety_name','packing_box','material')")->select();
-
- $this->success('ok', $result);
- }
- /**
- * @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));
- }
-
-
- }
|