GhsController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  28. // if (!empty($has)) {
  29. //
  30. // $connection = Yii::$app->db;
  31. // $transaction = $connection->beginTransaction();
  32. // try {
  33. // $shopId = $this->shopId;
  34. // $currentShopId = $has['shopId'] ?? 0;
  35. // if (empty($currentShopId)) {
  36. // util::fail('添加失败');
  37. // }
  38. // $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  39. // if (!empty($hasGhs)) {
  40. // $name = $hasGhs->name ?? '';
  41. // util::fail("手机已添加过了,供货商名称:【{$name}】");
  42. // }
  43. // $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  44. // $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  45. // $transaction->commit();
  46. // util::success($ghs);
  47. // } catch (\Exception $exception) {
  48. // $transaction->rollBack();
  49. // Yii::info("添加供货商没有成功:" . $exception->getMessage());
  50. // util::fail('添加供货商没有成功');
  51. // }
  52. // util::fail('添加失败,请联系管理员');
  53. // }
  54. $connection = Yii::$app->db;
  55. $transaction = $connection->beginTransaction();
  56. try {
  57. //获取虚拟手机号
  58. $mobile = orderSn::getMobileSn();
  59. $sjId = $this->sjId;
  60. $shopId = $this->shopId;
  61. $sjName = $this->sj->name ?? '';
  62. $address = $post['address'] ?? '';
  63. $applyData = [
  64. 'name' => $name,
  65. 'licenseNo' => $mobile,
  66. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  67. 'mobile' => $mobile,
  68. 'introSjId' => $sjId,
  69. 'introSjName' => $sjName,
  70. 'introShopId' => $shopId,
  71. 'introStyle' => SjClass::STYLE_SUPPLIER,
  72. 'from' => ApplyClass::FROM_GHS,
  73. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  74. 'address' => $address,
  75. 'status' => ApplyClass::STATUS_PASS,
  76. ];
  77. $apply = ApplyService::replaceKmGhs($applyData);
  78. $id = $apply['id'] ?? 0;
  79. $respond = \bizJd\apply\services\ApplyService::pass($id);
  80. $shop = $respond['shop'] ?? [];
  81. $sj = $respond['sj'] ?? [];
  82. $currentSjId = $sj['id'] ?? 0;
  83. $currentShopId = $shop->id ?? 0;
  84. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  85. if (empty($currentShopId)) {
  86. util::fail('供货商没有添加成功!');
  87. }
  88. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  89. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  90. if (is_numeric($location)) {
  91. //本地批发商的标记
  92. $ghsId = $ghs['id'] ?? 0;
  93. \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
  94. }
  95. $transaction->commit();
  96. util::success($ghs);
  97. } catch (\Exception $exception) {
  98. $transaction->rollBack();
  99. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  100. util::fail('添加供货商没有成功');
  101. }
  102. }
  103. //供货商列表 ssh 2021.1.18
  104. public function actionList()
  105. {
  106. $get = Yii::$app->request->get();
  107. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  108. $where = ['ownShopId' => $this->shopId];
  109. if (!empty($name)) {
  110. if (stringUtil::isLetter($name)) {
  111. $where['py'] = ['like', $name];
  112. } else {
  113. $where['name'] = ['like', $name];
  114. }
  115. }
  116. $list = GhsClass::getGhsList($where);
  117. util::success($list);
  118. }
  119. }