dlh_test_server/app/admin/logic/distribution/DistributionPartnerLogic.php
2024-10-25 17:31:56 +08:00

100 lines
3.1 KiB
PHP
Executable File

<?php
namespace app\admin\logic\distribution;
use app\common\basics\Logic;
use app\common\logic\RegionLogic;
use app\common\model\distribution\DistributionStoreType;
use app\common\model\distribution\DistributionPartner;
use app\common\server\ConfigServer;
use app\common\enum\DistributionPartnerEnum;
class DistributionPartnerLogic extends Logic
{
public static function templatelists($get)
{
$list = DistributionStoreType::where(['is_delete' => 0])
->order(['sort' => 'desc'])
->paginate([
'page' => $get['page'] ?? 1,
'list_rows' => $get['limit'] ?? 10,
'var_page' => 'page'
])
->toArray();
return $list;
}
public static function getConfig(){
$config = [
'open_store_type' => ConfigServer::get('distribution','store_type',0),
];
return [$config];
}
public static function add($post){
try{
$citys = explode(',', $post['citys']);
$cityIds = [];
foreach ($citys as &$v) {
$cityIds[] = RegionLogic::cityCoverId($v);
}
DistributionPartner::create([
'proportion' => str_replace('%', '', $post['proportion']),
'city' => implode(',', $cityIds),
'type' => $post['type'],
'core_city_money' => $post['core_city_money'],
'un_core_city_money' => $post['un_core_city_money'],
'is_show' => $post['is_show'],
'create_time' => time(),
]);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function changeOrderValue($id, $value)
{
try {
DistributionStoreType::where('id', $id)->update([
'sort' => $value,
'update_time' => time(),
]);
return true;
} catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function getRechargeTemplate($id){
return DistributionStoreType::where(['id' => $id])->find();
}
public static function edit($post){
try{
DistributionStoreType::update([
'id' => $post['id'],
'title' => $post['title'],
'money' => $post['money'],
'sort' => $post['sort'],
'update_time' => time(),
]);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function del($id){
return DistributionStoreType::where(['id' => $id])->update(['update_time' => time(),'is_delete' => 1]);
}
public static function setStoreType($post){
ConfigServer::set('distribution','store_type', $post['open_store_type']);
}
}