ShopExtController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\shop\classes\ShopExtClass;
  5. use common\components\printUtil;
  6. use common\components\util;
  7. use Yii;
  8. class ShopExtController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. //添加打印机 shish 20210712
  12. public function actionAddPrint()
  13. {
  14. $shopAdmin = $this->shopAdmin;
  15. $roleId = $shopAdmin['roleId'] ?? 0;
  16. $role = AdminRoleClass::getById($roleId);
  17. $roleName = $role['roleName'] ?? '';
  18. if ($roleName == '员工') {
  19. util::fail('没有权限操作哦');
  20. }
  21. $shopId = $this->shopId;
  22. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  23. $get = Yii::$app->request->get();
  24. $printSn = $get['printSn'] ?? '';
  25. $printKey = $get['printKey'] ?? '';
  26. $print = new printUtil($printSn);
  27. $shop = $this->shop;
  28. $default = $shop->default ?? 0;
  29. $shopName = $shop->shopName ?? '';
  30. $sj = $this->sj;
  31. $sjName = $sj->name ?? '';
  32. $name = $default == 1 ? $sjName : $sjName . ' ' . $shopName;
  33. if (!empty($printSn) && !empty($printKey)) {
  34. $return = $print->addPrint($printKey, $name);
  35. if ($return) {
  36. $ext->printSn = $printSn;
  37. $ext->printKey = $printKey;
  38. $ext->save();
  39. util::complete('添加成功');
  40. }
  41. }
  42. if (empty($printSn) && empty($printKey)) {
  43. $ext->printSn = '';
  44. $ext->printKey = '';
  45. $ext->save();
  46. util::complete('修改成功');
  47. }
  48. util::fail('添加失败');
  49. }
  50. //获取打印机信息
  51. public function actionGetPrint()
  52. {
  53. $shopId = $this->shopId;
  54. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  55. util::success($ext);
  56. }
  57. }