ShopController.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace pt\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizHd\merchant\services\ShopService;
  6. use common\components\dict;
  7. use common\components\stringUtil;
  8. use common\components\util;
  9. use Yii;
  10. class ShopController extends BaseController
  11. {
  12. //添加员工 ssh 2023429
  13. public function actionAddStaff()
  14. {
  15. $post = Yii::$app->request->post();
  16. $mobile = $post['mobile'] ?? '';
  17. $shopId = $post['shopId'] ?? 0;
  18. $super = $post['super'] ?? 0;
  19. $nickName = $post['nickName'] ?? '';
  20. $nickName = empty($nickName) ? substr($mobile, 7, 4) : $nickName;
  21. $shop = ShopClass::getById($shopId, true);
  22. if (empty($shop)) {
  23. util::fail('没有找到门店');
  24. }
  25. $ptStyle = $shop->ptStyle ?? 1;
  26. if ($ptStyle != 2) {
  27. util::fail('请在择批发店添加员工');
  28. }
  29. $connection = Yii::$app->db;
  30. $transaction = $connection->beginTransaction();
  31. try {
  32. $mainId = $shop->mainId ?? 0;
  33. $adminInfo = ['name' => $nickName, 'mobile' => $mobile, 'style' => $ptStyle, 'currentGhsShopId' => $shopId];
  34. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  35. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  36. $role = AdminRoleClass::getByCondition(['mainId' => $mainId], true);
  37. if (empty($role)) {
  38. util::fail('没有找到角色');
  39. }
  40. $roleId = $role->id ?? 0;
  41. $addData = ['shopId' => $shopId, 'mobile' => $mobile, 'super' => $super, 'remind' => 1, 'roleId' => $roleId];
  42. $respond = \bizGhs\shop\classes\ShopAdminClass::appGenerateStaff($addData, $admin);
  43. $transaction->commit();
  44. util::success($respond);
  45. } catch (\Exception $exception) {
  46. $transaction->rollBack();
  47. Yii::info("失败原因:" . $exception->getMessage());
  48. util::fail('添加失败');
  49. }
  50. }
  51. //调整仅采购功能,允许零售使用所有功能 ssh 20220919
  52. public function actionChangeOnlyCg()
  53. {
  54. $get = Yii::$app->request->get();
  55. $id = $get['id'] ?? 0;
  56. $shop = ShopClass::getById($id, true);
  57. if (empty($shop)) {
  58. util::fail('没有找到门店');
  59. }
  60. if ($shop->ptStyle != 1) {
  61. util::fail('只能给零售店操作');
  62. }
  63. $shop->onlyCg = $shop->onlyCg == 0 ? 1 : 0;
  64. $shop->save();
  65. util::complete();
  66. }
  67. //门店列表 ssh 20210730
  68. public function actionList()
  69. {
  70. $where = [];
  71. $name = Yii::$app->request->get('name', '');
  72. if (!empty($name)) {
  73. if (stringUtil::isLetter($name)) {
  74. $where['py'] = ['like', $name];
  75. } else {
  76. $where['merchantName'] = ['like', $name];
  77. }
  78. }
  79. $list = ShopService::getShopList($where);
  80. util::success($list);
  81. }
  82. }