123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /**
- * AgentOrderModel.php UTF-8
- * 渠道订单数据操作
- *
- * @date : 2017/10/12 20:07
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 7.2
- * Added by wuyonghong BEGIN 2017/10/12 ISSUES:3772 渠道收益计算重写
- */
- namespace huo\model\agent;
- use huo\model\common\CommonModel;
- use huo\model\game\GameModel;
- use huo\model\member\MemberModel;
- use huo\model\user\UserModel;
- use huolib\constant\OrderConst;
- class AgentOrderModel extends CommonModel {
- protected $name = 'agent_order';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- public function mem() {
- return $this->belongsTo(MemberModel::className(), 'mem_id', 'id', '', 'left')->field('id,username')
- ->setEagerlyType(0);
- }
- public function agent() {
- return $this->belongsTo(UserModel::className(), 'agent_id', 'id')->field('id,user_login,user_nicename,role_id');
- }
- public function fromagent() {
- return $this->belongsTo(UserModel::className(), 'from_id', 'id')->field('id,user_login,user_nicename');
- }
- public function parentagent() {
- return $this->belongsTo(UserModel::className(), 'parent_id', 'id')->field('id,user_login,user_nicename');
- }
- public function game() {
- return $this->belongsTo(GameModel::className(), 'app_id', 'id')->field('id,name');
- }
- /**
- * @param string $order_id
- *
- * @return array|bool|
- */
- public function getInfoByOrderId($order_id = '') {
- $_map['order_id'] = $order_id;
- $_info = $this->where($_map)->find();
- if (false === $_info) {
- return false;
- }
- if (is_object($_info)) {
- return $_info->toArray();
- } else {
- return $_info;
- }
- }
- /**
- * @param array $data
- *
- * @return bool|int
- */
- public function createOrder($data) {
- $_data['order_id'] = get_val($data, 'order_id', '');
- $_data['mem_id'] = get_val($data, 'mem_id', 0);
- $_data['from_id'] = get_val($data, 'from_id', 0);
- $_data['agent_id'] = get_val($data, 'agent_id', 0);
- $_data['app_id'] = get_val($data, 'app_id', 0);
- $_data['amount'] = get_val($data, 'amount', 0.00);
- $_data['real_amount'] = get_val($data, 'real_amount', 0.00);
- $_data['rebate_cnt'] = get_val($data, 'rebate_cnt', 0.00);
- $_data['agent_rate'] = get_val($data, 'agent_rate', 0.00);
- $_data['agent_gain'] = get_val($data, 'agent_gain', 0.00);
- $_data['flag'] = get_val($data, 'flag', 0.00);
- $_data['status'] = get_val($data, 'status', 1);
- $_data['parent_id'] = get_val($data, 'parent_id', 0);
- $_data['parent_rate'] = get_val($data, 'parent_rate', 0.00);
- $_data['parent_gain'] = get_val($data, 'parent_gain', 0.00);
- $_data['payway'] = get_val($data, 'payway', '');
- $_data['ptb_cnt'] = get_val($data, 'ptb_cnt', 0);
- $_data['rebate_cnt'] = get_val($data, 'rebate_cnt', 0);
- $_data['discount'] = get_val($data, 'discount', 1);
- $_data['payway'] = get_val($data, 'payway', '');
- $_data['remark'] = get_val($data, 'remark', '');
- if ($_obj = self::create($_data, true)) {
- return $_obj->id;
- } else {
- return false;
- }
- }
- /**
- * 昨日金额
- *
- *
- * @param array $map
- *
- * @return float
- */
- public function yesterdayMoney($map = []) {
- return $this->getSumMoney(strtotime('yesterday'), strtotime('today') - 1, $map);
- }
- /**
- * 今日金额
- *
- * @param array $map
- *
- * @return float
- */
- public function todayMoney($map = []) {
- return $this->getSumMoney(strtotime('today'), time(), $map);
- }
- /**
- * 本周金额
- *
- * @param array $map
- *
- * @return float|int
- */
- public function thisWeekMoney($map = []) {
- return $this->getSumMoney(strtotime(date('Y-m-d 00:00:00', strtotime('this week'))), time(), $map);
- }
- /**
- * 本月金额
- *
- * @param array $map
- *
- * @return float|int
- */
- public function thisMonthMoney($map = []) {
- return $this->getSumMoney(strtotime(date('Y-m-01 00:00:00')), time(), $map);
- }
- /**
- * 获取金额
- *
- * @param int $start_time 开始时间
- * @param int $end_time 结束时间
- *
- * @param array $map
- *
- * @return float|int
- */
- public function getSumMoney($start_time, $end_time, $map = []) {
- $where['status'] = OrderConst::DTB_STATUS_SUC;
- $where['create_time'] = ['between', [$start_time, $end_time]];
- return $this->where($map)->where($where)->sum('agent_gain');
- }
- public function getInfoByAgentIdAndFlag($agent_id, $flag) {
- $_info = $this->where('agent_id', '=', $agent_id)
- ->where('flag', '=', $flag)
- ->find();
- if (is_object($_info)) {
- $_info = $_info->toArray();
- }
- return $_info;
- }
- }
|