Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php // +---------------------------------------------------------------------- // | CR..

Decoded Output download

<?php 
// +---------------------------------------------------------------------- 
// | CRMEB [ CRMEB ] 
// +---------------------------------------------------------------------- 
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved. 
// +---------------------------------------------------------------------- 
// | Licensed CRMEBCRMEB 
// +---------------------------------------------------------------------- 
// | Author: CRMEB Team <[email protected]> 
// +---------------------------------------------------------------------- 
 
namespace app\dao; 
 
use crmebasic\BaseAuth; 
use crmebasic\BaseModel; 
use think\Model; 
 
/** 
 * Class BaseDao 
 * @package app\dao 
 */ 
abstract class BaseDao 
{ 
    /** 
     *  
     * @var string 
     */ 
    protected $alias; 
 
    /** 
     * join 
     * @var string 
     */ 
    protected $joinAlis; 
 
 
    /** 
     *  
     * @return string 
     */ 
    abstract protected function setModel(): string; 
 
    /** 
     * join 
     * @return string 
     */ 
    protected function setJoinModel(): string 
    { 
    } 
 
    /** 
     *  
     * @param array $where 
     * @return int 
     */ 
    public function count(array $where = []): int 
    { 
        return $this->search($where)->count(); 
    } 
 
    /** 
     *  
     * @param array $where 
     */ 
    public function getCount(array $where) 
    { 
        return $this->getModel()->where($where)->count(); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param $field 
     * @param $search 
     */ 
    public function getDistinctCount(array $where, $field, $search = true) 
    { 
        if ($search) { 
            return $this->search($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0; 
        } else { 
            return $this->getModel()->where($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0; 
        } 
    } 
 
    /** 
     *  
     * @return BaseModel 
     */ 
    protected function getModel() 
    { 
        return app()->make($this->setModel()); 
    } 
 
    /** 
     *  
     * @return mixed 
     */ 
    protected function getPk() 
    { 
        return $this->getModel()->getPk(); 
    } 
 
    /** 
     *  
     * @param int|array $id 
     * @param array|null $field 
     * @return array|Model|null 
     * @throws 	hink\db\exception\DataNotFoundException 
     * @throws 	hink\db\exception\DbException 
     * @throws 	hink\db\exception\ModelNotFoundException 
     */ 
    public function get($id, ?array $field = [], ?array $with = []) 
    { 
        if (is_array($id)) { 
            $where = $id; 
        } else { 
            $where = [$this->getPk() => $id]; 
        } 
        return $this->getModel()::where($where)->when(count($with), function ($query) use ($with) { 
            $query->with($with); 
        })->field($field ?? ['*'])->find(); 
    } 
 
    /** 
     *  
     * @param $map 
     * @param string $field 
     * @return bool  
     */ 
    public function be($map, string $field = '') 
    { 
        if (!is_array($map) && empty($field)) $field = $this->getPk(); 
        $map = !is_array($map) ? [$field => $map] : $map; 
        return 0 < $this->getModel()->where($map)->count(); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param string|null $field 
     * @param array $with 
     * @return array|Model|null 
     * @throws 	hink\db\exception\DataNotFoundException 
     * @throws 	hink\db\exception\DbException 
     * @throws 	hink\db\exception\ModelNotFoundException 
     */ 
    public function getOne(array $where, ?string $field = '*', array $with = []) 
    { 
        $field = explode(',', $field); 
        return $this->get($where, $field, $with); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param string|null $field 
     * @return mixed 
     */ 
    public function value(array $where, ?string $field = '') 
    { 
        $pk = $this->getPk(); 
        return $this->getModel()::where($where)->value($field ?: $pk); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param string $field 
     * @param string $key 
     * @return array 
     */ 
    public function getColumn(array $where, string $field, string $key = '') 
    { 
        return $this->getModel()::where($where)->column($field, $key); 
    } 
 
    /** 
     *  
     * @param int|string|array $id 
     * @return mixed 
     */ 
    public function delete($id, ?string $key = null) 
    { 
        if (is_array($id)) { 
            $where = $id; 
        } else { 
            $where = [is_null($key) ? $this->getPk() : $key => $id]; 
        } 
        return $this->getModel()::where($where)->delete(); 
    } 
 
    /** 
     *  
     * @param int|string|array $id 
     * @param array $data 
     * @return mixed 
     */ 
    public function update($id, array $data, ?string $key = null) 
    { 
        if (is_array($id)) { 
            $where = $id; 
        } else { 
            $where = [is_null($key) ? $this->getPk() : $key => $id]; 
        } 
        return $this->getModel()::update($data, $where); 
    } 
 
    /** 
     *  
     * @param array $ids 
     * @param array $data 
     * @param string|null $key 
     * @return BaseModel 
     */ 
    public function batchUpdate(array $ids, array $data, ?string $key = null) 
    { 
        return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->update($data); 
    } 
 
    /** 
     *  
     * @param array $data 
     * @return mixed 
     */ 
    public function save(array $data) 
    { 
        return $this->getModel()::create($data); 
    } 
 
    /** 
     *  
     * @param array $data 
     * @return mixed 
     */ 
    public function saveAll(array $data) 
    { 
        return $this->getModel()::insertAll($data); 
    } 
 
    /** 
     *  
     * @param $value 
     * @param string $filed 
     * @param string $valueKey 
     * @param array|string[] $where 
     * @return mixed 
     */ 
    public function getFieldValue($value, string $filed, ?string $valueKey = '', ?array $where = []) 
    { 
        return $this->getModel()->getFieldValue($value, $filed, $valueKey, $where); 
    } 
 
    /** 
     *  
     * @param array $withSearch 
     * @param array|null $data 
     * @return Model 
     */ 
    protected function withSearchSelect(array $withSearch, ?array $data = []) 
    { 
        [$with] = app()->make(BaseAuth::class)->________($withSearch, $this->setModel()); 
        return $this->getModel()->withSearch($with, $data); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @return \crmebasic\BaseModel|mixed 
     */ 
    protected function search(array $where = []) 
    { 
        if ($where) { 
            return $this->withSearchSelect(array_keys($where), $where); 
        } else { 
            return $this->getModel(); 
        } 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param string $field 
     * @param bool $search 
     * @return float 
     */ 
    public function sum(array $where, string $field, bool $search = false) 
    { 
        if ($search) { 
            return $this->search($where)->sum($field); 
        } else { 
            return $this->getModel()::where($where)->sum($field); 
        } 
    } 
 
    /** 
     *  
     * @param int|string $key 
     * @param string $incField 
     * @param string $inc 
     * @param string|null $keyField 
     * @param int $acc 
     * @return bool 
     * @throws 	hink\db\exception\DataNotFoundException 
     * @throws 	hink\db\exception\DbException 
     * @throws 	hink\db\exception\ModelNotFoundException 
     */ 
    public function bcInc($key, string $incField, string $inc, string $keyField = null, int $acc = 2) 
    { 
        return $this->bc($key, $incField, $inc, $keyField, 1); 
    } 
 
    /** 
     *   
     * @param int|string $uid id 
     * @param string $decField  
     * @param float|int $dec  
     * @param string $keyField id 
     * @param bool $minus  
     * @param int $acc  
     * @return bool 
     */ 
    public function bcDec($key, string $decField, string $dec, string $keyField = null, int $acc = 2) 
    { 
        return $this->bc($key, $decField, $dec, $keyField, 2); 
    } 
 
    /** 
     *  
     * @param $key 
     * @param string $incField 
     * @param string $inc 
     * @param string|null $keyField 
     * @param int $type 
     * @param int $acc 
     * @return bool 
     * @throws 	hink\db\exception\DataNotFoundException 
     * @throws 	hink\db\exception\DbException 
     * @throws 	hink\db\exception\ModelNotFoundException 
     */ 
    public function bc($key, string $incField, string $inc, string $keyField = null, int $type = 1, int $acc = 2) 
    { 
        if ($keyField === null) { 
            //$result = $this->get($key); 
            $where = [$this->getPk() => $key]; 
        } else { 
            $where = [$this->getPk() => $key]; 
            //$result = $this->getOne([$keyField => $key]); 
        } 
        if (!$where) return false; 
        if ($type === 1) { 
            //$new = bcadd($result[$incField], $inc, $acc); 
            return false !== $this->getModel()::where($where)->inc($incField,$inc) 
                ->update(); 
        } else if ($type === 2) { 
            //if ($result[$incField] < $inc) return false; 
            //$new = bcsub($result[$incField], $inc, $acc); 
            return false !== $this->getModel()::where($where)->dec($incField,$inc) 
                ->update(); 
        } 
       // $result->{$incField} = $new; 
        //return false !== $result->save(); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param int $num 
     * @return mixed 
     */ 
    public function decStockIncSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales') 
    { 
        return app()->make(BaseAuth::class)->_____($this->getModel(), $where, $num, $stock, $sales); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param int $num 
     * @return mixed 
     */ 
    public function incStockDecSalesOld(array $where, int $num, string $stock = 'stock', string $sales = 'sales') 
    { 
        return app()->make(BaseAuth::class)->___($this->getModel(), $where, $num, $stock, $sales); 
    } 
 
    /** 
     *  
     * @param array $where 
     * @param int $num 
     * @param string $stock 
     * @param string $sales 
     * @param bool $isIncStock 
     * @return mixed 
     */ 
    public function incStockDecSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales', $isIncStock = true) 
    { 
        $isQuota = false; 
        if (isset($where['type']) && $where['type']) { 
            $isQuota = true; 
            if (count($where) == 2) { 
                unset($where['type']); 
            } 
        } 
        $salesOne = $this->getModel()->where($where)->value($sales); 
        if ($salesOne) { 
            $salesNum = $num; 
            if ($num > $salesOne) { 
                $salesNum = $salesOne; 
            } 
            return $this->getModel()->where($where)->when($isQuota, function ($query) use ($num) { 
                $query->inc('quota', $num); 
            })->when($isIncStock, function ($query) use ($stock,$num) { 
                $query->inc($stock, $num); 
            })->dec($sales, $salesNum)->update(); 
        } 
        return true; 
    } 
} 
 ?>

Did this file decode correctly?

Original Code

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEBCRMEB
// +----------------------------------------------------------------------
// | Author: CRMEB Team <[email protected]>
// +----------------------------------------------------------------------

namespace app\dao;

use crmeb\basic\BaseAuth;
use crmeb\basic\BaseModel;
use think\Model;

/**
 * Class BaseDao
 * @package app\dao
 */
abstract class BaseDao
{
    /**
     * 
     * @var string
     */
    protected $alias;

    /**
     * join
     * @var string
     */
    protected $joinAlis;


    /**
     * 
     * @return string
     */
    abstract protected function setModel(): string;

    /**
     * join
     * @return string
     */
    protected function setJoinModel(): string
    {
    }

    /**
     * 
     * @param array $where
     * @return int
     */
    public function count(array $where = []): int
    {
        return $this->search($where)->count();
    }

    /**
     * 
     * @param array $where
     */
    public function getCount(array $where)
    {
        return $this->getModel()->where($where)->count();
    }

    /**
     * 
     * @param array $where
     * @param $field
     * @param $search
     */
    public function getDistinctCount(array $where, $field, $search = true)
    {
        if ($search) {
            return $this->search($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
        } else {
            return $this->getModel()->where($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
        }
    }

    /**
     * 
     * @return BaseModel
     */
    protected function getModel()
    {
        return app()->make($this->setModel());
    }

    /**
     * 
     * @return mixed
     */
    protected function getPk()
    {
        return $this->getModel()->getPk();
    }

    /**
     * 
     * @param int|array $id
     * @param array|null $field
     * @return array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function get($id, ?array $field = [], ?array $with = [])
    {
        if (is_array($id)) {
            $where = $id;
        } else {
            $where = [$this->getPk() => $id];
        }
        return $this->getModel()::where($where)->when(count($with), function ($query) use ($with) {
            $query->with($with);
        })->field($field ?? ['*'])->find();
    }

    /**
     * 
     * @param $map
     * @param string $field
     * @return bool 
     */
    public function be($map, string $field = '')
    {
        if (!is_array($map) && empty($field)) $field = $this->getPk();
        $map = !is_array($map) ? [$field => $map] : $map;
        return 0 < $this->getModel()->where($map)->count();
    }

    /**
     * 
     * @param array $where
     * @param string|null $field
     * @param array $with
     * @return array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getOne(array $where, ?string $field = '*', array $with = [])
    {
        $field = explode(',', $field);
        return $this->get($where, $field, $with);
    }

    /**
     * 
     * @param array $where
     * @param string|null $field
     * @return mixed
     */
    public function value(array $where, ?string $field = '')
    {
        $pk = $this->getPk();
        return $this->getModel()::where($where)->value($field ?: $pk);
    }

    /**
     * 
     * @param array $where
     * @param string $field
     * @param string $key
     * @return array
     */
    public function getColumn(array $where, string $field, string $key = '')
    {
        return $this->getModel()::where($where)->column($field, $key);
    }

    /**
     * 
     * @param int|string|array $id
     * @return mixed
     */
    public function delete($id, ?string $key = null)
    {
        if (is_array($id)) {
            $where = $id;
        } else {
            $where = [is_null($key) ? $this->getPk() : $key => $id];
        }
        return $this->getModel()::where($where)->delete();
    }

    /**
     * 
     * @param int|string|array $id
     * @param array $data
     * @return mixed
     */
    public function update($id, array $data, ?string $key = null)
    {
        if (is_array($id)) {
            $where = $id;
        } else {
            $where = [is_null($key) ? $this->getPk() : $key => $id];
        }
        return $this->getModel()::update($data, $where);
    }

    /**
     * 
     * @param array $ids
     * @param array $data
     * @param string|null $key
     * @return BaseModel
     */
    public function batchUpdate(array $ids, array $data, ?string $key = null)
    {
        return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->update($data);
    }

    /**
     * 
     * @param array $data
     * @return mixed
     */
    public function save(array $data)
    {
        return $this->getModel()::create($data);
    }

    /**
     * 
     * @param array $data
     * @return mixed
     */
    public function saveAll(array $data)
    {
        return $this->getModel()::insertAll($data);
    }

    /**
     * 
     * @param $value
     * @param string $filed
     * @param string $valueKey
     * @param array|string[] $where
     * @return mixed
     */
    public function getFieldValue($value, string $filed, ?string $valueKey = '', ?array $where = [])
    {
        return $this->getModel()->getFieldValue($value, $filed, $valueKey, $where);
    }

    /**
     * 
     * @param array $withSearch
     * @param array|null $data
     * @return Model
     */
    protected function withSearchSelect(array $withSearch, ?array $data = [])
    {
        [$with] = app()->make(BaseAuth::class)->________($withSearch, $this->setModel());
        return $this->getModel()->withSearch($with, $data);
    }

    /**
     * 
     * @param array $where
     * @return \crmeb\basic\BaseModel|mixed
     */
    protected function search(array $where = [])
    {
        if ($where) {
            return $this->withSearchSelect(array_keys($where), $where);
        } else {
            return $this->getModel();
        }
    }

    /**
     * 
     * @param array $where
     * @param string $field
     * @param bool $search
     * @return float
     */
    public function sum(array $where, string $field, bool $search = false)
    {
        if ($search) {
            return $this->search($where)->sum($field);
        } else {
            return $this->getModel()::where($where)->sum($field);
        }
    }

    /**
     * 
     * @param int|string $key
     * @param string $incField
     * @param string $inc
     * @param string|null $keyField
     * @param int $acc
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function bcInc($key, string $incField, string $inc, string $keyField = null, int $acc = 2)
    {
        return $this->bc($key, $incField, $inc, $keyField, 1);
    }

    /**
     *  
     * @param int|string $uid id
     * @param string $decField 
     * @param float|int $dec 
     * @param string $keyField id
     * @param bool $minus 
     * @param int $acc 
     * @return bool
     */
    public function bcDec($key, string $decField, string $dec, string $keyField = null, int $acc = 2)
    {
        return $this->bc($key, $decField, $dec, $keyField, 2);
    }

    /**
     * 
     * @param $key
     * @param string $incField
     * @param string $inc
     * @param string|null $keyField
     * @param int $type
     * @param int $acc
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function bc($key, string $incField, string $inc, string $keyField = null, int $type = 1, int $acc = 2)
    {
        if ($keyField === null) {
            //$result = $this->get($key);
            $where = [$this->getPk() => $key];
        } else {
            $where = [$this->getPk() => $key];
            //$result = $this->getOne([$keyField => $key]);
        }
        if (!$where) return false;
        if ($type === 1) {
            //$new = bcadd($result[$incField], $inc, $acc);
            return false !== $this->getModel()::where($where)->inc($incField,$inc)
                ->update();
        } else if ($type === 2) {
            //if ($result[$incField] < $inc) return false;
            //$new = bcsub($result[$incField], $inc, $acc);
            return false !== $this->getModel()::where($where)->dec($incField,$inc)
                ->update();
        }
       // $result->{$incField} = $new;
        //return false !== $result->save();
    }

    /**
     * 
     * @param array $where
     * @param int $num
     * @return mixed
     */
    public function decStockIncSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
    {
        return app()->make(BaseAuth::class)->_____($this->getModel(), $where, $num, $stock, $sales);
    }

    /**
     * 
     * @param array $where
     * @param int $num
     * @return mixed
     */
    public function incStockDecSalesOld(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
    {
        return app()->make(BaseAuth::class)->___($this->getModel(), $where, $num, $stock, $sales);
    }

    /**
     * 
     * @param array $where
     * @param int $num
     * @param string $stock
     * @param string $sales
     * @param bool $isIncStock
     * @return mixed
     */
    public function incStockDecSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales', $isIncStock = true)
    {
        $isQuota = false;
        if (isset($where['type']) && $where['type']) {
            $isQuota = true;
            if (count($where) == 2) {
                unset($where['type']);
            }
        }
        $salesOne = $this->getModel()->where($where)->value($sales);
        if ($salesOne) {
            $salesNum = $num;
            if ($num > $salesOne) {
                $salesNum = $salesOne;
            }
            return $this->getModel()->where($where)->when($isQuota, function ($query) use ($num) {
                $query->inc('quota', $num);
            })->when($isIncStock, function ($query) use ($stock,$num) {
                $query->inc($stock, $num);
            })->dec($sales, $salesNum)->update();
        }
        return true;
    }
}

Function Calls

None

Variables

None

Stats

MD5 a35303c19e144f43d657538e044a815c
Eval Count 0
Decode Time 52 ms