| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace pt\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\MerchantClass;
- use biz\sj\classes\SjClass;
- use common\components\util;
- use Yii;
- class GhsController extends BaseController
- {
- public $guestAccess = [];
- //绑定供货商 shish 2021.3.29
- public function actionBindGhs()
- {
- $get = Yii::$app->request->get();
- $ownSjId = $get['ownSjId'] ?? '';
- $sjId = $get['sjId'] ?? '';
- if ($ownSjId == $sjId) {
- util::fail('不能自己绑自己');
- }
- $sj = MerchantClass::getMerchantById($ownSjId);
- if (isset($sj['style']) == false || $sj['style'] != SjClass::STYLE_SUPPLIER) {
- util::fail('城市供货商才能发起绑定');
- }
- $ghsSj = MerchantClass::getMerchantById($sjId);
- if (isset($ghsSj['style']) == false || $ghsSj['style'] != SjClass::STYLE_KM_SUPPLIER) {
- util::fail('请选择昆明供货商');
- }
- $count = ShopClass::getCount(['delStatus' => 0, 'merchantId' => $sjId]);
- if ($count > 1) {
- util::fail('供货商已经不止一家门店,不知道要绑供货商的哪家店,所以不能再进行绑定');
- }
- $currentShop = ShopClass::getByCondition(['merchantId' => $sjId, 'delStatus' => 0]);
- if (empty($currentShop)) {
- util::fail('没有找到门店');
- }
- $currentShopId = $currentShop['id'] ?? 0;
- $list = ShopClass::getAllByCondition(['merchantId' => $ownSjId, 'delStatus' => 0], null, '*');
- if (empty($list)) {
- util::fail('没有找到门店');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- foreach ($list as $current) {
- $ownShopId = $current['id'];
- GhsClass::build($currentShopId, $ownShopId);
- }
- $transaction->commit();
- util::complete();
- } catch (Exception $exception) {
- $transaction->rollBack();
- util::fail("绑定失败");
- }
- }
- }
|