启程易购后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.3 KiB

10 months ago
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system;
9 months ago
use app\common\repositories\store\LotteryRepository;
use app\validate\admin\DepositValidate;
10 months ago
use crmeb\basic\BaseController;
use think\App;
9 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Request;
10 months ago
class Lottery extends BaseController
{
/**
9 months ago
* @var LotteryRepository
10 months ago
*/
protected $repository;
/**
* CacheRepository constructor.
* @param App $app
*/
9 months ago
public function __construct(App $app, LotteryRepository $repository)
10 months ago
{
parent::__construct($app);
$this->repository = $repository;
}
/**
* @return mixed
9 months ago
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-05-07
10 months ago
*/
9 months ago
public function lst()
10 months ago
{
9 months ago
return app('json')->success($this->repository->getList([]));
10 months ago
}
/**
9 months ago
* @param $id
* @param DepositValidate $validate
10 months ago
* @return mixed
9 months ago
* @throws DbException
* @author xaboy
* @day 2020-05-07
10 months ago
*/
9 months ago
public function save()
10 months ago
{
9 months ago
$data = Request::post();
10 months ago
9 months ago
if(count($data) != 8){
return app('json')->fail('参数错误');
}
10 months ago
9 months ago
$total = array_sum(array_column($data, 'rate'));
if($total != 100)
return app('json')->fail('总概率不等于100');
10 months ago
9 months ago
foreach ($data as $item){
$this->repository->update($item['id'], array('type' => $item['type'], 'value' => $item['value'], 'rate' => $item['rate']));
10 months ago
}
9 months ago
return app('json')->success('保存成功');
10 months ago
}
}