XinHongTai.Class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: phperstar
  5. * Date: 2021/4/28
  6. * Time: 3:54 PM
  7. */
  8. namespace Jindouyun\Controller\Common;
  9. use JinDouYun\Cache\SysAreaChinaCache;
  10. use Jindouyun\Model\Customer\MCustomer;
  11. use Jindouyun\Model\Goods\MQuickGoods;
  12. use Jindouyun\Model\GoodsCategory\MGoodsCategory;
  13. use JinDouYun\Model\Commission\MCommissionBusinessman;
  14. use Jindouyun\Dao\Customer\DCustomer;
  15. use Jindouyun\Dao\Goods\DGoods;
  16. use Mall\Framework\Core\StatusCode;
  17. class XinHongTai
  18. {
  19. /**
  20. * 导入客户数据
  21. */
  22. public function customer()
  23. {
  24. $objSysAreaChinaCache = new SysAreaChinaCache();
  25. $objDCustomer = new DCustomer('old');
  26. $objMCustomer = new MCustomer(1, 1);
  27. // 查询会员表获取客户信息
  28. $sql = 'select count(*) as total from ims_ewei_shop_member';
  29. $result = $objDCustomer->query($sql);
  30. // 查询会员表获取客户信息
  31. $sql = 'select id,mobile,realname,nickname,isblack,avatar,content,createtime,province,city,area,openid from ims_ewei_shop_member where id < 2 order by id DESC';
  32. $result = $objDCustomer->query($sql);
  33. foreach ($result as $key => $value){
  34. $customerData = [
  35. 'id' => $value['id'],
  36. 'mobile' => ($value['mobile']) ? : time().substr(microtime(),2,1),
  37. 'name' => (!empty($value['realname'])) ? $value['realname'] : $value['nickname'],
  38. 'type' => 3, // 默认散户
  39. 'enableStatus' => ($value['isblack']) ? 4 : 5, // 老系统黑名单 新系统禁用
  40. 'avatar' => $value['avatar'],
  41. 'remark' => $value['content'],
  42. 'createTime' => $value['createtime'],
  43. 'provinceCode' => $objSysAreaChinaCache->getCodeByName($value['province']),
  44. 'cityCode' => $objSysAreaChinaCache->getCodeByName($value['city']),
  45. 'districtCode' => ($value['area']) ? $objSysAreaChinaCache->getCodeByName($value['area']) : 0,
  46. 'contact' => [],
  47. ];
  48. // 查询收货地址
  49. $sql = 'select * from ims_ewei_shop_member_address where deleted = 0 and openid = '.$value['openid'].' order by id DESC limit 1 ';
  50. $result = $objDCustomer->query($sql);
  51. if(!empty($result)){
  52. $customerData['name'] = $result[0]['realname'];
  53. $customerData['mobile'] = $result[0][''];
  54. $customerData['provinceCode'] = $objSysAreaChinaCache->getCodeByName($result[0]['province']);
  55. $customerData['cityCode'] = $objSysAreaChinaCache->getCodeByName($result[0]['city']);
  56. $customerData['districtCode'] = $objSysAreaChinaCache->getCodeByName($result[0]['area']);
  57. $customerData['address'] = $result[0]['address'];
  58. $customerData['contact']['name'] = $result[0]['realname'];
  59. $customerData['contact']['mobile'] = $result[0][''];
  60. $customerData['contact']['provinceCode'] = $objSysAreaChinaCache->getCodeByName($result[0]['province']);
  61. $customerData['contact']['cityCode'] = $objSysAreaChinaCache->getCodeByName($result[0]['city']);
  62. $customerData['contact']['districtCode'] = $objSysAreaChinaCache->getCodeByName($result[0]['area']);
  63. $customerData['contact']['address'] = $result[0]['address'];
  64. }
  65. $result = $objMCustomer->addCustomer($customerData);
  66. if(!$result->isSuccess()){
  67. echo $result->getData();
  68. exit();
  69. }
  70. echo $value['id'].'迁移客户数据完成'.PHP_EOL;
  71. //sleep(1);
  72. }
  73. }
  74. /**
  75. * 迁移分销关系
  76. */
  77. public function commission()
  78. {
  79. $objDCustomer = new DCustomer('old');
  80. $objMCommissionBusinessman = new MCommissionBusinessman(1, 1);
  81. // 查询会员表获取客户信息
  82. $sql = 'select id,mobile,realname,nickname,isblack,avatar,content,createtime,province,city,area,openid,agentid from ims_ewei_shop_member where id > 16168 order by id asc';
  83. $result = $objDCustomer->query($sql);
  84. $objDCustomer = new DCustomer('default');
  85. foreach ($result as $key => $value){
  86. // 没有推荐人不做处理
  87. if($value['agentid'] == 0){
  88. continue;
  89. }
  90. // 上级客户信息
  91. $sql = 'select * from qianniao_customer_1 where id = '.$value['agentid'];
  92. $customerData = $objDCustomer->query($sql);
  93. if($customerData === false){
  94. echo $objDCustomer->error().PHP_EOL;
  95. exit();
  96. }
  97. if(empty($customerData)){
  98. echo $value['agentid'].'获取上级代理信息为空'.PHP_EOL;
  99. continue;
  100. }
  101. echo $value['agentid'].'准备创建分销商'.PHP_EOL;
  102. // 先把推荐人申请成为分销商
  103. $businessman = [
  104. 'customerId' => $value['agentid'],
  105. 'gradeId' => 1,
  106. 'grade' => 0,
  107. ];
  108. $result = $objMCommissionBusinessman->addBusinessman($businessman);
  109. if(!$result->isSuccess()){
  110. if($result->getData() != '该客户已经是分销商'){
  111. echo $result->getData().PHP_EOL;
  112. exit();
  113. }else{
  114. echo $result->getData().PHP_EOL;
  115. }
  116. }
  117. echo $value['agentid'].'成为分销商成功'.PHP_EOL;
  118. // 要绑定客户信息
  119. $sql = 'select * from qianniao_customer_1 where id = '.$value['id'];
  120. $customerData = $objDCustomer->query($sql);
  121. if($customerData === false){
  122. echo $objDCustomer->error().PHP_EOL;
  123. exit();
  124. }
  125. if(empty($customerData)){
  126. echo $value['agentid'].'获取绑定客户信息为空'.PHP_EOL;
  127. continue;
  128. }
  129. // 绑定当前用户和分销商的关系
  130. $data = [
  131. 'businessmanId' => $value['agentid'],
  132. 'source' => 1,
  133. ];
  134. $objMCommissionBusinessman = new MCommissionBusinessman(1, $customerData[0]['userCenterId']);
  135. $result = $objMCommissionBusinessman->relationshipBusinessman($data);
  136. if(!$result->isSuccess()){
  137. echo $result->getData().PHP_EOL;
  138. exit();
  139. }
  140. echo $value['agentid'].' 创建分销商成功,'.$value['id'].' 和分销商绑定关系完成'.PHP_EOL;
  141. }
  142. }
  143. /**
  144. * 分类
  145. */
  146. public function category()
  147. {
  148. $objDGoods = new DGoods('old');
  149. $objMGoodsCategory = new MGoodsCategory(1,1);
  150. // 查询商品表获取商品信息
  151. $sql = 'select * from ims_ewei_shop_category';
  152. $result = $objDGoods->query($sql);
  153. foreach ($result as $key => $value){
  154. $categoryData = [
  155. 'title' => $value['name'],
  156. 'sort' => $value['displayorder'],
  157. 'images' => 'https://xinhongtai168.com/attachment/'.$value['advimg'],
  158. ];
  159. $result = $objMGoodsCategory->addCategory($categoryData);
  160. if(!$result->isSuccess()){
  161. echo $result->getData();
  162. exit();
  163. }
  164. echo $value['id'].'迁移商品分类数据完成'.PHP_EOL;
  165. }
  166. }
  167. /**
  168. * 商品资料
  169. */
  170. public function goods()
  171. {
  172. $objDGoods = new DGoods('old');
  173. $objMQuickGoods = new MQuickGoods(1,1);
  174. // 查询商品表获取商品信息
  175. $sql = 'select id,title,cates,thumb_url,thumb,marketprice,productprice,content,subtitle,keywords,displayorder,status from ims_ewei_shop_goods where id < 1435 order by id desc ';
  176. $result = $objDGoods->query($sql);
  177. foreach ($result as $key => $value){
  178. // 处理商品分类
  179. $cates = explode(',', $value['cates']);
  180. $categoryId = array_shift($cates);
  181. $assistCategoryId = 0;
  182. $assistCategoryPath = [];
  183. if(!empty($cates)){
  184. $assistCategoryId = implode(',', $cates);
  185. $assistCategoryPath = $cates;
  186. }
  187. // 处理图片
  188. $thumb_url = ($value['thumb_url']) ? unserialize($value['thumb_url']) : [];
  189. $thumb = ($value['thumb']) ? [$value['thumb']] : [];
  190. $image = array_merge($thumb,$thumb_url);
  191. if(!empty($image)){
  192. foreach ($image as $k => $v){
  193. $image[$k] = 'https://xinhongtai168.com/attachment/'.$v;
  194. }
  195. }
  196. $goodsData = [
  197. 'createUserName' => '老系统迁移',
  198. 'merchantId' => 0,
  199. 'specGroup' => json_encode([]),
  200. 'notArea' => json_encode(''),
  201. 'link' => '',
  202. 'barCode' => '',
  203. 'expireTime' => 0,
  204. 'brandId' => 0,
  205. 'title' => $value['title'],
  206. 'categoryId' => ($categoryId) ? $categoryId : 0,
  207. 'categoryPath' => $categoryId,
  208. 'assistCategoryId' => $assistCategoryId,
  209. 'assistCategoryPath' => json_encode($assistCategoryPath),
  210. 'images' => json_encode($image),
  211. 'shopId' => 1,
  212. 'shopName' => '鑫弘泰食品商城',
  213. 'specType' => 1,
  214. 'specMultiple' => [
  215. [
  216. 'barCode' => '',
  217. 'weight' => '',
  218. 'isDefault' => 5,
  219. 'unitId' => 1,
  220. 'unitName' => '件',
  221. 'isMaster' => 5,
  222. 'conversion' => '0.00',
  223. 'specImage' => '',
  224. 'specGroup' => [],
  225. 'salePrice' =>[
  226. 'conversion' => '0.00',
  227. 'unitName' => '件',
  228. 'unitId' => 1,
  229. 'isMaster' => 5,
  230. 'deleteStatus' => 4,
  231. 'enabledLadder' => 0,
  232. 'salePriceAreaType' => 1,
  233. 'salePrice' => $value['marketprice'],
  234. 'ladderPrice' => [],
  235. 'marketPrice' => $value['productprice'],
  236. 'setNum' => 1,
  237. ],
  238. 'customerTypePrice' => [],
  239. 'customerPrice' => []
  240. ]
  241. ],
  242. 'isStore' => false,
  243. 'description' => $value['content'],
  244. 'describe' => $value['subtitle'],
  245. 'tag' => $value['keywords'],
  246. 'sort' => $value['displayorder'],
  247. 'enableStatus' => ($value['status']) ? StatusCode::$standard : StatusCode::$delete,
  248. 'noSalesShop' => '',
  249. ];
  250. $result = $objMQuickGoods->addBasicAndPublishGoods($goodsData);
  251. if(!$result->isSuccess()){
  252. echo $result->getData();
  253. exit();
  254. }
  255. echo $value['id'].'商品数据完成'.PHP_EOL;
  256. }
  257. }
  258. }