123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace App\Console\Commands\Book;
- use Illuminate\Console\Command;
- use App\Modules\Book\Models\Chapter;
- use App\Modules\Book\Models\Book;
- use App\Modules\Book\Models\BookConfig;
- use App\Modules\Book\Models\BookRechargeExpectedPositions;
- class BookRechargePredict extends Command
- {
-
- protected $signature = 'book_recharge_predict';
-
- protected $description = '书籍充值预测';
-
- public function __construct()
- {
- parent::__construct();
- }
-
- public function handle()
- {
- $params = array(
- ['first_recharge_amount'=>50,'first_recharge_bookcoin'=>9000,'secondChargeAmount'=>50,'second_recharge_bookcoin'=>9000],
- ['first_recharge_amount'=>50,'first_recharge_bookcoin'=>9000,'secondChargeAmount'=>30,'second_recharge_bookcoin'=>3000],
- ['first_recharge_amount'=>30,'first_recharge_bookcoin'=>3000,'secondChargeAmount'=>50,'second_recharge_bookcoin'=>9000],
- ['first_recharge_amount'=>30,'first_recharge_bookcoin'=>3000,'secondChargeAmount'=>30,'second_recharge_bookcoin'=>3000],
- );
- $books = BookConfig::whereIn('is_on_shelf',[1,2])->get();
- foreach ($books as $book){
- if($book->charge_type == 'BOOK'){
- continue;
- }
- foreach ($params as $param){
-
- $this->simulationDeduction($book,$param);
- }
- }
- }
- public function simulationDeduction($book,$param){
- $price_rate = 0.04;
- echo('千字价位为:'.$price_rate);
- $give_bookcoin = 80;
- $prediction = array();
- $prediction['bid'] = $book->bid;
- $seq=$book->vip_seq;
- $blance = 0;
- $prediction['first_recharge_amount'] = $param['first_recharge_amount'];
- $blance += $param['first_recharge_bookcoin'] + $give_bookcoin;
- $prediction['balance_after_first_recharge'] = $blance;
-
- while($blance>0) {
- $chapter = Chapter::getChapterByBidAndSeq($book->bid, $seq);
- if ($chapter) {
- $price = $this->getPrice($chapter,$price_rate);
- $real_fee = $chapter->size*$price_rate;
- if($price>$blance){break;}
- $blance -= $price;
-
- $seq++;
- } else {
- break;
- }
- }
- if($chapter){
- $prediction['sec_chapter_id'] = $chapter->id;
- $prediction['sec_chapter_seq'] = $chapter->sequence;
- $prediction['sec_chapter_name'] = $chapter->name;
- $prediction['balance_before_sec_recharge'] = $blance;
- $prediction['sec_recharge_amount'] = $param['secondChargeAmount'];
- $blance += $param['second_recharge_bookcoin'] + $give_bookcoin;
- $prediction['balance_after_sec_recharge'] = $blance;
-
- while($blance>0) {
- $chapter = Chapter::getChapterByBidAndSeq($book->bid, $seq);
- if ($chapter) {
- $price = $this->getPrice($chapter,$price_rate);
- $real_fee = $chapter->size*$price_rate;
- if($price>$blance){break;}
- $blance -= $price;
-
- $seq++;
- } else {
- break;
- }
- }
- if($chapter){
- $prediction['third_chapter_id'] = $chapter->id;
- $prediction['third_chapter_seq'] = $chapter->sequence;
- $prediction['third_chapter_name'] = $chapter->name;
- $prediction['balance_before_third_recharge'] = $blance;
- }else{
- $prediction['third_chapter_id'] = '';
- $prediction['third_chapter_seq'] = '';
- $prediction['third_chapter_name'] = '';
- $prediction['balance_before_third_recharge'] = '';
- }
-
- }else{
- $prediction['sec_chapter_id'] = '';
- $prediction['sec_chapter_seq'] = '';
- $prediction['sec_chapter_name'] = '';
- $prediction['balance_after_first_recharge'] = '';
- $prediction['balance_before_sec_recharge'] = '';
- $prediction['sec_recharge_amount'] = '';
- $prediction['third_chapter_id'] = '';
- $prediction['third_chapter_seq'] = '';
- $prediction['third_chapter_name'] = '';
- $prediction['balance_after_sec_recharge'] = '';
- $prediction['balance_before_third_recharge'] = '';
- }
- BookRechargeExpectedPositions::updateOrCreate([
- 'bid'=>$prediction['bid'],
- 'first_recharge_amount'=>$prediction['first_recharge_amount'],
- 'sec_recharge_amount'=>$prediction['sec_recharge_amount'],
- ]
- ,$prediction);
- }
- public static function getPrice($chapter,$price_rate){
- $fee = ceil($chapter->size * $price_rate);
- if($fee >189) $fee = 189;
- if($fee <37) $fee = 37;
- return $fee;
- }
- }
|