123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- /**
- * LogDayMemFakerModel.php UTF-8
- * 玩家每日
- *
- * @date : 2018/6/27 17:57
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lwl@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\model\fill;
- use huo\model\log\LogModel;
- use huolib\constant\CommonConst;
- class LogDayMemFakerModel extends LogModel {
- protected $table = 'mp_log_day_mem_faker';
- public function mem() {
- return $this->belongsTo(MemFakerModel::className(), 'faker_id', 'id')
- ->where('is_delete', '=', CommonConst::CONST_NOT_DELETE)
- ->field(['id', 'nickname', 'avatar']);
- }
- /**
- * @param $data
- * @param bool $replace
- * @param bool $get_last_insert_id
- *
- * @return bool|int|string
- */
- public function insertLog($data, $replace = false, $get_last_insert_id = true) {
- $_data['faker_id'] = get_val($data, 'faker_id', 0);
- $_data['sub_mem_cnt'] = get_val($data, 'sub_mem_cnt', 0);
- $_data['sub_amount'] = get_val($data, 'sub_amount', 0);
- $_data['sum_amount'] = get_val($data, 'sum_amount', 0);
- $_data['date'] = date('Y-m-d', $data['create_time']);
- $_mem_data = $this->memDayInfo($_data, 10, true);
- $_mem_data = $_mem_data->toArray();
- if (!empty($_mem_data['data'])) {
- $_data['sub_mem_cnt'] += $_mem_data['data'][0]['sub_mem_cnt'];
- $_data['sub_amount'] += $_mem_data['data'][0]['sub_amount'];
- $_data['sum_amount'] += $_mem_data['data'][0]['sum_amount'];
- return $this->updateData($_data);
- }
- return parent::insertLog($_data, $replace, $get_last_insert_id);
- }
- /**
- * @param string $date
- *
- * @return int|void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- function checkTable($date = '') {
- $this->table = $this->getPartitionTableName(
- $this->partition_data, $this->partition_field, $this->partition_rule
- );
- $_sql = "CREATE TABLE IF NOT EXISTS `$this->table` (";
- $_sql .= "`id` int(11) NOT NULL AUTO_INCREMENT,";
- $_sql .= "`date` date NOT NULL COMMENT '日期',";
- $_sql .= "`faker_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'mem_faker表ID',";
- $_sql .= "`sub_mem_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '邀请人数',";
- $_sql .= "`sub_amount` double(20,2) NOT NULL DEFAULT '0.00' COMMENT '邀请奖励',";
- $_sql .= "`sum_amount` double(20,2) NOT NULL DEFAULT '0.00' COMMENT '当日收入',";
- $_sql .= " PRIMARY KEY (`id`),";
- $_sql .= "UNIQUE KEY `ldm_date_faker_unique` (`date`,`faker_id`),";
- $_sql .= "KEY `ldm_faker_index` (`faker_id`)";
- $_sql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='玩家假数据每日';";
- return $this->execute($_sql);
- }
- /**
- * 玩家每日记录
- *
- * @param $param
- * @param int $offset
- * @param bool $the_day true 表示获取当日记录
- *
- * @return bool|\think\Paginator
- */
- public function memDayInfo($param, $offset = 10, $the_day = false) {
- if (isset($param['date']) && !empty($param['date'])) {
- $_date = $param['date'];
- } else {
- $_date = date('Y-m-d', time());
- }
- if (isset($param['faker_id']) && !empty($param['faker_id'])) {
- $_map['faker_id'] = $param['faker_id'];
- } else {
- return false;
- }
- if (true == $the_day) {
- $_map['date'] = $_date;
- }
- $_field = 'faker_id, sub_mem_cnt, sub_amount, sum_amount';
- $_data = $this->computeTable($_date)->field($_field)
- ->where($_map)
- ->paginate($offset);
- return $_data;
- }
- /**
- * 根据日期获取
- *
- * @param string $field 字段,包括别名
- * @param string $start_date 开始日期
- * @param string $end_date 结束日期
- * @param null $alias
- *
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getByDate($field, $start_date, $end_date, $alias = null) {
- $alias or $alias = $field;
- $_rows = $this->computeTable($start_date)
- ->field("date, $field")
- ->group('date')
- ->select()->toArray();
- $_data = [];
- foreach ($_rows as $_row) {
- $_data[$_row['date']] = $_row[$alias];
- }
- $result = [];
- for ($_i = strtotime($start_date); $_i <= strtotime($end_date); $_i += 24 * 3600) {
- $_key = date('Y-m-d', $_i);
- $result[date('m-d', $_i)] = isset($_data[$_key]) ? doubleval($_data[$_key]) : 0;
- }
- return $result;
- }
- public function getLastDataByFakerId($faker_id) {
- $_map['faker_id'] = $faker_id;
- $_date = date('Y-m-d');
- $_info = $this->computeTable($_date)->where($_map)->find();
- if (false === $_info) {
- return false;
- }
- if (is_object($_info)) {
- return $_info->toArray();
- } else {
- return $_info;
- }
- }
- public function updateData($data) {
- if (empty($data['date'])) {
- return false;
- }
- if (empty($data['faker_id'])) {
- return false;
- }
- $_map = [
- 'faker_id' => $data['faker_id'],
- 'date' => $data['date'],
- ];
- $_rs = $this->computeTable($data['date'])->where($_map)->update($data);
- return $_rs;
- }
- }
|