GhsController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\stringUtil;
  10. use Yii;
  11. use common\components\util;
  12. class GhsController extends BaseController
  13. {
  14. //添加供货商 ssh 20210611
  15. public function actionAdd()
  16. {
  17. $post = Yii::$app->request->post();
  18. $mobile = $post['mobile'] ?? '';
  19. $confirmMobile = $post['confirmMobile'];
  20. if (stringUtil::isMobile($mobile) == false) {
  21. util::fail(' 请填写正确的手机号');
  22. }
  23. if ($mobile != $confirmMobile) {
  24. util::fail('二次号码填写不一致');
  25. }
  26. $name = $post['name'] ?? '';
  27. if (empty($name)) {
  28. util::fail('名称不能为空');
  29. }
  30. if (stringUtil::getWordNum($name) > 8) {
  31. util::fail('名称不能超过8个汉字');
  32. }
  33. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  34. if (!empty($has)) {
  35. $connection = Yii::$app->db;
  36. $transaction = $connection->beginTransaction();
  37. try {
  38. $shopId = $this->shopId;
  39. $currentShopId = $has['shopId'] ?? 0;
  40. if (empty($currentShopId)) {
  41. util::fail('添加失败');
  42. }
  43. $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  44. if (!empty($hasGhs)) {
  45. $name = $hasGhs->name ?? '';
  46. util::fail("手机已添加过了,供货商名称:【{$name}】");
  47. }
  48. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  49. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  50. $transaction->commit();
  51. util::success($ghs);
  52. } catch (\Exception $exception) {
  53. $transaction->rollBack();
  54. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  55. util::fail('添加供货商没有成功');
  56. }
  57. util::fail('添加失败,请联系管理员');
  58. }
  59. $connection = Yii::$app->db;
  60. $transaction = $connection->beginTransaction();
  61. try {
  62. $sjId = $this->sjId;
  63. $shopId = $this->shopId;
  64. $sjName = $this->sj->name ?? '';
  65. $address = $post['address'] ?? '';
  66. $applyData = [
  67. 'name' => $name,
  68. 'licenseNo' => $mobile,
  69. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  70. 'mobile' => $mobile,
  71. 'introSjId' => $sjId,
  72. 'introSjName' => $sjName,
  73. 'introShopId' => $shopId,
  74. 'introStyle' => SjClass::STYLE_SUPPLIER,
  75. 'from' => ApplyClass::FROM_GHS,
  76. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  77. 'address' => $address,
  78. 'status' => ApplyClass::STATUS_PASS,
  79. ];
  80. $apply = ApplyService::replaceKmGhs($applyData);
  81. $id = $apply['id'] ?? 0;
  82. $respond = \bizJd\apply\services\ApplyService::pass($id);
  83. $shop = $respond['shop'] ?? [];
  84. $sj = $respond['sj'] ?? [];
  85. $currentSjId = $sj['id'] ?? 0;
  86. $currentShopId = $shop->id ?? 0;
  87. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  88. if (empty($currentShopId)) {
  89. util::fail('供货商没有添加成功!');
  90. }
  91. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  92. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  93. $transaction->commit();
  94. util::success($ghs);
  95. } catch (\Exception $exception) {
  96. $transaction->rollBack();
  97. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  98. util::fail('添加供货商没有成功');
  99. }
  100. }
  101. //供货商列表 ssh 2021.1.18
  102. public function actionList()
  103. {
  104. $get = Yii::$app->request->get();
  105. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  106. $where = ['ownShopId' => $this->shopId];
  107. if (!empty($name)) {
  108. if (stringUtil::isLetter($name)) {
  109. $where['py'] = ['like', $name];
  110. } else {
  111. $where['name'] = ['like', $name];
  112. }
  113. }
  114. $list = GhsClass::getGhsList($where);
  115. util::success($list);
  116. }
  117. }