ShopController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace pt\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\shop\classes\ShopAdminClass;
  6. use bizHd\merchant\services\ShopService;
  7. use bizHd\staff\classes\StaffClass;
  8. use common\components\dict;
  9. use common\components\stringUtil;
  10. use common\components\util;
  11. use Yii;
  12. class ShopController extends BaseController
  13. {
  14. //续期要求变更 ssh 20240427
  15. public function actionNeedRenewChange()
  16. {
  17. $get = Yii::$app->request->get();
  18. $shopId = $get['id'] ?? 0;
  19. $shop = ShopClass::getById($shopId, true);
  20. if (empty($shop)) {
  21. util::fail('没有找到门店43');
  22. }
  23. $old = $shop->needRenew;
  24. $new = $old == 0 ? 1 : 0;
  25. $shop->needRenew = $new;
  26. $shop->save();
  27. util::complete('修改成功');
  28. }
  29. //添加员工 ssh 2023429
  30. public function actionAddStaff()
  31. {
  32. $post = Yii::$app->request->post();
  33. $mobile = $post['mobile'] ?? '';
  34. $shopId = $post['shopId'] ?? 0;
  35. $super = $post['super'] ?? 0;
  36. $nickName = $post['nickName'] ?? '';
  37. $nickName = empty($nickName) ? substr($mobile, 7, 4) : $nickName;
  38. $shop = ShopClass::getById($shopId, true);
  39. if (empty($shop)) {
  40. util::fail('没有找到门店44');
  41. }
  42. $ptStyle = $shop->ptStyle ?? 1;
  43. $connection = Yii::$app->db;
  44. $transaction = $connection->beginTransaction();
  45. try {
  46. $mainId = $shop->mainId ?? 0;
  47. $adminInfo = ['name' => $nickName, 'mobile' => $mobile, 'style' => $ptStyle, 'currentGhsShopId' => $shopId];
  48. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  49. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  50. $role = AdminRoleClass::getByCondition(['mainId' => $mainId], true);
  51. if (empty($role)) {
  52. util::fail('没有找到角色...');
  53. }
  54. $roleId = $role->id ?? 0;
  55. $addData = ['shopId' => $shopId, 'mobile' => $mobile, 'super' => $super, 'remind' => 1, 'roleId' => $roleId];
  56. $respond = [];
  57. if ($ptStyle == 2) {
  58. $respond = ShopAdminClass::appGenerateStaff($addData, $admin);
  59. } elseif ($ptStyle == 1) {
  60. $respond = StaffClass::appGenerateStaff($addData, $admin);
  61. } else {
  62. util::fail('不存在的平台');
  63. }
  64. $transaction->commit();
  65. util::success($respond);
  66. } catch (\Exception $exception) {
  67. $transaction->rollBack();
  68. Yii::info("失败原因:" . $exception->getMessage());
  69. util::fail('添加失败');
  70. }
  71. }
  72. //调整仅采购功能,允许零售使用所有功能 ssh 20220919
  73. public function actionChangeOnlyCg()
  74. {
  75. $get = Yii::$app->request->get();
  76. $id = $get['id'] ?? 0;
  77. $shop = ShopClass::getById($id, true);
  78. if (empty($shop)) {
  79. util::fail('没有找到门店45');
  80. }
  81. if ($shop->ptStyle != 1) {
  82. util::fail('只能给零售店操作');
  83. }
  84. $shop->onlyCg = $shop->onlyCg == 0 ? 1 : 0;
  85. $shop->save();
  86. util::complete();
  87. }
  88. //修改/批量修改门店终端号、到期时间、续费状态等信息
  89. public function actionUpdate()
  90. {
  91. $post = Yii::$app->request->post();
  92. $isBatch = $post['isBatch'] ?? 0;
  93. $ids = $post['ids'] ?? $post['id'] ?? [];
  94. if (is_string($ids)) {
  95. $ids = array_filter(array_map('trim', explode(',', $ids)));
  96. } elseif (is_numeric($ids)) {
  97. $ids = [(int)$ids];
  98. }
  99. if (empty($ids)) {
  100. util::fail('缺少门店ID');
  101. }
  102. $shops = ShopClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  103. if (empty($shops)) {
  104. util::fail('没有找到对应门店');
  105. }
  106. foreach ($shops as $shop) {
  107. if (!empty($isBatch) || count($ids) > 1) {
  108. // 批量修改模式:只更新有传且不为空/不为-1的字段
  109. if (isset($post['lklSjNo']) && trim((string)$post['lklSjNo']) !== '') {
  110. $shop->lklSjNo = trim((string)$post['lklSjNo']);
  111. }
  112. if (isset($post['lklB2BTermNo']) && trim((string)$post['lklB2BTermNo']) !== '') {
  113. $shop->lklB2BTermNo = trim((string)$post['lklB2BTermNo']);
  114. }
  115. if (isset($post['lklScanTermNo']) && trim((string)$post['lklScanTermNo']) !== '') {
  116. $shop->lklScanTermNo = trim((string)$post['lklScanTermNo']);
  117. }
  118. if (isset($post['deadline']) && trim((string)$post['deadline']) !== '') {
  119. $shop->deadline = trim((string)$post['deadline']);
  120. }
  121. if (isset($post['beforeDeadline']) && trim((string)$post['beforeDeadline']) !== '') {
  122. $shop->beforeDeadline = trim((string)$post['beforeDeadline']);
  123. }
  124. if (isset($post['hasRenew']) && $post['hasRenew'] !== '' && (int)$post['hasRenew'] !== -1) {
  125. $shop->hasRenew = (int)$post['hasRenew'];
  126. }
  127. } else {
  128. // 单个修改模式:全量覆盖提交的字段
  129. if (isset($post['lklSjNo'])) {
  130. $shop->lklSjNo = trim((string)$post['lklSjNo']);
  131. }
  132. if (isset($post['lklB2BTermNo'])) {
  133. $shop->lklB2BTermNo = trim((string)$post['lklB2BTermNo']);
  134. }
  135. if (isset($post['lklScanTermNo'])) {
  136. $shop->lklScanTermNo = trim((string)$post['lklScanTermNo']);
  137. }
  138. if (isset($post['deadline'])) {
  139. $shop->deadline = !empty($post['deadline']) ? trim((string)$post['deadline']) : null;
  140. }
  141. if (isset($post['beforeDeadline'])) {
  142. $shop->beforeDeadline = !empty($post['beforeDeadline']) ? trim((string)$post['beforeDeadline']) : null;
  143. }
  144. if (isset($post['hasRenew'])) {
  145. $shop->hasRenew = (int)$post['hasRenew'];
  146. }
  147. }
  148. $shop->save();
  149. }
  150. util::complete('修改成功');
  151. }
  152. //门店列表 ssh 20210730
  153. public function actionList()
  154. {
  155. $where = [];
  156. $name = Yii::$app->request->get('name', '');
  157. if (!empty($name)) {
  158. if (is_numeric($name)) {
  159. $where['mobile'] = ['like', $name];
  160. } elseif (stringUtil::isLetter($name)) {
  161. $where['py'] = ['like', $name];
  162. } else {
  163. $where['merchantName'] = ['like', $name];
  164. }
  165. }
  166. $list = ShopService::getShopList($where);
  167. util::success($list);
  168. }
  169. }