GhsController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\SjClass;
  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. //添加供应商 shish 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(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  34. if (!empty($has)) {
  35. util::fail('名称已经存在');
  36. }
  37. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  38. if (!empty($has)) {
  39. util::fail('手机号已经添加过');
  40. }
  41. $connection = Yii::$app->db;
  42. $transaction = $connection->beginTransaction();
  43. try {
  44. $sjId = $this->sjId;
  45. $shopId = $this->shopId;
  46. $sjName = $this->sj->name ?? '';
  47. $address = $post['address'] ?? '';
  48. $applyData = [
  49. 'name' => $name,
  50. 'licenseNo' => $mobile,
  51. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  52. 'mobile' => $mobile,
  53. 'introSjId' => $sjId,
  54. 'introSjName' => $sjName,
  55. 'introShopId' => $shopId,
  56. 'introStyle' => SjClass::STYLE_SUPPLIER,
  57. 'from' => ApplyClass::FROM_GHS,
  58. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  59. 'address' => $address,
  60. 'status' => ApplyClass::STATUS_PASS,
  61. 'replace' => 1,//1表示供应商添加的客户或供应商
  62. ];
  63. $apply = ApplyService::replaceKmGhs($applyData);
  64. $id = $apply['id'] ?? 0;
  65. $respond = ApplyService::pass($id);
  66. $shop = $respond['shop'] ?? [];
  67. $sj = $respond['sj'] ?? [];
  68. $currentSjId = $sj['id'] ?? 0;
  69. $currentShopId = $shop->id ?? 0;
  70. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  71. if (empty($currentShopId)) {
  72. util::fail('供应商没有添加成功!');
  73. }
  74. $ghs = GhsClass::build($currentShopId, $shopId, 1);
  75. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  76. $transaction->commit();
  77. util::success($ghs);
  78. } catch (\Exception $exception) {
  79. $transaction->rollBack();
  80. Yii::info("添加供应商没有成功:" . $exception->getMessage());
  81. util::fail('添加供应商没有成功');
  82. }
  83. }
  84. //供应商列表 ssh 2021.1.18
  85. public function actionList()
  86. {
  87. $get = Yii::$app->request->get();
  88. $name = isset($get['name']) ? $get['name'] : '';
  89. $where = ['ownShopId' => $this->shopId];
  90. if (!empty($name)) {
  91. if (stringUtil::isLetter($name)) {
  92. $where['py'] = ['like', $name];
  93. } else {
  94. $where['name'] = ['like', $name];
  95. }
  96. }
  97. $list = GhsClass::getGhsList($where);
  98. util::success($list);
  99. }
  100. }