| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- namespace ghs\controllers;
- use biz\sj\classes\SjClass;
- use bizGhs\ghs\classes\GhsClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\services\ApplyService;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\orderSn;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- use bizGhs\order\classes\PurchaseOrderClass;
- class GhsController extends BaseController
- {
- //修改供货商类型 ssh 20240727
- public function actionChangeLocation()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghs = GhsClass::getById($id, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- if ($ghs->ownMainId != $this->mainId) {
- util::fail('不是你的供货商');
- }
- $newLocation = $ghs->location == 0 ? 1 :0;
- $ghs->location = $newLocation;
- $ghs->save();
- util::complete('修改成功');
- }
- public function actionModifyName()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $name = $get['name'] ?? '';
- $ghs = GhsClass::getById($id, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- if ($ghs->ownMainId != $this->mainId) {
- util::fail('不是你的供货商');
- }
- if (empty($name)) {
- util::fail('请填写名称');
- }
- if (stringUtil::getWordNum($name) > 27) {
- util::fail('名称不能超过27个汉字');
- }
- $ghs->name = $name;
- $ghs->py = stringUtil::py($name);
- $ghs->save();
- util::complete('修改成功');
- }
- //添加供货商 ssh 20210611
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $location = $post['location'] ?? '';
- $mobile = $post['mobile'] ?? '';
- $name = $post['name'] ?? '';
- if (empty($name)) {
- util::fail('名称不能为空');
- }
- if (stringUtil::getWordNum($name) > 27) {
- util::fail('名称不能超过27个汉字');
- }
- $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true);
- if (!empty($hasGhsList)) {
- foreach ($hasGhsList as $hasGhs) {
- $hasGhsName = $hasGhs->name ?? '';
- if ($hasGhsName == $name) {
- util::fail('名称已经存在了');
- }
- }
- }
- if (!empty($mobile)) {
- $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
- if (!empty($has)) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $this->shopId;
- $currentShopId = $has['shopId'] ?? 0;
- if (empty($currentShopId)) {
- util::fail('添加失败');
- }
- $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
- if (!empty($hasGhs)) {
- $name = $hasGhs->name ?? '';
- util::fail("手机已添加过了,供货商名称:【{$name}】");
- }
- $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
- $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
- $transaction->commit();
- util::success($ghs);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("添加供货商没有成功:" . $exception->getMessage());
- util::fail('添加供货商没有成功');
- }
- util::fail('添加失败,请联系管理员');
- }
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- if (empty($mobile)) {
- //获取虚拟手机号
- $mobile = orderSn::getMobileSn();
- }
- $sjId = $this->sjId;
- $shopId = $this->shopId;
- $sjName = $this->sj->name ?? '';
- $address = $post['address'] ?? '';
- $applyData = [
- 'name' => $name,
- 'licenseNo' => $mobile,
- 'certType' => ApplyClass::CERT_TYPE_MOBILE,
- 'mobile' => $mobile,
- 'introSjId' => $sjId,
- 'introSjName' => $sjName,
- 'introShopId' => $shopId,
- 'introStyle' => SjClass::STYLE_SUPPLIER,
- 'from' => ApplyClass::FROM_GHS,
- 'style' => dict::getDict('ptStyle', 'kmGhs'),
- 'address' => $address,
- 'status' => ApplyClass::STATUS_PASS,
- ];
- $apply = ApplyService::replaceKmGhs($applyData);
- $id = $apply['id'] ?? 0;
- $respond = \bizJd\apply\services\ApplyService::pass($id);
- $shop = $respond['shop'] ?? [];
- $sj = $respond['sj'] ?? [];
- $currentSjId = $sj['id'] ?? 0;
- $currentShopId = $shop->id ?? 0;
- ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
- if (empty($currentShopId)) {
- util::fail('供货商没有添加成功!');
- }
- $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
- $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
- if (is_numeric($location)) {
- //本地批发商的标记
- $ghsId = $ghs['id'] ?? 0;
- \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
- }
- $transaction->commit();
- util::success($ghs);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("添加供货商没有成功:" . $exception->getMessage());
- util::fail('添加供货商没有成功');
- }
- }
- //供货商列表 ssh 2021.1.18
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
- $where = ['ownShopId' => $this->shopId];
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $location = $get['location'] ?? '';
- if (is_numeric($location)) {
- $where['location'] = $location;
- }
- //采购限制访问,有多处要同步修改,关键词cg_limit_access
- if (getenv('YII_ENV') == 'production') {
- //纯彩花艺
- if ($this->mainId == 10) {
- if (in_array($this->adminId, [37, 988, 14346]) == false) {
- util::fail('没有数据哦4');
- }
- }
- //天天鲜花十堰店
- if ($this->mainId == 7184) {
- if (in_array($this->adminId, [8340, 8345, 9433]) == false) {
- util::fail('没有数据哦5');
- }
- }
- //小向花卉采购控制
- if ($this->mainId == 23390) {
- if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655,28521,4])) {
- util::fail('没有数据哦6');
- }
- }
- }
- $list = GhsClass::getGhsList($where);
- $staff = $this->shopAdmin;
- if (isset($staff->finance) == false || $staff->finance == 0) {
- $totalDebtAmount = 0;
- //没有财务权限的人不让看到欠款多少
- if (!empty($list['list'])) {
- foreach ($list['list'] as $key => $val) {
- $list['list'][$key]['debtAmount'] = 0;
- }
- }
- } else {
- //累计总欠款
- $totalDebtAmount = PurchaseOrderClass::sum(['mainId' => $this->mainId, 'status' => 4, 'debt' => PurchaseOrderClass::DEBT_YES], 'actPrice');
- }
- $list['totalDebtAmount'] = $totalDebtAmount;
- util::success($list);
- }
- //下载供货商 ssh 20240506
- public function actionDownloadGhs()
- {
- //$get = Yii::$app->request->get();
- $mainId = $this->mainId;
- $respond = GhsClass::getGhsFile($mainId);
- $file = $respond['file'] ?? '';
- $shortFile = $respond['shortFile'] ?? '';
- $fileUrl = Yii::$app->params['ghsHost'] . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
- }
- }
|