Commit be61d854 by lizhilin

更新

parent 27e6c88c
<?php
namespace App\Admin\Controllers;
use App\Admin\Forms\EditPermission;
use App\Admin\Forms\updatePassword;
use App\Models\User;
use App\Models\UserPermission;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Forms\UserCheckForm;
class UserCheckController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new User(), function (Grid $grid) {
$grid->addTableClass(['table-text-center']);
$grid->model()->where(['status' => 0])->orderBy('created_at', 'DESC');
$grid->column('id')->sortable();
$grid->column('avatar', '头像')->image('', 50, 50);
$grid->column('company', '公司名称');
$grid->column('phone', '手机号');
$grid->column('status')
->display('点击审核')->modal(function (Grid\Displayers\Modal $modal) {
// 标题
$modal->title('点击审核');
// 自定义图标
$modal->icon('feather icon-edit');
// 传递当前行字段值
return UserCheckForm::make()->payload(['id' => $this->id]);
});
$grid->column('created_at', '注册时间')->display(function ($val) {
return date("Y-m-d H:i:s", strtotime($this->created_at));
});
$grid->disableActions();
$grid->disableCreateButton();
$grid->filter(function (Grid\Filter $filter) {
// 更改为 panel 布局
$filter->panel();
$filter->like('phone')->width(3);
$filter->like('company')->width(3);
$filter->between('created_at', '创建时间')->datetime()->width(6);
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new User(), function (Show $show) {
$show->field('id');
$show->field('name');
$show->field('avatar');
$show->field('openid');
$show->field('phone');
$show->field('status');
$show->field('role');
$show->field('department');
$show->field('email');
$show->field('email_verified_at');
$show->field('password');
$show->field('remember_token');
$show->field('created_at');
$show->field('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new User(), function (Form $form) {
$form->text('name', '昵称');
$form->text('company', '公司名称');
$form->text('score', '积分');
// $form->image('avatar', '头像')
// ->url('upload/user-avatar')
// ->deleteUrl('upload/delete-public-cos-file')
// ->autoUpload();
// if ($form->isCreating()) {
// $form->mobile('phone', '手机号')->rules('required|unique:users,phone', ['required' => '手机号码不可为空', 'unique' => '此手机号码已存在,请重新填写']);
// $form->text('password', '密码');
// }
// if ($form->isCreating()) {
// $form->saving(function (Form $form) {
// $form->password = bcrypt($form->password);
// });
// }
});
}
}
<?php
namespace App\Admin\Forms;
use App\Models\User;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Illuminate\Support\Facades\DB;
class GenerateUserCode extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$num = (int)$input['num'];
if ($num <= 0 || $num > 20) {
$num = 20;
}
$data = [];
$i = 0;
$dcount = 0;
do {
$rndstr = generateRandomString(6);
$exist = DB::table("li_check_number")->where("code", $rndstr)->count();
if (!$exist) {
array_push($data, $rndstr);
}
$dcount = count($data);
} while ($i <= $num && $dcount != $num);
// for ($i = 0; $i <= $num; $i++) {
// $rndstr = generateRandomString(6);
// $exist = DB::table("li_check_number")->where("code", $rndstr)->count();
// if (!$exist) {
// array_push($data, $rndstr);
// }
// }
if ($data) {
foreach ($data as $code) {
$addtime = date("Y-m-d H:i:s");
DB::table("li_check_number")->insert(['code' => $code, 'created_at' => $addtime]);
}
}
return $this->response()->success('确认成功')->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->text('num', '生成数量')->required()->help("生成20个以内随机编号(数字+大小写英文)");
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
// 获取外部传递参数
return [];
}
}
<?php
namespace App\Admin\Forms;
use App\Models\User;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
class UserCheckForm extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$status = (int)$input['status'];
$order = User::find($this->payload['id']);
$order->status = $status;
$order->save();
return $this->response()->success('确认成功')->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->radio('status', '状态')->options([1 => '通过', 2 => '驳回'])->default(1)->required();
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
// 获取外部传递参数
return [];
}
}
<?php
namespace App\Admin\Repositories;
use App\Models\Verifier as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class Verifier extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}
......@@ -40,7 +40,6 @@
$router->resource('article', 'ArticleController'); //文章管理
$router->resource('goods', 'GoodController'); //商品管理
Route::get('goods-export', 'GoodController@export'); //导出
$router->resource('kefu', 'KefuController'); //平台客服
......@@ -52,10 +51,6 @@
$router->resource('user-share', 'ShareController'); //查看下级
$router->resource('user-check', 'UserCheckController'); //用户审核列表
$router->resource('check-number', 'CheckNumberController'); //审核编号列表
$router->resource('carousel', 'CarouselController'); //轮播图管理
$router->resource('merchant', 'MerchantController'); //商家管理
......
<?php
namespace App\Imports;
use App\Command\Log;
use App\Models\Brand;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\ToCollection;
use function Matrix\trace;
class ImportExcel implements ToCollection
{
private $className = null;
private $filename = null;
public function __construct($className, $filename)
{
$this->className = $className;
//文件存储后临时路径含文件名
$this->filename = $filename;
}
public function sheets(): array
{
// 只处理第一个sheet
return [
0 => $this,
];
}
/**
* @param Collection $collection
*/
public function collection(Collection $rows)
{
set_time_limit(0);
// 去掉表头
unset($rows[0]);
unset($rows[1]);
$data = $this->uploadImg($this->filename);
//Log::add('导入数据', $data);
DB::enableQueryLog();
$i = 0;
foreach ($data as $k => $item) {
if ($k == 0 || $k == 1) {
continue;
}
$i++;
$result = $this->className::CreateImportData($item);
if (!$result['goods_name']) {
continue;
}
$insert[] = $result;
$res = DB::table($this->className::getTableName())->insert($insert);
if ($res) {
$id = DB::getPdo()->lastInsertId();
$this->addGoodSku($result['sku'], $id);
}
}
// if (!empty($insert)) {
// DB::table($this->className::getTableName())->insert($insert);
// }
}
public function getExt($filename)
{
$arr = explode('.', $filename);
return array_pop($arr);
}
private function uploadImg($filepath)
{
$imageFilePath = public_path() . '/uploads/goods/' . date("Ymd") . "/";
if (!file_exists($imageFilePath)) {
mkdir("$imageFilePath", 0777, true);
chown("root", "www");
}
// 实例化阅读器对象。
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
// 将文件读取到到$spreadsheet对象中
//$filepath: storage\app/public/import/00c95d181f32fcbfca053e861cc13923.xlsx
$spreadsheet = $reader->load($filepath);
// 获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
$worksheet = $spreadsheet->getSheet(0);
$objWorksheet = $spreadsheet->getActiveSheet(0); //getSheet(0)
$data = $objWorksheet->toArray();
foreach ($objWorksheet->getDrawingCollection() as $drawing) {
list($startColumn, $startRow) = \PhpOffice\PhpSpreadsheet\cell\Coordinate::coordinateFromString($drawing->getCoordinates());
$imageFileName = strtolower($drawing->getIndexedFilename()); //获取文件名称
$filename = $drawing->getPath();
$extension = strtolower($drawing->getExtension());
switch ($extension) {
case 'jpg':
case 'jpeg':
$source = imagecreatefromjpeg($drawing->getPath());
imagejpeg($source, $imageFilePath . $imageFileName);
break;
case 'gif':
$source = imagecreatefromgif($drawing->getPath());
imagegif($source, $imageFilePath . $imageFileName);
break;
case 'png':
$source = imagecreatefrompng($drawing->getPath());
imagepng($source, $imageFilePath . $imageFileName);
break;
}
//Log::add('文件列', $startColumn);
$startColumn = $this->ABC2decimal($startColumn);
if ($startColumn != 9) {
//continue;
}
$data[$startRow - 1][$startColumn][] = $imageFileName ? "/goods/" . date("Ymd") . "/" . $imageFileName : '';
}
return $data;
}
public function ABC2decimal($abc)
{
$ten = 0;
$len = strlen($abc);
for ($i = 1; $i <= $len; $i++) {
$char = substr($abc, 0 - $i, 1); //反向获取单个字符
$int = ord($char);
$ten += ($int - 65) * pow(26, $i - 1);
}
return $ten;
}
private function addGoodSku($skuStr, $goods_id)
{
$skuArr = json_decode($skuStr, true);
$attrs = isset($skuArr['attrs']) ? $skuArr['attrs'] : [];
$attrsKey = $attrs ? array_keys($attrs) : [];
$data = [];
$goods_price = 0;
//Log::add('规格数据', $skuArr);
if (isset($skuArr['sku'])) {
foreach ($skuArr['sku'] as $kk => $vv) {
$tmp = [];
$tmp['goods_id'] = $goods_id;
$attr_name = [];
if ($kk == 0) {
$price = isset($vv['price']) ? explode("、", $vv['price']) : [];
$goods_price = isset($price[0]) ? $price[0] : 0;
}
foreach ($attrsKey as $val) {
array_push($attr_name, $vv[$val]);
}
utf8_array_asort($attr_name);
$attr_sn = join("、", $attr_name);
$tmp['attr_val'] = $attr_sn;
$tmp['attr_sn'] = $attr_sn ? md5($attr_sn) : '';
$tmp['content'] = json_encode($vv, JSON_UNESCAPED_UNICODE);
array_push($data, $tmp);
//规格标识
$skuArr['sku'][$kk]['attr_sn'] = $tmp['attr_sn'];
}
$skuCon = json_encode($skuArr, JSON_UNESCAPED_UNICODE);
DB::table('li_goods_sku')->insert($data);
DB::table('li_goods')->where("id", $goods_id)->update(['goods_price' => $goods_price, 'sku' => $skuCon]);
}
}
}
......@@ -37,7 +37,7 @@ public function __construct($className, $file_path)
*/
public function handle()
{
$toolOrder = new ImportExcel($this->className, $this->file_path);
//$toolOrder = new ImportExcel($this->className, $this->file_path);
Excel::import($toolOrder, $this->file_path);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment