| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace pt\controllers;
- use biz\admin\classes\AdminRoleClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizHd\merchant\services\ShopService;
- use bizHd\staff\classes\StaffClass;
- use common\components\dict;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class ShopController extends BaseController
- {
- //续期要求变更 ssh 20240427
- public function actionNeedRenewChange()
- {
- $get = Yii::$app->request->get();
- $shopId = $get['id'] ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('没有找到门店43');
- }
- $old = $shop->needRenew;
- $new = $old == 0 ? 1 : 0;
- $shop->needRenew = $new;
- $shop->save();
- util::complete('修改成功');
- }
- //添加员工 ssh 2023429
- public function actionAddStaff()
- {
- $post = Yii::$app->request->post();
- $mobile = $post['mobile'] ?? '';
- $shopId = $post['shopId'] ?? 0;
- $super = $post['super'] ?? 0;
- $nickName = $post['nickName'] ?? '';
- $nickName = empty($nickName) ? substr($mobile, 7, 4) : $nickName;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('没有找到门店44');
- }
- $ptStyle = $shop->ptStyle ?? 1;
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $mainId = $shop->mainId ?? 0;
- $adminInfo = ['name' => $nickName, 'mobile' => $mobile, 'style' => $ptStyle, 'currentGhsShopId' => $shopId];
- $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
- $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
- $role = AdminRoleClass::getByCondition(['mainId' => $mainId], true);
- if (empty($role)) {
- util::fail('没有找到角色...');
- }
- $roleId = $role->id ?? 0;
- $addData = ['shopId' => $shopId, 'mobile' => $mobile, 'super' => $super, 'remind' => 1, 'roleId' => $roleId];
- $respond = [];
- if ($ptStyle == 2) {
- $respond = ShopAdminClass::appGenerateStaff($addData, $admin);
- } elseif ($ptStyle == 1) {
- $respond = StaffClass::appGenerateStaff($addData, $admin);
- } else {
- util::fail('不存在的平台');
- }
- $transaction->commit();
- util::success($respond);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败原因:" . $exception->getMessage());
- util::fail('添加失败');
- }
- }
- //调整仅采购功能,允许零售使用所有功能 ssh 20220919
- public function actionChangeOnlyCg()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $shop = ShopClass::getById($id, true);
- if (empty($shop)) {
- util::fail('没有找到门店45');
- }
- if ($shop->ptStyle != 1) {
- util::fail('只能给零售店操作');
- }
- $shop->onlyCg = $shop->onlyCg == 0 ? 1 : 0;
- $shop->save();
- util::complete();
- }
- //修改/批量修改门店终端号、到期时间、续费状态等信息
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $isBatch = $post['isBatch'] ?? 0;
- $ids = $post['ids'] ?? $post['id'] ?? [];
- if (is_string($ids)) {
- $ids = array_filter(array_map('trim', explode(',', $ids)));
- } elseif (is_numeric($ids)) {
- $ids = [(int)$ids];
- }
- if (empty($ids)) {
- util::fail('缺少门店ID');
- }
- $shops = ShopClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($shops)) {
- util::fail('没有找到对应门店');
- }
- foreach ($shops as $shop) {
- if (!empty($isBatch) || count($ids) > 1) {
- // 批量修改模式:只更新有传且不为空/不为-1的字段
- if (isset($post['lklSjNo']) && trim((string)$post['lklSjNo']) !== '') {
- $shop->lklSjNo = trim((string)$post['lklSjNo']);
- }
- if (isset($post['lklB2BTermNo']) && trim((string)$post['lklB2BTermNo']) !== '') {
- $shop->lklB2BTermNo = trim((string)$post['lklB2BTermNo']);
- }
- if (isset($post['lklScanTermNo']) && trim((string)$post['lklScanTermNo']) !== '') {
- $shop->lklScanTermNo = trim((string)$post['lklScanTermNo']);
- }
- if (isset($post['deadline']) && trim((string)$post['deadline']) !== '') {
- $shop->deadline = trim((string)$post['deadline']);
- }
- if (isset($post['beforeDeadline']) && trim((string)$post['beforeDeadline']) !== '') {
- $shop->beforeDeadline = trim((string)$post['beforeDeadline']);
- }
- if (isset($post['hasRenew']) && $post['hasRenew'] !== '' && (int)$post['hasRenew'] !== -1) {
- $shop->hasRenew = (int)$post['hasRenew'];
- }
- } else {
- // 单个修改模式:全量覆盖提交的字段
- if (isset($post['lklSjNo'])) {
- $shop->lklSjNo = trim((string)$post['lklSjNo']);
- }
- if (isset($post['lklB2BTermNo'])) {
- $shop->lklB2BTermNo = trim((string)$post['lklB2BTermNo']);
- }
- if (isset($post['lklScanTermNo'])) {
- $shop->lklScanTermNo = trim((string)$post['lklScanTermNo']);
- }
- if (isset($post['deadline'])) {
- $shop->deadline = !empty($post['deadline']) ? trim((string)$post['deadline']) : null;
- }
- if (isset($post['beforeDeadline'])) {
- $shop->beforeDeadline = !empty($post['beforeDeadline']) ? trim((string)$post['beforeDeadline']) : null;
- }
- if (isset($post['hasRenew'])) {
- $shop->hasRenew = (int)$post['hasRenew'];
- }
- }
- $shop->save();
- }
- util::complete('修改成功');
- }
- //门店列表 ssh 20210730
- public function actionList()
- {
- $where = [];
- $name = Yii::$app->request->get('name', '');
- if (!empty($name)) {
- if (is_numeric($name)) {
- $where['mobile'] = ['like', $name];
- } elseif (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['merchantName'] = ['like', $name];
- }
- }
- $list = ShopService::getShopList($where);
- util::success($list);
- }
- }
|