GhsController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. use bizGhs\order\classes\PurchaseOrderClass;
  14. class GhsController extends BaseController
  15. {
  16. //修改供货商类型 ssh 20240727
  17. public function actionChangeLocation()
  18. {
  19. $get = Yii::$app->request->get();
  20. $id = $get['id'] ?? 0;
  21. $ghs = GhsClass::getById($id, true);
  22. if (empty($ghs)) {
  23. util::fail('没有找到供货商');
  24. }
  25. if ($ghs->ownMainId != $this->mainId) {
  26. util::fail('不是你的供货商');
  27. }
  28. $newLocation = $ghs->location == 0 ? 1 :0;
  29. $ghs->location = $newLocation;
  30. $ghs->save();
  31. util::complete('修改成功');
  32. }
  33. public function actionModifyName()
  34. {
  35. $get = Yii::$app->request->get();
  36. $id = $get['id'] ?? 0;
  37. $name = $get['name'] ?? '';
  38. $ghs = GhsClass::getById($id, true);
  39. if (empty($ghs)) {
  40. util::fail('没有找到供货商');
  41. }
  42. if ($ghs->ownMainId != $this->mainId) {
  43. util::fail('不是你的供货商');
  44. }
  45. if (empty($name)) {
  46. util::fail('请填写名称');
  47. }
  48. if (stringUtil::getWordNum($name) > 27) {
  49. util::fail('名称不能超过27个汉字');
  50. }
  51. $ghs->name = $name;
  52. $ghs->py = stringUtil::py($name);
  53. $ghs->save();
  54. util::complete('修改成功');
  55. }
  56. //添加供货商 ssh 20210611
  57. public function actionAdd()
  58. {
  59. $post = Yii::$app->request->post();
  60. $location = $post['location'] ?? '';
  61. $mobile = $post['mobile'] ?? '';
  62. $name = $post['name'] ?? '';
  63. if (empty($name)) {
  64. util::fail('名称不能为空');
  65. }
  66. if (stringUtil::getWordNum($name) > 27) {
  67. util::fail('名称不能超过27个汉字');
  68. }
  69. $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true);
  70. if (!empty($hasGhsList)) {
  71. foreach ($hasGhsList as $hasGhs) {
  72. $hasGhsName = $hasGhs->name ?? '';
  73. if ($hasGhsName == $name) {
  74. util::fail('名称已经存在了');
  75. }
  76. }
  77. }
  78. if (!empty($mobile)) {
  79. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  80. if (!empty($has)) {
  81. $connection = Yii::$app->db;
  82. $transaction = $connection->beginTransaction();
  83. try {
  84. $shopId = $this->shopId;
  85. $currentShopId = $has['shopId'] ?? 0;
  86. if (empty($currentShopId)) {
  87. util::fail('添加失败');
  88. }
  89. $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  90. if (!empty($hasGhs)) {
  91. $name = $hasGhs->name ?? '';
  92. util::fail("手机已添加过了,供货商名称:【{$name}】");
  93. }
  94. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  95. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  96. $transaction->commit();
  97. util::success($ghs);
  98. } catch (\Exception $exception) {
  99. $transaction->rollBack();
  100. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  101. util::fail('添加供货商没有成功');
  102. }
  103. util::fail('添加失败,请联系管理员');
  104. }
  105. }
  106. $connection = Yii::$app->db;
  107. $transaction = $connection->beginTransaction();
  108. try {
  109. if (empty($mobile)) {
  110. //获取虚拟手机号
  111. $mobile = orderSn::getMobileSn();
  112. }
  113. $sjId = $this->sjId;
  114. $shopId = $this->shopId;
  115. $sjName = $this->sj->name ?? '';
  116. $address = $post['address'] ?? '';
  117. $applyData = [
  118. 'name' => $name,
  119. 'licenseNo' => $mobile,
  120. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  121. 'mobile' => $mobile,
  122. 'introSjId' => $sjId,
  123. 'introSjName' => $sjName,
  124. 'introShopId' => $shopId,
  125. 'introStyle' => SjClass::STYLE_SUPPLIER,
  126. 'from' => ApplyClass::FROM_GHS,
  127. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  128. 'address' => $address,
  129. 'status' => ApplyClass::STATUS_PASS,
  130. ];
  131. $apply = ApplyService::replaceKmGhs($applyData);
  132. $id = $apply['id'] ?? 0;
  133. $respond = \bizJd\apply\services\ApplyService::pass($id);
  134. $shop = $respond['shop'] ?? [];
  135. $sj = $respond['sj'] ?? [];
  136. $currentSjId = $sj['id'] ?? 0;
  137. $currentShopId = $shop->id ?? 0;
  138. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  139. if (empty($currentShopId)) {
  140. util::fail('供货商没有添加成功!');
  141. }
  142. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  143. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  144. if (is_numeric($location)) {
  145. //本地批发商的标记
  146. $ghsId = $ghs['id'] ?? 0;
  147. \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
  148. }
  149. $transaction->commit();
  150. util::success($ghs);
  151. } catch (\Exception $exception) {
  152. $transaction->rollBack();
  153. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  154. util::fail('添加供货商没有成功');
  155. }
  156. }
  157. //供货商列表 ssh 2021.1.18
  158. public function actionList()
  159. {
  160. $get = Yii::$app->request->get();
  161. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  162. $where = ['ownShopId' => $this->shopId];
  163. if (!empty($name)) {
  164. if (stringUtil::isLetter($name)) {
  165. $where['py'] = ['like', $name];
  166. } else {
  167. $where['name'] = ['like', $name];
  168. }
  169. }
  170. $location = $get['location'] ?? '';
  171. if (is_numeric($location)) {
  172. $where['location'] = $location;
  173. }
  174. //采购限制访问,有多处要同步修改,关键词cg_limit_access
  175. if (getenv('YII_ENV') == 'production') {
  176. //纯彩花艺
  177. if ($this->mainId == 10) {
  178. if (in_array($this->adminId, [37, 988, 14346]) == false) {
  179. util::fail('没有数据哦4');
  180. }
  181. }
  182. //天天鲜花十堰店
  183. if ($this->mainId == 7184) {
  184. if (in_array($this->adminId, [8340, 8345, 9433]) == false) {
  185. util::fail('没有数据哦5');
  186. }
  187. }
  188. //小向花卉采购控制
  189. if ($this->mainId == 23390) {
  190. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655,28521,4])) {
  191. util::fail('没有数据哦6');
  192. }
  193. }
  194. }
  195. $list = GhsClass::getGhsList($where);
  196. $staff = $this->shopAdmin;
  197. if (isset($staff->finance) == false || $staff->finance == 0) {
  198. $totalDebtAmount = 0;
  199. //没有财务权限的人不让看到欠款多少
  200. if (!empty($list['list'])) {
  201. foreach ($list['list'] as $key => $val) {
  202. $list['list'][$key]['debtAmount'] = 0;
  203. }
  204. }
  205. } else {
  206. //累计总欠款
  207. $totalDebtAmount = PurchaseOrderClass::sum(['mainId' => $this->mainId, 'status' => 4, 'debt' => PurchaseOrderClass::DEBT_YES], 'actPrice');
  208. }
  209. $list['totalDebtAmount'] = $totalDebtAmount;
  210. util::success($list);
  211. }
  212. //下载供货商 ssh 20240506
  213. public function actionDownloadGhs()
  214. {
  215. //$get = Yii::$app->request->get();
  216. $mainId = $this->mainId;
  217. $respond = GhsClass::getGhsFile($mainId);
  218. $file = $respond['file'] ?? '';
  219. $shortFile = $respond['shortFile'] ?? '';
  220. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  221. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  222. }
  223. }