GhsController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 $guestAccess = [];
  13. //绑定供货商 shish 2021.3.29 !!!!!!!!!!!!!!!!!!!!!!这个方法有问题,绑了供货商,没互绑客户 todo
  14. public function actionBindGhs()
  15. {
  16. $get = Yii::$app->request->get();
  17. $ownSjId = $get['ownSjId'] ?? '';
  18. $sjId = $get['sjId'] ?? '';
  19. if ($ownSjId == $sjId) {
  20. util::fail('不能绑自己');
  21. }
  22. $sj = MerchantClass::getMerchantById($ownSjId);
  23. if (isset($sj['style']) == false || $sj['style'] != SjClass::STYLE_SUPPLIER) {
  24. util::fail('城市供货商才能发起绑定');
  25. }
  26. $ghsSj = MerchantClass::getMerchantById($sjId);
  27. if (isset($ghsSj['style']) == false || $ghsSj['style'] != SjClass::STYLE_KM_SUPPLIER) {
  28. util::fail('请选择昆明供货商');
  29. }
  30. $count = ShopClass::getCount(['delStatus' => 0, 'merchantId' => $ownSjId]);
  31. if ($count > 1) {
  32. util::fail('发起人已经不止一家门店,不能再进行绑定');
  33. }
  34. $shop = ShopClass::getByCondition(['delStatus' => 0, 'merchantId' => $ownSjId]);
  35. if (empty($shop)) {
  36. util::fail('没有找到门店');
  37. }
  38. $count = ShopClass::getCount(['delStatus' => 0, 'merchantId' => $sjId]);
  39. if ($count > 1) {
  40. util::fail('供货商已经不止一家门店,不能再进行绑定');
  41. }
  42. $currentShop = ShopClass::getByCondition(['delStatus' => 0, 'merchantId' => $sjId]);
  43. if (empty($currentShop)) {
  44. util::fail('没有找到门店');
  45. }
  46. $currentShopId = $currentShop['id'] ?? 0;
  47. $has = GhsClass::getByCondition(['ownSjId' => $ownSjId, 'sjId' => $sjId, 'shopId' => $currentShopId]);
  48. if (!empty($has)) {
  49. util::fail('您已经绑定这个供货商了');
  50. }
  51. $name = $ghsSj['name'] ?? '';
  52. $data = [
  53. 'name' => $name,
  54. 'py' => stringUtil::getSpelling($name),
  55. 'shopId' => $currentShopId,
  56. 'sjId' => $sjId,
  57. 'ownSjId' => $ownSjId,
  58. ];
  59. GhsClass::addGhs($data);
  60. util::complete();
  61. }
  62. }