| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace app\api\controller;
- use app\api\service\auth\MysqlAdapter;
- use app\common\model\ScanLog;
- use app\common\model\StockConfig;
- use app\api\service\StockService;
- use app\common\model\StockLog;
- use think\exception\HttpResponseException;
- use think\exception\ValidateException;
- use app\api\validate\Worker as WorkerValidate;
- use think\facade\Cache;
- use think\facade\Db;
- use think\Response;
- /**
- * 打包工人相关接口
- */
- class Worker extends Base
- {
- /**
- * 判断权限
- * @access protected
- */
- protected function _initialize()
- {
- parent::_initialize();
- if(!str_contains($this->userinfo['role'], "4")){
- $this->error(__('没有权限' . $this->userinfo['role']));
- }
- }
- //首页
- public function index(StockConfig $stockConfig)
- {
- $data = [];
- $data['today'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'today')->count();
- $data['yesterday'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'yesterday')->count();
- $this->success('ok', $data);
- }
- //添加出入库
- public function scan(ScanLog $scanLog)
- {
- $data = $this->request->post();
- $result = false;
- Db::startTrans();
- $insert_data = [];
- try {
- validate(WorkerValidate::class)->scene('scan')->check($data);
- //$resData = $stockService::setGoOutStock($this->userinfo['id'], $data);
- $insert_data = [
- <<<<<<< HEAD
- 'user_id' => $this->userinfo['id'],
- =======
- 'user_id' => $this->userinfo['id'],
- >>>>>>> 7417099cf867aa98fa0a09ae05ba232261f7552d
- 'code' => $data['code'],
- 'order_status' => 0,
- 'remark' => '未找到单号',
- ];
- $result = $scanLog->save($insert_data);
- Db::commit();
- }catch (ValidateException $e) {
- return $this->error($e->getError());
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('没有新增任何数据'));
- }
- $this->success('', $insert_data);
- }
- //扫描记录
- public function scanlog(ScanLog $scanLog)
- {
- $where = [];
- $limit = $this->request->post('limit/d', 10); //条数
- $time = $this->request->post('create_time/s'); //日期
- if(!empty($type)) $where[] = ['a.type', '=', $type];
- if(!empty($type_id)) $where[] = ['a.type_id', '=',$type_id];
- if(!empty($spec_id)) $where[] = ['a.variety_id', '=',$spec_id];
- if(!empty($time)){
- $arr = explode(',', $time);
- $where[] = ['a.createtime', '>=', strtotime($arr[0])];
- $where[] = ['a.createtime', '<=', strtotime($arr[1])];
- }
- $list = ScanLog::where('user_id', $this->userinfo['id'])
- ->whereTime('createtime', 'today')
- ->order('id desc')
- ->paginate($limit);
- $this->success('ok', $list);
- }
-
-
- }
|