代码优化

This commit is contained in:
sugar1569 2021-12-03 15:31:59 +08:00
parent 521a90bf53
commit 4632595806
18 changed files with 23 additions and 20 deletions

View File

@ -122,6 +122,7 @@ if (!function_exists('attr_format')) {
if ($i == 0) $data = $arr[$i]['detail'];
//替代变量1
$rep1 = [];
$rep4 = [];
foreach ($data as $v) {
foreach ($arr[$i + 1]['detail'] as $g) {
//替代变量2

View File

@ -82,7 +82,7 @@ class PublicController
if ($request->uid()) {
/** @var WechatUserServices $wechatUserService */
$wechatUserService = app()->make(WechatUserServices::class);
$subscribe = $wechatUserService->value(['uid' => $request->uid()], 'subscribe') ? true : false;
$subscribe = (bool)$wechatUserService->value(['uid' => $request->uid()], 'subscribe');
} else {
$subscribe = true;
}
@ -137,7 +137,7 @@ class PublicController
$brokerageFuncStatus = sys_config('brokerage_func_status');
$balanceFuncStatus = sys_config('balance_func_status');
$vipCard = sys_config('member_card_status', 0);
$svipOpen = sys_config('member_card_status') ? true : false;
$svipOpen = (bool)sys_config('member_card_status');
$userService = $invoiceStatus = $deliveryUser = $isUserPromoter = $userVerifyStatus = $userOrder = true;
if ($uid && $userInfo) {

View File

@ -45,7 +45,7 @@ class PublicController
$userService->offMemberLevel($request->uid());
/** @var WechatUserServices $wechatUserService */
$wechatUserService = app()->make(WechatUserServices::class);
$subscribe = $wechatUserService->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe') ? true : false;
$subscribe = (bool)$wechatUserService->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe');
} else {
$subscribe = true;
}
@ -75,7 +75,7 @@ class PublicController
*/
public function bindPhoneStatus()
{
$status = sys_config('store_user_mobile') ? true : false;
$status = (bool)sys_config('store_user_mobile');
return app('json')->success(compact('status'));
}
@ -87,7 +87,7 @@ class PublicController
*/
public function subscribe(Request $request, WechatUserServices $services)
{
return app('json')->success(['subscribe' => $services->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe') ? true : false]);
return app('json')->success(['subscribe' => (bool)$services->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe')]);
}
/**

View File

@ -69,7 +69,7 @@ if (!function_exists('sys_config')) {
if (strpos($sysConfig, '/uploads/system/') !== false) $sysConfig = set_file_url($sysConfig);
}
$config = is_array($sysConfig) ? $sysConfig : trim($sysConfig);
if ($config === '' || $config === false) {
if ($config === '' || $config == false) {
return $default;
} else {
return $config;

View File

@ -378,6 +378,7 @@ abstract class BaseDao
$result = $this->getOne([$keyField => $key]);
}
if (!$result) return false;
$new = 0;
if ($type === 1) {
$new = bcadd($result[$incField], $inc, $acc);
} else if ($type === 2) {

View File

@ -192,7 +192,7 @@ class OrderJob extends BaseJobs
$cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
/** @var SmsSendServices $smsServices */
$smsServices = app()->make(SmsSendServices::class);
$switch = sys_config('admin_pay_success_switch') ? true : false;
$switch = (bool)sys_config('admin_pay_success_switch');
foreach ($serviceOrderNotice as $key => $item) {
$admin_name = $item['nickname'];
$order_id = $order['order_id'];
@ -256,7 +256,7 @@ class OrderJob extends BaseJobs
*/
public function mssageSendPaySuccess($order)
{
$switch = sys_config('lower_order_switch') ? true : false;
$switch = (bool)sys_config('lower_order_switch');
//模板变量
$pay_price = $order['pay_price'];
$order_id = $order['order_id'];

View File

@ -100,7 +100,7 @@ class Common extends BaseController
$tourist_avatar = sys_config('tourist_avatar');
$avatar = Arr::getArrayRandKey(is_array($tourist_avatar) ? $tourist_avatar : []);
$userInfo['tourist_avatar'] = $uid ? '' : $avatar;
$userInfo['is_tourist'] = $tourist_uid ? true : false;
$userInfo['is_tourist'] = (bool)$tourist_uid;
return app('json')->success($userInfo->toArray());
} else {
return app('json')->fail('暂无客服人员');

View File

@ -103,7 +103,7 @@ class NoticeService extends BaseServices
'partner' => sys_config('develop_id', ''),
'terminal' => sys_config('terminal_number', '')
];
$switch = sys_config('pay_success_printing_switch') ? true : false;
$switch = (bool)sys_config('pay_success_printing_switch');
if (!$switch) {
throw new ValidateException('小票打印未开启!');
}

View File

@ -38,7 +38,7 @@ class EnterpriseWechatService extends NoticeService
*/
public function isOpen(string $mark)
{
$this->isopend = ($this->notceinfo['is_ent_wechat'] == 1 && $this->notceinfo['url'] !== '') ? true : false;
$this->isopend = $this->notceinfo['is_ent_wechat'] == 1 && $this->notceinfo['url'] !== '';
return $this;
}

View File

@ -39,7 +39,7 @@ class NoticeSmsService extends NoticeService
*/
public function isOpen(string $mark)
{
$this->isopend = $this->notceinfo['is_sms'] === 1 ? true : false;
$this->isopend = $this->notceinfo['is_sms'] === 1;
return $this;
}
@ -57,7 +57,7 @@ class NoticeSmsService extends NoticeService
public function sendSms($phone, array $data, string $template)
{
try {
$this->isopend = $this->notceinfo['is_sms'] === 1 ? true : false;
$this->isopend = $this->notceinfo['is_sms'] === 1;
if ($this->isopend) {
SmsJob::dispatch('doJob', [$phone, $data, $template]);
}

View File

@ -148,6 +148,6 @@ class DeliveryServiceServices extends BaseServices
*/
public function checkoutIsService(int $uid)
{
return $this->dao->count(['uid' => $uid, 'status' => 1]) ? true : false;
return (bool)$this->dao->count(['uid' => $uid, 'status' => 1]);
}
}

View File

@ -562,6 +562,6 @@ class CopyTaobaoServices extends BaseServices
*/
public function createSpu()
{
return substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8) . str_pad((string)mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
return substr(implode('NULL', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8) . str_pad((string)mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
}
}

View File

@ -106,7 +106,7 @@ class SystemAttachmentCategoryServices extends BaseServices
public function form($info = [])
{
return [
Form::select('pid', '上级分类', (int)($info['pid'] ?? ''))->setOptions($this->getCateList(['pid' => 0]))->filterable(1),
Form::select('pid', '上级分类', (int)($info['pid'] ?? ''))->setOptions($this->getCateList(['pid' => 0]))->filterable(true),
Form::input('name', '分类名称', $info['name'] ?? '')->maxlength(30),
];
}

View File

@ -274,7 +274,7 @@ class UserRechargeServices extends BaseServices
*/
public function getOrderId()
{
return 'wx' . date('YmdHis', time()) . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
return 'wx' . date('YmdHis', time()) . substr(implode('NULL', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
/**

View File

@ -541,7 +541,7 @@ class FileService
$content = file_get_contents($path);
$content = string::chang_code($content, $input_code, $out_code);
$fp = fopen($path, 'w');
return fputs($fp, $content) ? TRUE : FALSE;
return (bool)fputs($fp, $content);
fclose($fp);
}
}

View File

@ -60,7 +60,7 @@ trait CurdControllerTrait
foreach ($data as $key => $value) {
$modelData->{$key} = $value;
}
return $modelData->save() ? true : $this->setErrorInfo('保存失败');
return $modelData->save() || $this->setErrorInfo('保存失败');
}
/**

View File

@ -156,6 +156,7 @@ class Canvas
$file = str_replace('https', 'http', $file);
$imagesize = getimagesize($file);
$type = image_type_to_extension($imagesize[2], true);
$canvas = null;
switch ($type) {
case '.png':
$canvas = imagecreatefrompng($file);

View File

@ -270,7 +270,7 @@ switch ($step) {
case '4':
if (intval($_GET['install'])) {
$n = intval($_GET['n']);
if ($i == 999999)
if ($n == 999999)
exit;
$arr = array();