123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- /**
- * 调查问卷发放书币
- * Created by PhpStorm.
- * User: lytian
- * Date: 2019/7/25
- * Time: 21:46
- */
- namespace app\admin\command;
- use app\common\library\Redis;
- use app\common\library\WeChatObject;
- use app\common\model\AdminConfig;
- use app\common\model\User;
- use app\main\constants\CacheConstants;
- use app\main\service\AdminService;
- use app\main\service\OfficialAccountsService;
- use app\main\service\OpenPlatformService;
- use app\main\service\UserService;
- use EasyWeChat\Kernel\Messages\Text;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- use think\Exception;
- use think\Log;
- use think\Request;
- class DcwjFinish extends Command
- {
- /**
- * @var User
- */
- private $model = null;
- private $redis = null;
- protected function configure()
- {
- $this->setName('dcwjFinish')
- ->setDescription('调查问卷发放书币');
- }
- protected function execute(Input $input, Output $output)
- {
- Request::instance()->module('admin'); //cli模式下无法获取到当前的项目模块,手动指定一下
- $filename = APP_PATH."dcwj.txt";
- $handle = fopen ($filename, "r");
- $adminIds = [];
- $i = 1;
- while (!feof($handle)) {
- $buffer = fgets($handle, 4096);
- $content = trim($buffer);
- if (empty($content)) {
- break;
- }
- try {
- $userId = $content;
- if (!is_numeric($userId)) {
- continue;
- }
- $this->model = model("User");
- $this->redis = Redis::instance();
- $key = 'U_DCWJ:'. $userId;
- if ($this->redis->exists($key)) {
- echo "第{$i}行--userid:{$userId}--处理结果:已赠送\n";
- continue;
- }
- $res = $this->editUserKandian($userId,1,2,0,500,'调查问卷脚本执行添加');
- if ($res) {
- echo "第{$i}行--userid:{$userId}--处理结果:成功\n";
- $this->redis->set($key, '1', 86400*30);
- } else {
- echo "第{$i}行--userid:{$userId}--处理结果:失败\n";
- }
- }catch (Exception $e) {
- echo "第{$i}行--userid:{$userId}--处理结果:异常\n";
- }
- $i++;
- }
- fclose ($handle);
- $output->writeln("\n处理完毕!");
- }
- /**
- * @param $id 用户id
- * @param $type 增加/减少 书币
- * @param $czlx 充值类型
- * @param int $kandian 书币
- * @param int $free_kandian 减少多少免费书币
- * @param string $bz
- * @return bool
- */
- public function editUserKandian($id,$type,$czlx,$kandian=0,$free_kandian=0,$bz=''){
- $user = $this->model->getUserInfo($id);
- if($user){
- $saveDate = []; //新增充值记录
- $saveDate['user_id'] = $id;
- $saveDate['type'] = 6; //活动赠送
- $saveDate['notes'] = $bz;
- $saveDate['edit_type'] = $czlx;
- $saveDate['createtime'] = time();
- if($type==1){ //增加书币
- if($kandian){
- $saveDate['kandian'] = $kandian;
- }
- if($free_kandian){
- $saveDate['free_kandian'] = $free_kandian;
- $saveDate['remain_free_kandian'] = $free_kandian;
- $saveDate['free_endtime'] = 5*86400 + time();
- }
- }
- if(isset($saveDate['free_kandian']) || isset($saveDate['kandian'])){
- $flagFreeRecharge = true;
- $flagRecharge = true;
- if(!empty($saveDate['kandian'])){
- $kandianSaveDate = $saveDate;
- if(!empty($kandianSaveDate['free_kandian'])){
- unset($kandianSaveDate['free_kandian']);
- unset($kandianSaveDate['remain_free_kandian']);
- unset($kandianSaveDate['free_endtime']);
- }
- $flagRecharge = model('Recharge')->setConnect($id)->insertGetId($kandianSaveDate); //插入充值记录
- }
- if(!empty($saveDate['free_kandian'])){
- $freeSaveDate = $saveDate;
- if(!empty($freeSaveDate['kandian'])){
- unset($freeSaveDate['kandian']);
- }
- $flagFreeRecharge = model('Recharge')->setConnect($id)->insertGetId($freeSaveDate); //插入免费充值记录
- if($flagFreeRecharge) {
- $insertId = $flagFreeRecharge;
- $rData = [];
- $rData['id'] = $insertId;
- $rData['remain_free_kandian'] = $saveDate['remain_free_kandian'];
- $rData['free_endtime'] = $saveDate['free_endtime'];
- if ($flagFreeRecharge) {
- $this->redis->del('ZR:' . $id);
- }
- }
- }
- if(!$flagRecharge || !$flagFreeRecharge){
- Log::error('修改用户书币:数据库recharge插入失败!');
- return false;
- }
- }
- }else{ //没有此用户
- return false;
- }
- return true;
- }
- }
|