ShopExtController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. //添加修改小菊颜色 shish 20210906
  58. public function actionReplaceXj()
  59. {
  60. $act = Yii::$app->request->get('act', 'add');
  61. $id = Yii::$app->request->get('id', 0);
  62. $xj = $this->shopExt->xj;
  63. $hasIds = [];
  64. if (!empty($xj)) {
  65. $hasIds = json_decode($xj, true);
  66. }
  67. if ($act == 'add') {
  68. if(in_array($id,$hasIds) == false){
  69. $hasIds[] = $id;
  70. $this->shopExt->xj = json_encode($hasIds);
  71. $this->shopExt->save();
  72. }
  73. } else {
  74. $key = array_search($id,$hasIds);
  75. unset($hasIds[$key]);
  76. $this->shopExt->xj = json_encode($hasIds);
  77. $this->shopExt->save();
  78. }
  79. util::complete();
  80. }
  81. }