request->get(); $customId = $get['customId'] ?? 0; $id = $get['distId'] ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { util::fail('没有找到客户'); } if ($custom->ownMainId != $this->mainId) { util::fail('不是你的客户'); } $dist = DistClass::getById($id, true); if (empty($dist)) { util::fail('没有找到片区'); } if ($dist->mainId != $this->mainId) { util::fail('不是你的片区'); } $custom->distId = $id; $custom->save(); // 客户片区变更后,同步更新该客户所有订单的片区(走 customId 单索引) OrderClass::updateByCondition(['customId' => $customId], ['customDistId' => $id]); util::complete('修改成功'); } //获取所有片区id ssh 20251117 public function actionGetAllDist() { $mainId = $this->mainId; $all = DistClass::getAllByCondition(['mainId' => $mainId], null, '*'); util::success(['list' => $all]); } public function actionGetList() { $where = ['mainId' => $this->mainId, 'delStatus' => 0]; $list = DistClass::getDistList($where); util::success($list); } public function actionAdd() { $post = Yii::$app->request->post(); $post['adminId'] = $this->adminId; $post['mainId'] = $this->mainId ?? 0; DistClass::addDist($this->shop, $post); util::complete('添加成功'); } //修改分类同步 ssh 20220906 public function actionUpdate() { $data = Yii::$app->request->post(); $id = $data['id'] ?? 0; $name = $data['name'] ?? ''; $currentDist = DistClass::getById($id, true); if (empty($currentDist)) { util::fail('没有找到片区'); } if ($currentDist->mainId != $this->mainId) { util::fail('不是您的片区'); } $originName = $currentDist->name ?? ''; $has = DistClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true); if (!empty($has) && $id != $has->id) { util::fail('名称已经存在'); } $currentDist->name = $name; $currentDist->save(); //在首店修改,则父级下所有直营和加盟店,同步修改 $masterShop = $this->shop; if (isset($masterShop->default) && $masterShop->default == 1 && isset($masterShop->dataSync) && $masterShop->dataSync == 1) { $sjId = $masterShop->sjId ?? 0; $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true); foreach ($shopList as $shop) { $shopId = $shop->id ?? 0; if ($shopId == $masterShop->id) { //前面已经修改过了 continue; } $currentMainId = $shop->mainId ?? 0; $chainList = DistClass::getAllByCondition(['mainId' => $currentMainId], null, '*', null, true); if (!empty($chainList)) { foreach ($chainList as $chain) { if ($chain->name == $originName) { $chain->name = $name; $chain->save(); } } } } } util::complete('修改成功'); } //删除花材分类 ssh 202207062136 public function actionDelete() { $id = Yii::$app->request->get('id', 0); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $myDist = DistClass::getById($id, true); if ($myDist->mainId != $this->mainId) { util::fail('不是你的片区'); } $myDist->delStatus = 1; $myDist->save(); $originName = $myDist->name ?? ''; //在首店删除,则父级下所有直营和加盟店同步删除 $masterShop = $this->shop; if (isset($masterShop->default) && $masterShop->default == 1) { $sjId = $masterShop->sjId ?? 0; $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true); foreach ($shopList as $shop) { $shopId = $shop->id ?? 0; if ($shopId == $masterShop->id) { //前面已经删除过了 continue; } $currentMainId = $shop->mainId ?? 0; $chainList = DistClass::getAllByCondition(['mainId' => $currentMainId], null, '*', null, true); if (!empty($chainList)) { foreach ($chainList as $chain) { if ($chain->name == $originName) { $chain->delStatus = 1; $chain->save(); } } } } } $transaction->commit(); util::complete('操作成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("失败原因:" . $e->getMessage()); util::fail('删除失败'); } } }