GhsController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\classes\SjClass;
  4. use bizGhs\ghs\classes\GhsClass;
  5. use bizHd\saas\classes\ApplyClass;
  6. use bizHd\saas\services\ApplyService;
  7. use common\components\dict;
  8. use common\components\imgUtil;
  9. use common\components\orderSn;
  10. use common\components\stringUtil;
  11. use Yii;
  12. use common\components\util;
  13. class GhsController extends BaseController
  14. {
  15. //添加供货商 ssh 20210611
  16. public function actionAdd()
  17. {
  18. $post = Yii::$app->request->post();
  19. $location = $post['location'] ?? '';
  20. $name = $post['name'] ?? '';
  21. if (empty($name)) {
  22. util::fail('名称不能为空');
  23. }
  24. if (stringUtil::getWordNum($name) > 8) {
  25. util::fail('名称不能超过8个汉字');
  26. }
  27. $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true);
  28. if (!empty($hasGhsList)) {
  29. foreach ($hasGhsList as $hasGhs) {
  30. $hasGhsName = $hasGhs->name ?? '';
  31. if ($hasGhsName == $name) {
  32. util::fail('名称已经存在了');
  33. }
  34. }
  35. }
  36. // $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  37. // if (!empty($has)) {
  38. //
  39. // $connection = Yii::$app->db;
  40. // $transaction = $connection->beginTransaction();
  41. // try {
  42. // $shopId = $this->shopId;
  43. // $currentShopId = $has['shopId'] ?? 0;
  44. // if (empty($currentShopId)) {
  45. // util::fail('添加失败');
  46. // }
  47. // $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  48. // if (!empty($hasGhs)) {
  49. // $name = $hasGhs->name ?? '';
  50. // util::fail("手机已添加过了,供货商名称:【{$name}】");
  51. // }
  52. // $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  53. // $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  54. // $transaction->commit();
  55. // util::success($ghs);
  56. // } catch (\Exception $exception) {
  57. // $transaction->rollBack();
  58. // Yii::info("添加供货商没有成功:" . $exception->getMessage());
  59. // util::fail('添加供货商没有成功');
  60. // }
  61. // util::fail('添加失败,请联系管理员');
  62. // }
  63. $connection = Yii::$app->db;
  64. $transaction = $connection->beginTransaction();
  65. try {
  66. //获取虚拟手机号
  67. $mobile = orderSn::getMobileSn();
  68. $sjId = $this->sjId;
  69. $shopId = $this->shopId;
  70. $sjName = $this->sj->name ?? '';
  71. $address = $post['address'] ?? '';
  72. $applyData = [
  73. 'name' => $name,
  74. 'licenseNo' => $mobile,
  75. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  76. 'mobile' => $mobile,
  77. 'introSjId' => $sjId,
  78. 'introSjName' => $sjName,
  79. 'introShopId' => $shopId,
  80. 'introStyle' => SjClass::STYLE_SUPPLIER,
  81. 'from' => ApplyClass::FROM_GHS,
  82. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  83. 'address' => $address,
  84. 'status' => ApplyClass::STATUS_PASS,
  85. ];
  86. $apply = ApplyService::replaceKmGhs($applyData);
  87. $id = $apply['id'] ?? 0;
  88. $respond = \bizJd\apply\services\ApplyService::pass($id);
  89. $shop = $respond['shop'] ?? [];
  90. $sj = $respond['sj'] ?? [];
  91. $currentSjId = $sj['id'] ?? 0;
  92. $currentShopId = $shop->id ?? 0;
  93. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  94. if (empty($currentShopId)) {
  95. util::fail('供货商没有添加成功!');
  96. }
  97. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  98. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  99. if (is_numeric($location)) {
  100. //本地批发商的标记
  101. $ghsId = $ghs['id'] ?? 0;
  102. \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
  103. }
  104. $transaction->commit();
  105. util::success($ghs);
  106. } catch (\Exception $exception) {
  107. $transaction->rollBack();
  108. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  109. util::fail('添加供货商没有成功');
  110. }
  111. }
  112. //供货商列表 ssh 2021.1.18
  113. public function actionList()
  114. {
  115. $get = Yii::$app->request->get();
  116. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  117. $where = ['ownShopId' => $this->shopId];
  118. if (!empty($name)) {
  119. if (stringUtil::isLetter($name)) {
  120. $where['py'] = ['like', $name];
  121. } else {
  122. $where['name'] = ['like', $name];
  123. }
  124. }
  125. $location = $get['location'] ?? '';
  126. if (is_numeric($location)) {
  127. $where['location'] = $location;
  128. }
  129. $list = GhsClass::getGhsList($where);
  130. util::success($list);
  131. }
  132. }