GhsController.php 4.5 KB

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