123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?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);
- var_dump("共{$pageNum}页");
- for ($i = 1; $i <= $pageNum; $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'],
- 'bloc_code' => 'BAIXIONG'
- ];
- $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();
- var_dump($couponList);
- die();
- 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();
- // $where = ['mobile' => $data['mobile'], 'bloc_code' => $data['bloc_code']];
- // $rs = $memberModel->where($where)->find();
- // if (!empty($rs)) {
- //// $memberModel->where($where)->delete();
- // var_dump('存在'.$data['mobile']);
- // return;
- // }
- try {
- $rs = $memberModel->insert($data);
- var_dump($data['mobile']);
- if(!empty($rs)){
- var_dump($data['mobile']."成功");
- }
- } catch (\Exception $e) {
- var_dump($e->getMessage());
- if (strpos($e->getMessage(),'idx_mobile')){
- var_dump('无需处理');
- return;
- }else{
- $data['user_no'] = $this->randomNum();
- $this->insertMemberData($data);
- }
- }
- }
- }
|