CustomClass.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace bizGhs\custom\classes;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\sj\classes\MerchantClass;
  6. use biz\sj\classes\SjClass;
  7. use common\components\business;
  8. use common\components\imgUtil;
  9. use common\components\util;
  10. use Yii;
  11. use bizHd\base\classes\BaseClass;
  12. class CustomClass extends BaseClass
  13. {
  14. public static $baseFile = '\bizGhs\custom\models\Custom';
  15. //申请开店建立客户关系 ssh 2021.2.28
  16. //GhsClass::build()也有相似流程
  17. public static function buildCustom($applyData, $sjId, $shopId)
  18. {
  19. if ($applyData['style'] == SjClass::STYLE_RETAIL) {
  20. if ($applyData['introStyle'] == SjClass::STYLE_SUPPLIER) {
  21. $has = CustomClass::getByCondition(['ownSjId' => $applyData['introSjId'], 'sjId' => $sjId, 'shopId' => $shopId]);
  22. if (empty($has)) {
  23. $customData = [
  24. 'sjId' => $sjId,//零售商家id
  25. 'shopId' => $shopId,//零售门店id
  26. 'ownSjId' => $applyData['introSjId'],//供货商id
  27. 'name' => $applyData['name'],
  28. 'mobile' => $applyData['mobile'],
  29. 'province' => $applyData['province'] ?? '',
  30. 'city' => $applyData['city'] ?? '',
  31. 'dist' => $applyData['dist'] ?? '',
  32. 'address' => $applyData['address'] ?? '',
  33. 'fullAddress' => $applyData['fullAddress'],
  34. 'long' => $applyData['long'],
  35. 'lat' => $applyData['lat'],
  36. ];
  37. CustomClass::addCustom($customData);
  38. }
  39. $introShopId = $applyData['introShopId'] ?? 0;
  40. $ghsShop = ShopClass::getShopInfo($introShopId);
  41. if (empty($ghsShop)) {
  42. util::fail('没有找到门店');
  43. }
  44. $ghs = GhsClass::getByCondition(['ownSjId' => $sjId, 'sjId' => $ghsShop['merchantId'], 'shopId' => $ghsShop['id']]);
  45. if (empty($ghs)) {
  46. $ghsData = [
  47. 'sjId' => $ghsShop['merchantId'],
  48. 'shopId' => $ghsShop['id'],
  49. 'ownSjId' => $sjId,
  50. 'ownShopId' => $sjId,
  51. 'mobile' => $ghsShop['mobile'] ?? '',
  52. 'province' => $ghsShop['province'] ?? '',
  53. 'city' => $ghsShop['city'] ?? '',
  54. 'dist' => $ghsShop['dist'] ?? '',
  55. 'address' => $ghsShop['address'] ?? '',
  56. 'floor' => $ghsShop['floor'] ?? '',
  57. 'fullAddress' => $ghsShop['fullAddress'] ?? '',
  58. 'lat' => $ghsShop['lat'] ?? '',
  59. 'long' => $ghsShop['long'] ?? '',
  60. ];
  61. GhsClass::addGhs($ghsData);
  62. }
  63. }
  64. }
  65. if ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
  66. if ($applyData['introStyle'] == SjClass::STYLE_RETAIL) {
  67. $has = CustomClass::getByCondition(['ownSjId' => $sjId, 'sjId' => $applyData['introSjId'], 'shopId' => $applyData['introShopId']]);
  68. $introSjId = $applyData['introSjId'] ?? 0;
  69. $introShopId = $applyData['introShopId'] ?? 0;
  70. if (empty($has)) {
  71. $shop = ShopClass::getShopInfo($introShopId);
  72. $name = $shop['shopName'] ?? '';
  73. $super = ShopClass::getSuper($introShopId);
  74. $mobile = $super['mobile'] ?? '';
  75. $customData = [
  76. 'sjId' => $introSjId,//零售商id
  77. 'shopId' => $introShopId,//零售门店id
  78. 'ownSjId' => $sjId,//供货商id
  79. 'name' => $name,
  80. 'mobile' => $mobile,
  81. 'isOpen' => 1,
  82. 'province' => $applyData['province'] ?? '',
  83. 'city' => $applyData['city'] ?? '',
  84. 'dist' => $applyData['dist'] ?? '',
  85. 'address' => $applyData['address'] ?? '',
  86. 'fullAddress' => $applyData['fullAddress'],
  87. 'long' => $applyData['long'],
  88. 'lat' => $applyData['lat'],
  89. ];
  90. CustomClass::addCustom($customData);
  91. }
  92. $ghsShop = ShopClass::getShopInfo($shopId);
  93. if (empty($ghsShop)) {
  94. util::fail('没有找到门店');
  95. }
  96. $ghs = GhsClass::getByCondition(['ownSjId' => $introSjId, 'sjId' => $sjId, 'shopId' => $shopId]);
  97. dd($ghs);
  98. if (empty($ghs)) {
  99. $ghsData = [
  100. 'sjId' => $sjId,
  101. 'shopId' => $shopId,
  102. 'ownSjId' => $introSjId,
  103. 'ownShopId' => $introShopId,
  104. 'mobile' => $ghsShop['mobile'] ?? '',
  105. 'province' => $ghsShop['province'] ?? '',
  106. 'city' => $ghsShop['city'] ?? '',
  107. 'dist' => $ghsShop['dist'] ?? '',
  108. 'address' => $ghsShop['address'] ?? '',
  109. 'floor' => $ghsShop['floor'] ?? '',
  110. 'fullAddress' => $ghsShop['fullAddress'] ?? '',
  111. 'lat' => $ghsShop['lat'] ?? '',
  112. 'long' => $ghsShop['long'] ?? '',
  113. ];
  114. GhsClass::addGhs($ghsData);
  115. }
  116. }
  117. }
  118. }
  119. //添加客户 ssh 2021.2.24
  120. public static function addCustom($data)
  121. {
  122. return self::add($data);
  123. }
  124. //获取客户信息 ssh 2021.2.4
  125. public static function getCustom($id)
  126. {
  127. $info = self::getById($id);
  128. if (empty($info)) {
  129. return $info;
  130. }
  131. $respond = self::groupBaseInfo([$info]);
  132. return current($respond);
  133. }
  134. public static function getCustomByIds($ids)
  135. {
  136. $list = self::getByIds($ids, null, 'id');
  137. return self::groupBaseInfo($list);
  138. }
  139. //整合头像等信息 ssh 2021.1.8
  140. public static function groupBaseInfo($list)
  141. {
  142. if (empty($list)) {
  143. return $list;
  144. }
  145. //获取客户信息
  146. $customSjIdList = array_unique(array_filter(array_column($list, 'sjId')));
  147. $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
  148. foreach ($list as $key => $val) {
  149. $customSjId = $val['sjId'];
  150. $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
  151. $currentInfo = business::formatMerchantLogo($currentInfo);
  152. $smallAvatar = !empty($currentInfo['smallLogoUrl']) ? $currentInfo['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  153. $avatar = !empty($currentInfo['logoUrl']) ? $currentInfo['logoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  154. $list[$key]['smallAvatar'] = $smallAvatar;
  155. $list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
  156. $list[$key]['avatar'] = $avatar;
  157. $list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
  158. $list[$key]['visitTime'] = '03-20 12:00';
  159. $list[$key]['level'] = 0;
  160. $list[$key]['sn'] = $val['id'];
  161. }
  162. return $list;
  163. }
  164. //欠款权限开关 ssh 2021.1.8
  165. public static function debt($custom, $debt)
  166. {
  167. $id = isset($custom['id']) ? $custom['id'] : 0;
  168. self::updateById($id, ['debt' => $debt]);
  169. return true;
  170. }
  171. //权限判断 ssh 2021.1.8
  172. public static function valid($custom, $merchantId)
  173. {
  174. if (empty($custom)) {
  175. util::fail('没有找到客户');
  176. }
  177. if ($custom['ownSjId'] != $merchantId) {
  178. util::fail('您没有权限操作此客户');
  179. }
  180. }
  181. }