Browse Source

优化

master
wanghongjun 3 years ago
parent
commit
13442ec5f1
  1. 26
      app/common.php
  2. 9
      app/controller/Zone.php
  3. 6
      app/model/ZoneGoods.php

26
app/common.php

@ -139,4 +139,30 @@ function rand_avatar()
$avatarArr = config('custom.avatar') ?: [];
$rand = rand(0,count($avatarArr));
return $avatarArr[$rand] ?: '';
}
/**
* 返回金额
* @param $number
* @return string
*/
function format_money($number) {
$units = array("万元", "亿元");
$unitMaxValue = 10000; // 单位最大值
$unitIndex = 0; // 单位索引
if ($number >= $unitMaxValue && $number % $unitMaxValue === 0) {
while (abs($number) >= $unitMaxValue && $unitIndex < count($units) - 1) {
$number = $number / $unitMaxValue;
$unitIndex++;
}
$formattedNumber = number_format($number, 0) . $units[$unitIndex];
} elseif ($number % $unitMaxValue === 0) {
$formattedNumber = $number / $unitMaxValue . $units[0];
} else {
$formattedNumber = $number . '元';
}
return $formattedNumber;
}

9
app/controller/Zone.php

@ -46,11 +46,14 @@ class Zone extends BaseController
$param = Request::param();
$zoneGoodsId = $param['zone_goods_id'];
$userData = Session::get('login_user_data');
$info = ZoneGoods::where('status',1)->field('important,content,price,bg_image')->find()->toArray();
$info = ZoneGoods::where(['status' => 1,'id' => $zoneGoodsId])
->field('max_awards_amount,content,price,bg_image')
->find()
->toArray();
$info['important'] = '最高中奖金额'.format_money($info['max_awards_amount']);
if ($info['bg_image']) $info['bg_image'] = get_image_url($info['bg_image']);
unset($info['max_awards_amount']);
return $this->renderSuccess('数据返回成功',['data' => $info]);
}

6
app/model/ZoneGoods.php

@ -10,12 +10,14 @@ class ZoneGoods extends \think\Model
$where = $is_manage ? ['status' => 1] : [];
if (isset($param['zone_id'])) $where['zone_id'] = $param['zone_id'];
$field = 'id,title,important,price,cover_image,status';
$field = 'id,title,max_awards_amount,price,cover_image,status';
$list = self::where($where)->field($field)->order('id desc')->select()->toArray();
foreach ($list as &$item) {
if ($item['cover_image']) $item['cover_image'] = get_image_url($item['cover_image']);
if (!$is_manage) {
$item['important'] = '最高中奖金额'.format_money($item['max_awards_amount']);
unset($item['status']);
unset($item['max_awards_amount']);
}
}
return $list;
@ -23,7 +25,7 @@ class ZoneGoods extends \think\Model
public static function getFind($id)
{
#$item = self::find($id)->field('id,important,cover_image')->toArray();
#$item = self::find($id)->field('id,max_awards_amount,cover_image')->toArray();
#if ($item['bg_image']) $item['bg_image'] = get_image_url($item['bg_image']);
#return $item;
}

Loading…
Cancel
Save