GhsController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace pt\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\sj\classes\MerchantClass;
  6. use biz\sj\classes\SjClass;
  7. use common\components\stringUtil;
  8. use common\components\util;
  9. use Yii;
  10. class GhsController extends BaseController
  11. {
  12. public $guestAccessAction = [];
  13. //绑定供货商 shish 2021.3.29
  14. public function actionBindGhs()
  15. {
  16. $get = Yii::$app->request->get();
  17. $sjId = $get['sjId'] ?? '';
  18. $ghsSjId = $get['ghsSjId'] ?? '';
  19. if ($sjId == $ghsSjId) {
  20. util::fail('不能绑自己');
  21. }
  22. $sj = MerchantClass::getMerchantById($sjId);
  23. if (isset($sj['style']) == false || $sj['style'] != SjClass::STYLE_SUPPLIER) {
  24. util::fail('城市供货商才能发起绑定');
  25. }
  26. $ghsSj = MerchantClass::getMerchantById($ghsSjId);
  27. if (isset($ghsSj['style']) == false || $ghsSj['style'] != SjClass::STYLE_KM_SUPPLIER) {
  28. util::fail('请选择昆明供货商');
  29. }
  30. $count = ShopClass::getCount(['delStatus' => 0, 'merchantId' => $sjId]);
  31. if ($count > 1) {
  32. util::fail('发起人已经不止一家门店,不能再进行绑定');
  33. }
  34. $shop = ShopClass::getByCondition(['delStatus' => 0, 'merchantId' => $sjId]);
  35. if (empty($shop)) {
  36. util::fail('没有找到门店');
  37. }
  38. $shopId = $shop['id'] ?? 0;
  39. $count = ShopClass::getCount(['delStatus' => 0, 'merchantId' => $ghsSjId]);
  40. if ($count > 1) {
  41. util::fail('供货商已经不止一家门店,不能再进行绑定');
  42. }
  43. $ghsShop = ShopClass::getByCondition(['delStatus' => 0, 'merchantId' => $ghsSjId]);
  44. if (empty($ghsShop)) {
  45. util::fail('没有找到门店');
  46. }
  47. $ghsShopId = $ghsShop['id'] ?? 0;
  48. $has = GhsClass::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsSjId' => $ghsSjId, 'ghsShopId' => $ghsShopId]);
  49. if (!empty($has)) {
  50. util::fail('您已经绑定这个供货商了');
  51. }
  52. $name = $ghsSj['name'] ?? '';
  53. $data = [
  54. 'name' => $name,
  55. 'sjId' => $sjId,
  56. 'ghsSjId' => $ghsSjId,
  57. 'py' => stringUtil::getSpelling($name),
  58. 'shopId' => $shopId,
  59. 'ghsShopId' => $ghsShopId,
  60. ];
  61. GhsClass::addGhs($data);
  62. util::complete();
  63. }
  64. }