PrinterController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Printer;
  5. class PrinterController extends Base
  6. {
  7. public function update()
  8. {
  9. $data = input('post.');
  10. $data['settings'] = serialize($data);
  11. unset($data['create_time']);
  12. $data['weid'] = weid();
  13. if (!empty($this->sid)) {
  14. $data['sid'] = (int) $this->sid;
  15. }
  16. if (empty($data['id'])) {
  17. try {
  18. $res = Printer::create($data);
  19. } catch (\Exception $e) {
  20. throw new ValidateException($e->getMessage());
  21. }
  22. return $this->json(['msg' => '操作成功', 'data' => $res->id]);
  23. } else {
  24. try {
  25. Printer::update($data);
  26. } catch (\Exception $e) {
  27. throw new ValidateException($e->getMessage());
  28. }
  29. return $this->json(['msg' => '操作成功']);
  30. }
  31. }
  32. function getInfo()
  33. {
  34. $data = Printer::where(['weid' => weid(), 'sid' => (int) $this->sid])->order('id desc')->find();
  35. $res = iunserializer($data['settings']);
  36. $res['id'] = $data['id'];
  37. $res['pinpai'] = $data['pinpai'];
  38. return $this->json(['data' => $res]);
  39. }
  40. function getField()
  41. {
  42. $data['PinpaiType'] = Printer::getpcarray();
  43. return $this->json(['data' => $data]);
  44. }
  45. }