Browse Source

feat(转移数据):转移会员数据,券数据完毕

geek 4 years ago
parent
commit
78ba18b547

+ 32 - 0
application/common/model/bx/BxModel.php

@@ -0,0 +1,32 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/18 15:13
+ */
+
+namespace app\common\model\bx;
+
+
+use think\Model;
+
+class BxModel extends Model {
+
+    protected $connection = [
+        // 数据库类型
+        'type'           => 'mysql',
+        // 服务器地址
+        'hostname'       => '180.166.104.67',
+        // 数据库名
+        'database'       => 'bx',
+        // 用户名
+        'username'       => 'member_org',
+        // 密码
+        'password'       => 'A06af7cDfa6b970ef0A9db915Fa5a237',
+        // 端口
+        'hostport'       => '5904',
+        // 连接dsn
+        'charset'        => 'utf8',
+        'debug'          => true,
+        'resultset_type' => 'array'
+    ];
+}

+ 13 - 0
application/common/model/bx/CouponModel.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/21 10:46
+ */
+
+namespace app\common\model\bx;
+
+
+class CouponModel extends BxModel {
+
+    protected $table = 'coupon';
+}

+ 12 - 0
application/common/model/bx/MemberModel.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/18 09:59
+ */
+namespace app\common\model\bx;
+
+class MemberModel extends BxModel {
+
+    protected $table = 'user';
+
+}

+ 13 - 0
application/common/model/bx/UserCouponModel.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/21 10:47
+ */
+
+namespace app\common\model\bx;
+
+
+class UserCouponModel extends BxModel {
+
+    protected $table = 'user_coupon';
+}

+ 44 - 0
application/common/model/sqlsev/CouponModel.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/18 18:01
+ */
+
+namespace app\common\model\sqlsev;
+
+
+use app\common\service\HelperService;
+use app\cron\controller\MigrateData;
+
+class CouponModel extends sqlSerModel {
+
+    protected $table = 'tabPromoConfig';
+
+
+    //select * from tabPromoConfig where strHQCode='126' and blnState=0 and strPromoMode='Coupon' and strCouponTypeCode='1001'
+    /**
+     * 获取现金券
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function getCoupon() {
+        $rs = $this->where(['strHQCode' => MigrateData::BX, 'blnState' => 0, 'strPromoMode' => 'Coupon', 'strCouponTypeCode' => 1001,
+        ])->order(['intPromoConfigID' => 'asc'])->select();
+        return HelperService::object2Arr($rs);
+    }
+
+    /**
+     * 获取产品券
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function getProductCoupon() {
+        $rs = $this->where(['strHQCode' => MigrateData::BX, 'blnState' => 0, 'strPromoMode' => 'Coupon', 'strCouponTypeCode' => 1002,
+        ])->order(['intPromoConfigID' => 'asc'])->select();
+        return HelperService::object2Arr($rs);
+    }
+}

+ 13 - 0
application/common/model/sqlsev/MemberCouponModel.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/18 15:11
+ */
+
+namespace app\common\model\sqlsev;
+
+
+class MemberCouponModel extends sqlSerModel {
+
+    protected $table = 'tabMemberCoupon';
+}

+ 13 - 0
application/common/model/sqlsev/UserModel.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/17 16:38
+ */
+namespace app\common\model\sqlsev;
+
+use think\Model;
+class UserModel extends sqlSerModel {
+
+    protected $table = 'tabMemberInfo';
+
+}

+ 35 - 0
application/common/model/sqlsev/sqlSerModel.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/18 15:07
+ */
+
+namespace app\common\model\sqlsev;
+
+
+use think\Model;
+
+class sqlSerModel extends Model {
+
+
+    protected $connection = [
+        // 数据库类型
+        'type'            => 'sqlsrv',
+        // 服务器地址
+        'hostname'        => '47.100.235.34',
+        // 数据库名
+        'database'        => 'HQDB',
+        // 用户名
+        'username'        => 'member_system',
+        // 密码
+        'password'        => 'AbcKeqin891107@163.com',
+        // 端口
+        'hostport'        => '8989',
+        // 连接dsn
+        'charset'         => 'utf8',
+        'debug'           => true,
+        'resultset_type'  => 'array',
+        // 自动写入时间戳字段
+
+    ];
+}

+ 158 - 0
application/cron/controller/MigrateData.php

@@ -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);
+        }
+
+    }
+
+
+}
+

+ 12 - 0
application/cron/controller/Test.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/9/17 16:26
+ */
+namespace app\cron\controller;
+class Test extends \think\Controller {
+    public function index() {
+        var_dump(111);
+
+ }
+}