MigrateData.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/9/17 16:12
  5. */
  6. namespace app\cron\controller;
  7. use app\common\model\bx\MemberModel;
  8. use app\common\model\bx\UserCouponModel;
  9. use app\common\model\sqlsev\CouponModel;
  10. use app\common\model\sqlsev\MemberCouponModel;
  11. use app\common\model\sqlsev\UserModel;
  12. use app\common\service\HelperService;
  13. /**
  14. * 数据转移
  15. * Class MigrateData
  16. * @package app\cron\controller
  17. */
  18. class MigrateData {
  19. //白熊标识
  20. const BX = '126';
  21. public function randomNum() {
  22. return date('ymdHis') . random_int(1000, 9999);
  23. }
  24. /**
  25. * 转移会员数据
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. * @throws \think\exception\DbException
  29. */
  30. public function index() {
  31. $userModel = new UserModel();
  32. $pageSize = 200;
  33. $where = ['strHQCode' => self::BX];
  34. $count = $userModel->where($where)->count();
  35. $pageNum = ceil($count / $pageSize);
  36. var_dump("共{$pageNum}页");
  37. for ($i = 1; $i <= $pageNum; $i++) {
  38. $res = $userModel->order(['intMemberID' => 'asc'])->where($where)->page($i, $pageSize)->select();
  39. $res = HelperService::object2Arr($res);
  40. foreach ($res as $v) {
  41. $data = [
  42. 'user_no' => $this->randomNum(),
  43. 'mobile' => $v['strMobilePhone'],
  44. 'name' => $v['strMemberNickName'],
  45. 'birthday' => $v['datBirthday'],
  46. 'sex' => $v['blnSex'] == 0 ? 1 : 2,
  47. 'header_img' => $v['strHeaderImg'],
  48. 'nickname' => $v['strMemberNickName'],
  49. 'add_ts' => strtotime($v['datDateTime']),
  50. 'smdd_openid' => $v['strWxXcxOpenID'],
  51. 'usable_score' => $v['intBonus'],
  52. 'total_score' => $v['intBonusCumulative'],
  53. 'other_id' => $v['strMemberCode'],
  54. 'bloc_code' => 'BAIXIONG'
  55. ];
  56. $this->insertMemberData($data);
  57. }
  58. }
  59. }
  60. /**
  61. *
  62. */
  63. public function couponData() {
  64. var_dump('先转移券的信息');
  65. $countConfigData = $this->couponConfig();
  66. var_dump('获取券的配置信息完毕');
  67. $memberCouponModel = new MemberCouponModel();
  68. $userModel = new MemberModel();
  69. $where = ['strHQCode' => self::BX];
  70. // $where['strCouponCode'] = 13;
  71. $where['strCouponCode'] = ['in', array_keys($countConfigData)];
  72. $count = $memberCouponModel->where($where)->count();
  73. $userCoupon = new UserCouponModel();
  74. $pageSize = 200;
  75. $pageNum = ceil($count / $pageSize);
  76. for ($i = 0; $i < $pageNum; $i++) {
  77. $couponList = $memberCouponModel->where($where)->order(['intMemberCouponID' => 'asc'])->page($i, $pageSize)->select();
  78. $couponList = HelperService::object2Arr($couponList);
  79. foreach ($couponList as $couponInfo) {
  80. $userNo = $userModel->where(['other_id' => $couponInfo['strMemberCode']])->value('user_no');
  81. if ($couponInfo['blnVoid'] == 0){
  82. if ($couponInfo['blnState'] == 0){
  83. $status = 1;
  84. }else{
  85. $status = 2;
  86. }
  87. }else{
  88. $status = 4;
  89. }
  90. $data = [
  91. 'user_no' => $userNo,
  92. 'coupon_id' => 13,
  93. 'start_time' => strtotime($couponInfo['datBegin']),
  94. 'end_time' => strtotime($couponInfo['datEnd']),
  95. 'use_time' => strtotime($couponInfo['datVerificationTime']),
  96. 'status' => $status,
  97. 'source_type' => 1,
  98. 'add_ts' => strtotime($couponInfo['datDateTime']),
  99. ];
  100. $userCoupon->insert($data);
  101. var_dump($userNo);
  102. }
  103. }
  104. }
  105. /**
  106. * 转移现金券的配置
  107. * @return array
  108. * @throws \think\db\exception\DataNotFoundException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. * @throws \think\exception\DbException
  111. */
  112. public function couponConfig() {
  113. $couponModel = new CouponModel();
  114. // $bxCoupon = new \app\common\model\bx\CouponModel();
  115. //select * from tabPromoConfig where strHQCode='126' and blnState=0 and strPromoMode='Coupon' and strCouponTypeCode='1001'
  116. $data = [];
  117. $couponList = $couponModel->getCoupon();
  118. foreach ($couponList as $info) {
  119. // $id = $bxCoupon->insertGetId([
  120. // 'coupon_name' => $info['strValue2'],
  121. // 'type' => $info['intValidityType'],
  122. // 'full_money' => $info['strValue'],
  123. // 'discount_money' => $info['strValue1'],
  124. // 'start_time' => strtotime($info['datBeginDate']),
  125. // 'end_time' => strtotime($info['datEndDate']),
  126. // 'receive_day' => $info['intValidityBegin'],
  127. // 'day' => $info['intValidityEnd'],
  128. // 'remark' => $info['strValue3'],
  129. // 'bloc_code' => 'BAIXIONG',
  130. // ]);
  131. $data[$info['strCode']] = 13;
  132. }
  133. return $data;
  134. }
  135. protected function insertMemberData($data = [], $num = 0) {
  136. $memberModel = new MemberModel();
  137. try {
  138. $memberModel->insert($data);
  139. } catch (\Exception $e) {
  140. var_dump($e->getMessage());
  141. if ($num > 5) {
  142. return;
  143. }
  144. $this->insertMemberData($data);
  145. }
  146. }
  147. }