MigrateData.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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'] = ['in', array_keys($countConfigData)];
  71. $count = $memberCouponModel->where($where)->count();
  72. $userCoupon = new UserCouponModel();
  73. $pageSize = 200;
  74. $pageNum = ceil($count / $pageSize);
  75. for ($i = 0; $i < $pageNum; $i++) {
  76. $couponList = $memberCouponModel->where($where)->order(['intMemberCouponID' => 'asc'])->page($i, $pageSize)->select();
  77. $couponList = HelperService::object2Arr($couponList);
  78. foreach ($couponList as $couponInfo) {
  79. $userNo = $userModel->where(['other_id' => $couponInfo['strMemberCode']])->value('user_no');
  80. if ($couponInfo['blnVoid'] == 0){
  81. if ($couponInfo['blnState'] == 0){
  82. $status = 1;
  83. }else{
  84. $status = 2;
  85. }
  86. }else{
  87. $status = 4;
  88. }
  89. $data = [
  90. 'user_no' => $userNo,
  91. 'coupon_id' => $countConfigData[$couponInfo['strCouponCode']],
  92. 'start_time' => strtotime($couponInfo['datBegin']),
  93. 'end_time' => strtotime($couponInfo['datEnd']),
  94. 'use_time' => strtotime($couponInfo['datVerificationTime']),
  95. 'status' => $status,
  96. 'source_type' => 1,
  97. 'add_ts' => strtotime($couponInfo['datDateTime']),
  98. ];
  99. $userCoupon->insert($data);
  100. }
  101. }
  102. }
  103. /**
  104. * 转移现金券的配置
  105. * @return array
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. */
  110. public function couponConfig() {
  111. $couponModel = new CouponModel();
  112. $bxCoupon = new \app\common\model\bx\CouponModel();
  113. //select * from tabPromoConfig where strHQCode='126' and blnState=0 and strPromoMode='Coupon' and strCouponTypeCode='1001'
  114. $data = [];
  115. $couponList = $couponModel->getCoupon();
  116. var_dump($couponList);
  117. die();
  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']] = $id;
  132. }
  133. return $data;
  134. }
  135. protected function insertMemberData($data = [], $num = 0) {
  136. $memberModel = new MemberModel();
  137. // $where = ['mobile' => $data['mobile'], 'bloc_code' => $data['bloc_code']];
  138. // $rs = $memberModel->where($where)->find();
  139. // if (!empty($rs)) {
  140. //// $memberModel->where($where)->delete();
  141. // var_dump('存在'.$data['mobile']);
  142. // return;
  143. // }
  144. try {
  145. $rs = $memberModel->insert($data);
  146. var_dump($data['mobile']);
  147. if(!empty($rs)){
  148. var_dump($data['mobile']."成功");
  149. }
  150. } catch (\Exception $e) {
  151. var_dump($e->getMessage());
  152. if (strpos($e->getMessage(),'idx_mobile')){
  153. var_dump('无需处理');
  154. return;
  155. }else{
  156. $data['user_no'] = $this->randomNum();
  157. $this->insertMemberData($data);
  158. }
  159. }
  160. }
  161. }