erp/app/admin/logic/supplier/SupplierLogic.php
2024-05-18 14:01:51 +08:00

248 lines
9.0 KiB
PHP

<?php
namespace app\admin\logic\supplier;
use app\admin\logic\user\UserLogic;
use app\common\model\goods\GoodsLabel;
use app\common\model\supplier\Supplier;
use app\common\logic\BaseLogic;
use think\facade\Db;
use support\exception\BusinessException;
/**
* 供应商管理逻辑
* Class SupplierLogic
* @package app\admin\logic\supplier
*/
class SupplierLogic extends BaseLogic
{
/**
* @notes 添加供应商管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/27 14:33
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$res= Supplier::create([
'category_id' => $params['category_id'],
'type_id' => $params['type_id'] ?? '',
'mer_name' => $params['mer_name'],
'settle_cycle' => $params['settle_cycle']??15,
'interest_rate' => $params['interest_rate']??0,
'sys_labels' => $params['sys_labels'] ?? '',
'province_id' => $params['province_id'] ?? '',
'city_id' => $params['city_id'] ?? '',
'area_id' => $params['area_id'] ?? '',
'street_id' => $params['street_id'] ?? '',
'village_id' => $params['village_id'] ?? '',
'mer_address' => $params['mer_address'] ?? '',
'mer_avatar' => $params['mer_avatar'] ?? '',
'mark' => $params['mark'] ?? '',
'status' => $params['status'] ?? 0,
'commission_rate' => $params['commission_rate'] ?? '',
'commission_switch' => $params['commission_switch'] ?? '',
'long' => $params['long'] ?? '',
'lat' => $params['lat'] ?? '',
'service_phone' => $params['phone'],
'mer_money' => $params['mer_money']??0,
'financial_bank' => $params['financial_bank'] ?? '',
'financial_wechat' => $params['financial_wechat'] ?? '',
'financial_alipay' => $params['financial_alipay'] ?? '',
'financial_type' => $params['financial_type'] ?? '',
'data_json'=>json_encode([
'company_address' => $params['address'] ?? '',
'company_nickname' => $params['nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '',
'images'=>$params['images'][0] ?? '',
])
]);
Db::name('user_auth_shop')->insert(['pid'=>$res->id,'user_id'=>0,'shop_uid'=>$params['shop_user_id'],'status'=>0,'type'=>2,'create_time'=>time()]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 审核商户状态
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/23 16:35
*/
public static function status(array $params): bool
{
Db::startTrans();
try {
$user=[
'real_name'=>$params['service_phone'],
'nickname' => '用户'.$params['service_phone'],
'account' => $params['service_phone'],
'mobile' => $params['service_phone'],
'password' => $params['service_phone'],
'sex' => 0,
'is_disable' => 0,
'user_money' => 0
];
$res1=UserLogic::add($user);
if($res1==false){
throw new BusinessException(UserLogic::getError(), 0);
}
if($params['status']==1){
$data=[
'user_id'=>$res1['id'],
'status'=>1,
'apply_status'=>1,
'pid'=>$params['id']
];
Supplier::where('id',$params['id'])->update(['status'=>1,'uid'=>$res1['id']]);
Db::name('user_auth_shop')->where('id',$params['apply_id'])->update($data);
}
if($params['status']==0){
$data=[
'mark'=>$params['mark']??'',
'apply_status'=>-1
];
Db::name('user_auth_shop')->where('id',$params['apply_id'])->update($data);
}
Supplier::where('id', $params['id'])->update([
'status' => $params['status'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑供应商管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/27 14:33
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Supplier::where('id', $params['id'])->update([
'category_id' => $params['category_id'],
'type_id' => $params['type_id'] ?? '',
'mer_name' => $params['mer_name'],
'settle_cycle' => $params['settle_cycle'],
'interest_rate' => $params['interest_rate'],
'sys_labels' => $params['sys_labels'] ?? '',
'province_id' => $params['province_id'] ?? '',
'city_id' => $params['city_id'] ?? '',
'area_id' => $params['area_id'] ?? '',
'street_id' => $params['street_id'] ?? '',
'village_id' => $params['village_id'] ?? '',
'mer_address' => $params['mer_address'] ?? '',
'mer_avatar' => $params['mer_avatar'] ?? '',
'mark' => $params['mark'] ?? '',
'status' => $params['status'] ?? 0,
'commission_rate' => $params['commission_rate'] ?? '',
'commission_switch' => $params['commission_switch'] ?? '',
'long' => $params['long'] ?? '',
'lat' => $params['lat'] ?? '',
'service_phone' => $params['service_phone'],
'mer_money' => $params['mer_money'],
'financial_bank' => $params['financial_bank'] ?? '',
'financial_wechat' => $params['financial_wechat'] ?? '',
'financial_alipay' => $params['financial_alipay'] ?? '',
'financial_type' => $params['financial_type'] ?? ''
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除供应商管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/27 14:33
*/
public static function delete(array $params): bool
{
return Supplier::destroy($params['id']);
}
/**
* @notes 获取供应商管理详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/04/27 14:33
*/
public static function detail($params): array
{
$data = Supplier::findOrEmpty($params['id']);
$province = Db::name('geo_province')->field('province_name')->where('province_code',$data['province_id'])->findOrEmpty();
$city = Db::name('geo_city')->field('city_name')->where('city_code',$data['city_id'])->findOrEmpty();
$area = Db::name('geo_area')->field('area_name')->where('area_code',$data['area_id'])->findOrEmpty();
$street = Db::name('geo_street')->field('street_name')->where('street_code',$data['street_id'])->findOrEmpty();
$village = Db::name('geo_village')->field('village_name')->where('village_code',$data['village_id'])->findOrEmpty();
$data['province_name'] = !empty($province) ? $province['province_name'] : '';
$data['city_name'] = !empty($city) ? $city['city_name'] : '';
$data['area_name'] = !empty($area) ? $area['area_name'] : '';
$data['street_name'] = !empty($street) ? $street['street_name'] : '';
$data['village_name'] = !empty($village) ? $village['village_name'] : '';
if(!empty($data['sys_labels'])){
$goodslabel = GoodsLabel::where('id','in',$data['sys_labels'])->column('name');
$data['sys_labels_text'] = implode(',',$goodslabel);
}else{
$data['sys_labels_text'] = '';
}
return $data->toArray();
}
/**
* @notes 设置标签
* @param $params
* @return bool
* @date 2024/04/23 11:28
*/
public static function setLabel($params)
{
try {
$value = $params['sys_labels'];
if (!empty($value)) {
if (!is_array($value)){
$value= ',' . $value . ',';
}else{
$value = ',' . implode(',', $value) . ',';
}
}
Supplier::where('id', $params['id'])->update(['sys_labels' => $value]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}