|
@@ -0,0 +1,158 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Author: luzheng.liu
|
|
|
+ * Time: 2020/9/17 16:12
|
|
|
+ */
|
|
|
+
|
|
|
+namespace app\cron\controller;
|
|
|
+
|
|
|
+use app\common\model\bx\MemberModel;
|
|
|
+use app\common\model\bx\UserCouponModel;
|
|
|
+use app\common\model\sqlsev\CouponModel;
|
|
|
+use app\common\model\sqlsev\MemberCouponModel;
|
|
|
+use app\common\model\sqlsev\UserModel;
|
|
|
+use app\common\service\HelperService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数据转移
|
|
|
+ * Class MigrateData
|
|
|
+ * @package app\cron\controller
|
|
|
+ */
|
|
|
+class MigrateData {
|
|
|
+
|
|
|
+ //白熊标识
|
|
|
+ const BX = '126';
|
|
|
+
|
|
|
+ public function randomNum() {
|
|
|
+ return date('ymdHis') . random_int(1000, 9999);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转移会员数据
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function index() {
|
|
|
+ $userModel = new UserModel();
|
|
|
+ $pageSize = 200;
|
|
|
+ $where = ['strHQCode' => self::BX];
|
|
|
+ $count = $userModel->where($where)->count();
|
|
|
+ $pageNum = ceil($count / $pageSize);
|
|
|
+ for ($i = 1; $i <= 1; $i++) {
|
|
|
+ $res = $userModel->order(['intMemberID' => 'asc'])->where($where)->page($i, $pageSize)->select();
|
|
|
+ $res = HelperService::object2Arr($res);
|
|
|
+ foreach ($res as $v) {
|
|
|
+ $data = [
|
|
|
+ 'user_no' => $this->randomNum(),
|
|
|
+ 'mobile' => $v['strMobilePhone'],
|
|
|
+ 'name' => $v['strMemberNickName'],
|
|
|
+ 'birthday' => $v['datBirthday'],
|
|
|
+ 'sex' => $v['blnSex'] == 0 ? 1 : 2,
|
|
|
+ 'header_img' => $v['strHeaderImg'],
|
|
|
+ 'nickname' => $v['strMemberNickName'],
|
|
|
+ 'add_ts' => strtotime($v['datDateTime']),
|
|
|
+ 'smdd_openid' => $v['strWxXcxOpenID'],
|
|
|
+ 'usable_score' => $v['intBonus'],
|
|
|
+ 'total_score' => $v['intBonusCumulative'],
|
|
|
+ 'other_id' => $v['strMemberCode']
|
|
|
+ ];
|
|
|
+ $this->insertMemberData($data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function couponData() {
|
|
|
+ var_dump('先转移券的信息');
|
|
|
+ $countConfigData = $this->couponConfig();
|
|
|
+ var_dump('获取券的配置信息完毕');
|
|
|
+ $memberCouponModel = new MemberCouponModel();
|
|
|
+ $userModel = new MemberModel();
|
|
|
+ $where = ['strHQCode' => self::BX];
|
|
|
+ $where['strCouponCode'] = ['in', array_keys($countConfigData)];
|
|
|
+ $count = $memberCouponModel->where($where)->count();
|
|
|
+ $userCoupon = new UserCouponModel();
|
|
|
+ $pageSize = 200;
|
|
|
+ $pageNum = ceil($count / $pageSize);
|
|
|
+ for ($i = 0; $i < $pageNum; $i++) {
|
|
|
+ $couponList = $memberCouponModel->where($where)->order(['intMemberCouponID' => 'asc'])->page($i, $pageSize)->select();
|
|
|
+ $couponList = HelperService::object2Arr($couponList);
|
|
|
+ foreach ($couponList as $couponInfo) {
|
|
|
+ $userNo = $userModel->where(['other_id' => $couponInfo['strMemberCode']])->value('user_no');
|
|
|
+ if ($couponInfo['blnVoid'] == 0){
|
|
|
+ if ($couponInfo['blnState'] == 0){
|
|
|
+ $status = 1;
|
|
|
+ }else{
|
|
|
+ $status = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $status = 4;
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'user_no' => $userNo,
|
|
|
+ 'coupon_id' => $countConfigData[$couponInfo['strCouponCode']],
|
|
|
+ 'start_time' => strtotime($couponInfo['datBegin']),
|
|
|
+ 'end_time' => strtotime($couponInfo['datEnd']),
|
|
|
+ 'use_time' => strtotime($couponInfo['datVerificationTime']),
|
|
|
+ 'status' => $status,
|
|
|
+ 'source_type' => 1,
|
|
|
+ 'add_ts' => strtotime($couponInfo['datDateTime']),
|
|
|
+ ];
|
|
|
+ $userCoupon->insert($data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转移现金券的配置
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function couponConfig() {
|
|
|
+ $couponModel = new CouponModel();
|
|
|
+ $bxCoupon = new \app\common\model\bx\CouponModel();
|
|
|
+ //select * from tabPromoConfig where strHQCode='126' and blnState=0 and strPromoMode='Coupon' and strCouponTypeCode='1001'
|
|
|
+ $data = [];
|
|
|
+ $couponList = $couponModel->getCoupon();
|
|
|
+ foreach ($couponList as $info) {
|
|
|
+ $id = $bxCoupon->insertGetId([
|
|
|
+ 'coupon_name' => $info['strValue2'],
|
|
|
+ 'type' => $info['intValidityType'],
|
|
|
+ 'full_money' => $info['strValue'],
|
|
|
+ 'discount_money' => $info['strValue1'],
|
|
|
+ 'start_time' => strtotime($info['datBeginDate']),
|
|
|
+ 'end_time' => strtotime($info['datEndDate']),
|
|
|
+ 'receive_day' => $info['intValidityBegin'],
|
|
|
+ 'day' => $info['intValidityEnd'],
|
|
|
+ 'remark' => $info['strValue3'],
|
|
|
+ 'bloc_code' => 'BAIXIONG',
|
|
|
+ ]);
|
|
|
+ $data[$info['strCode']] = $id;
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ protected function insertMemberData($data = [], $num = 0) {
|
|
|
+ $memberModel = new MemberModel();
|
|
|
+ try {
|
|
|
+ $memberModel->insert($data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ var_dump($e->getMessage());
|
|
|
+ if ($num > 5) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $this->insertMemberData($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|