优化代码格式,提升代码可读性

This commit is contained in:
mkm 2024-05-24 10:38:10 +08:00
parent 67d6fc5a3e
commit 70e58fe432
9 changed files with 201 additions and 129 deletions

View File

@ -81,7 +81,7 @@ class SupplierController extends BaseAdminController
}
/**
* @notes 编辑状态
* @notes 供应商审核
* @return \think\response\Json
* @author likeadmin
* @date 2024/04/23 16:35
@ -91,7 +91,7 @@ class SupplierController extends BaseAdminController
$params = (new SupplierValidate())->post()->goCheck('status');
$result = SupplierLogic::status($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
return $this->success('审核成功', [], 1, 1);
}
return $this->fail(SupplierLogic::getError());
}

View File

@ -23,7 +23,9 @@ class FinancialRecordLists extends BaseAdminDataLists implements ListsSearchInte
*/
public function setSearch(): array
{
return [];
return [
"between_time" => 'create_time'
];
}

View File

@ -43,6 +43,7 @@ class AdminLogic extends BaseLogic
*/
public static function add(array $params)
{
d($params);
Db::startTrans();
try {
$password = password_hash($params['password'],PASSWORD_DEFAULT);

View File

@ -161,7 +161,8 @@ class MerchantLogic extends BaseLogic
$res1 = UserLogic::add($user);
if ($res1 == false) {
Db::rollback();
throw new BusinessException(UserLogic::getError(), 0);
self::setError(UserLogic::getError());
return false;
}
$data = [
'user_id' => $res1['id'],
@ -184,7 +185,13 @@ class MerchantLogic extends BaseLogic
}
if (!empty($apply_info['jg_register_id'])) {
(new JgPushService())->sendMsg($apply_info['jg_register_id'], '您的经销入驻请求审核' . ($params['status'] == 1 ? '通过' : '被拒绝'), '/pages/bindDistribution/index');
$res=(new JgPushService())->sendMsg($apply_info['jg_register_id'], '您的经销入驻请求审核' . ($params['status'] == 1 ? '通过' : '被拒绝'), '/pages/bindDistribution/index');
if($res!==true){
Db::rollback();
self::setError('极光推送失败:'.$res);
return false;
}
}
Db::commit();
return true;

View File

@ -2,6 +2,7 @@
namespace app\admin\logic\supplier;
use app\admin\logic\auth\AdminLogic;
use app\admin\logic\user\UserLogic;
use app\common\service\JgPushService;
use app\common\enum\OrderEnum;
@ -34,19 +35,19 @@ class SupplierLogic extends BaseLogic
{
Db::startTrans();
try {
$sys_labels='';
if(isset($params['sys_labels'])){
$sys_labels=explode(',',$params['sys_labels']);
$sys_labels= ','.implode(',',$sys_labels).',';
$sys_labels = '';
if (isset($params['sys_labels'])) {
$sys_labels = explode(',', $params['sys_labels']);
$sys_labels = ',' . implode(',', $sys_labels) . ',';
}
$res= Supplier::create([
$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,
'settle_cycle' => $params['settle_cycle'] ?? 15,
'interest_rate' => $params['interest_rate'] ?? 0,
'sys_labels' => $sys_labels,
'province_id' => $params['province_id'] ?? '',
'province_id' => $params['province_id'] ?? '',
'city_id' => $params['city_id'] ?? '',
'area_id' => $params['area_id'] ?? '',
'street_id' => $params['street_id'] ?? '',
@ -64,15 +65,15 @@ class SupplierLogic extends BaseLogic
'financial_wechat' => $params['financial_wechat'] ?? '',
'financial_alipay' => $params['financial_alipay'] ?? '',
'financial_type' => $params['financial_type'] ?? '',
'data_json'=>json_encode([
'data_json' => json_encode([
'company_address' => $params['address'] ?? '',
'company_nickname' => $params['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '',
'images'=>$params['images'][0] ?? '',
])
'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(),'jg_register_id'=>$params['jg_register_id']]);
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(), 'jg_register_id' => $params['jg_register_id']]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -90,49 +91,70 @@ class SupplierLogic extends BaseLogic
*/
public static function status(array $params): bool
{
$apply_info = Db::name('user_auth_shop')->where('id',$params['apply_id'])->findOrEmpty();
$apply_info = Db::name('user_auth_shop')->where('id', $params['apply_id'])->findOrEmpty();
Db::startTrans();
try {
if($params['status']==1){
$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){
Db::rollback();
throw new BusinessException(UserLogic::getError(), 0);
}
$data=[
'user_id'=>$res1['id'],
'status'=>1,
'apply_status'=>1,
'pid'=>$params['id']
if ($params['status'] == 1) {
$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
];
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
$res1 = UserLogic::add($user);
if ($res1 == false) {
Db::rollback();
self::setError(UserLogic::getError());
return false;
}
$admin=[
'name' => '供应商' . $params['service_phone'],
'account' => $params['service_phone'],
'dept_id' => [],
'jobs_id' => [],
'role_id' => [1],
'avatar' => '',
'password' => $params['service_phone'],
'password_confirm' => $params['service_phone'],
'disable' => 0,
'multipoint_login' => 1,
'root' => 0
];
Supplier::where('id', $params['id'])->update([
'status' => 0,
]);
Db::name('user_auth_shop')->where('id',$params['apply_id'])->update($data);
$res2 = AdminLogic::add($admin);
if ($res2 == false) {
Db::rollback();
self::setError(AdminLogic::getError());
return false;
}
$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
];
Supplier::where('id', $params['id'])->update([
'status' => 0,
]);
Db::name('user_auth_shop')->where('id', $params['apply_id'])->update($data);
}
if (!empty($apply_info['jg_register_id'])) {
(new JgPushService())->sendMsg($apply_info['jg_register_id'], '您的供应入驻请求审核' . ($params['status'] == 1 ? '通过' : '被拒绝'), '/pages/bindSupplier/index');
}
if(!empty($apply_info['jg_register_id'])){
(new JgPushService()) -> sendMsg($apply_info['jg_register_id'],'您的供应入驻请求审核'.($params['status']==1?'通过':'被拒绝'),'/pages/bindSupplier/index');
}
Db::commit();
return true;
} catch (\Exception $e) {
@ -153,43 +175,43 @@ class SupplierLogic extends BaseLogic
{
Db::startTrans();
try {
$sys_labels='';
if(isset($params['sys_labels'])){
$sys_labels=explode(',',$params['sys_labels']);
$sys_labels= ','.implode(',',$sys_labels).',';
$sys_labels = '';
if (isset($params['sys_labels'])) {
$sys_labels = explode(',', $params['sys_labels']);
$sys_labels = ',' . implode(',', $sys_labels) . ',';
}
Supplier::where('id', $params['id'])->update([
'category_id' => $params['category_id']??'',
'type_id' => $params['type_id'] ?? '',
'mer_name' => $params['mer_name'],
'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' => $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'],
'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['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '',
'images'=>$params['images'][0] ?? '',
])
'sys_labels' => $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'],
'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['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '',
'images' => $params['images'][0] ?? '',
])
]);
Db::commit();
@ -204,15 +226,16 @@ class SupplierLogic extends BaseLogic
/**
* @notes 设置余额
*/
public static function set_money($id,$set_money,$type=1){
public static function set_money($id, $set_money, $type = 1)
{
Db::startTrans();
try {
if($type==1){
Supplier::where('id',$id)->inc('mer_money',$set_money)->update();
if ($type == 1) {
Supplier::where('id', $id)->inc('mer_money', $set_money)->update();
$record = [
'financial_record_sn' => time(),
'order_id' => 0,
'number_sn' =>getNewOrderId('XTCZ') ,
'number_sn' => getNewOrderId('XTCZ'),
'user_id' => 0,
'financial_type' => OrderEnum::SYSTEM_SET,
'financial_pm' => OrderEnum::INCOME,
@ -222,18 +245,18 @@ class SupplierLogic extends BaseLogic
'mer_id' => $id,
];
FinancialRecord::create($record);
}else{
$money=Supplier::where('id',$id)->value('mer_money');
if($money<$set_money){
} else {
$money = Supplier::where('id', $id)->value('mer_money');
if ($money < $set_money) {
Db::rollback();
self::setError('余额不足');
return false;
}
Supplier::where('id',$id)->dec('mer_money',$set_money)->update();
Supplier::where('id', $id)->dec('mer_money', $set_money)->update();
$record = [
'financial_record_sn' => time(),
'order_id' => 0,
'number_sn' =>getNewOrderId('XTJS') ,
'number_sn' => getNewOrderId('XTJS'),
'user_id' => 0,
'financial_type' => OrderEnum::SYSTEM_SET,
'financial_pm' => OrderEnum::EXPENDITURE,
@ -275,31 +298,31 @@ class SupplierLogic extends BaseLogic
*/
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'] = '';
}
$data['supplier_banks'] = MerchantBank::where('supplier_id',$params['id'])->select()->each(function($item){
$item['is_check_text'] = $item->is_check_text;
$item['is_own_text'] = $item->is_own_text;
})->toArray();
$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'] = '';
}
$data['supplier_banks'] = MerchantBank::where('supplier_id', $params['id'])->select()->each(function ($item) {
$item['is_check_text'] = $item->is_check_text;
$item['is_own_text'] = $item->is_own_text;
})->toArray();
return $data->toArray();
}
/**
/**
* @notes 设置标签
* @param $params
* @return bool
@ -310,9 +333,9 @@ class SupplierLogic extends BaseLogic
try {
$value = $params['sys_labels'];
if (!empty($value)) {
if (!is_array($value)){
$value= ',' . $value . ',';
}else{
if (!is_array($value)) {
$value = ',' . $value . ',';
} else {
$value = ',' . implode(',', $value) . ',';
}
}
@ -323,4 +346,4 @@ class SupplierLogic extends BaseLogic
return false;
}
}
}
}

View File

@ -2,7 +2,6 @@
namespace app\api\controller\financial;
use app\api\controller\BaseApiController;
use app\api\lists\financial\FinancialRecordLists;
@ -46,4 +45,16 @@ class FinancialRecordController extends BaseApiController
}
return $this->dataLists((new FinancialRecordLists));
}
/**
* @notes 获取商户流水统计
* @return \think\response\Json
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function api_lists()
{
$this->request->__set('is_detail',1);
return $this->dataLists((new FinancialRecordLists));
}
}

View File

@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists;
use app\common\enum\OrderEnum;
use app\common\lists\ListsSearchInterface;
use app\common\model\financial\FinancialRecord;
use app\common\model\user\User;
/**
* 商户财务记录列表
@ -53,8 +54,24 @@ class FinancialRecordLists extends BaseAdminDataLists implements ListsSearchInte
];
$this->where = $where;
$searchWhere=$this->searchWhere;
$list = FinancialRecord::where($this->searchWhere)
$is_detail=$this->request->__get('is_detail');
if($is_detail==1){
$list = FinancialRecord::where($this->searchWhere)
->where($where)
->limit($this->limitOffset, $this->limitLength)
->order('create_time','desc')
->select()->each(function ($item) {
$item['user_nickname']='';
if($item['user_id']!=0){
$item['user_nickname']=User::where('id',$item['user_id'])->value('nickname');
}
$item['financial_pm']=$item['financial_pm']==0?"支出":"获得";
return $item;
});
}else{
$list = FinancialRecord::where($this->searchWhere)
->where($where)
->limit($this->limitOffset, $this->limitLength)
->field("FROM_UNIXTIME(create_time, '%Y-%m-%d') as record_date, SUM(number) as total_amount")
->group('record_date')
->order('record_date')
@ -63,7 +80,12 @@ class FinancialRecordLists extends BaseAdminDataLists implements ListsSearchInte
$item['cashier_total_amount'] = $cashier_total_amount;
$cashier_cash_total_amount=FinancialRecord::where($where)->where($searchWhere)->where('financial_type',OrderEnum::CASHIER_CASH_ORDER_PAY)->sum('number');
$item['cashier_cash_total_amount'] = $cashier_cash_total_amount;
$platofrm_total_amount=FinancialRecord::where($where)->where($searchWhere)->where('financial_type',OrderEnum::USER_ORDER_PAY)->sum('number');
$item['platofrm_total_amount'] = $platofrm_total_amount;
});
}
return $list?->toArray();
}

View File

@ -66,10 +66,12 @@ class OrderEnum
self::USER_ORDER_PAY=>'用户订单支付',
self::MERCHANT_ORDER_PAY=>'商户订单支付',
self::PLATFORM_ORDER_PAY=>'平台订单支付',
self::MERCHANT_ORDER_OBTAINS=>'商户订单提现',
self::MERCHANT_ORDER_OBTAINS=>'商户订单获得',
self::ORDER_HANDLING_FEES=>'订单手续费',
self::PLATFORM_ORDER_OBTAINS=>'平台订单获得',
self::SUPPLIER_ORDER_OBTAINS=>'供应商订单获得',
self::SYSTEM_SET=>'平台设置',
];
if ($value === true) {

View File

@ -4,7 +4,8 @@
use JPush\Client;
use support\Log;
use support\exception\BusinessException;
class JgPushService
{
@ -34,9 +35,10 @@
$this->push->iosNotification($message, ['extras' => ['route' => $route, 'type' => $type]]);
$this->push->send();
unset($this->client, $this->push);
return true;
} catch (\Exception $e) {
dump($e->getMessage());
Log::error($e->getMessage());
return $e->getMessage();
}
try {
$this->client = new Client($this->azKey, $this->azSecret);
@ -46,9 +48,11 @@
$this->push->androidNotification($message, ['extras' => ['route' => $route, 'type' => $type]]);
$this->push->send();
unset($this->client, $this->push);
return true;
} catch (\Exception $e) {
dump($e->getMessage());
Log::error($e->getMessage());
return $e->getMessage();
}
}
}