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.
393 lines
18 KiB
393 lines
18 KiB
<?php
|
|
namespace app\api\controller;
|
|
use think\Request;
|
|
use app\admin\model\Finance;
|
|
use think\Controller;
|
|
use app\admin\model\Product as Pro;
|
|
use app\admin\model\Procategory;
|
|
use app\admin\model\Proquarter;
|
|
class Product extends Controller{
|
|
public function __construct(){
|
|
$request=request();
|
|
$action=$request->action();
|
|
$post = $request->post();
|
|
$params=isset($post['data'])?$post['data']:[];
|
|
|
|
$keys=[
|
|
'import'=>'9417aaa07a16d1fa',
|
|
'importartbook'=>'2ce09d0fd2a21809',
|
|
'importebook'=>'2fdd1f00234aca81',
|
|
];
|
|
$agencykey=isset($keys[$action])?$keys[$action]:'';
|
|
|
|
if(empty($agencykey)){
|
|
$this->error('缺少参数');
|
|
}
|
|
if (!isset($post['time'])) {
|
|
$this->error('缺少参数');
|
|
}
|
|
$timestamp = $post['time'];
|
|
if (empty($timestamp)) {
|
|
$this->error('缺少参数');
|
|
}
|
|
// 判断token
|
|
$token =$post['token'];
|
|
if(!$token) {
|
|
$this->error('缺少参数');
|
|
}
|
|
$curtime = time();
|
|
$expire = 60; // 允许延迟秒数
|
|
if (!$timestamp || $timestamp > $curtime || ($timestamp + $expire) < $curtime) {
|
|
$this->error('token验证超时');
|
|
}
|
|
$sign = $this->getSign($agencykey, $post);
|
|
if ($token != $sign) {
|
|
$this->error('token验证失败');
|
|
}
|
|
|
|
}
|
|
|
|
// 获取sign
|
|
protected function getSign($secret, $data)
|
|
{
|
|
if (isset($data['token']))
|
|
unset($data['token']);
|
|
// 对数组的值按key排序
|
|
ksort($data);
|
|
// 生成url的形式
|
|
$params = http_build_query($data);
|
|
// 生成sign
|
|
$sign = md5($params.$secret);
|
|
return $sign;
|
|
}
|
|
/**
|
|
* 拍品电子图录
|
|
* @param Request $request
|
|
*/
|
|
public function importebook(Request $request){
|
|
$params=$request->post();
|
|
|
|
$childs=db('procategory')->field('id,code')->select();
|
|
|
|
if(count($childs)){
|
|
$ids=array_column($childs, 'id');
|
|
$titles=array_column($childs, 'code');
|
|
$childs=array_combine($titles,$ids);
|
|
}
|
|
|
|
if(isset($params['data'])&&$params['type']=='product'){
|
|
$sort=db('product')->min('sort');
|
|
$products=$params['data'];
|
|
if(count($products)){
|
|
$addlist=[];
|
|
$updlist=[];
|
|
foreach ($products as $row){
|
|
$item=[];
|
|
$sort--;
|
|
if($sort<1)$sort=1;
|
|
$cids='';
|
|
if(isset($row['category'])&&count($row['category'])){
|
|
foreach ($row['category'] as $jo){
|
|
if($jo['parentid']!=0){
|
|
$code='tuku_'.$jo['childid'];
|
|
$cid=isset($childs[$code])?$childs[$code]:'';
|
|
if($cid)$cids=$cid;
|
|
}
|
|
}
|
|
}
|
|
$item['cid']= $cids;
|
|
$item['title']=$row['name'];
|
|
$item['code']=$row['code'];
|
|
$item['author']=$row['author'];
|
|
$item['size']=$row['size'];
|
|
$item['material']=$row['material'];
|
|
$item['year']=$row['period'];
|
|
$item['poster']=$row['poster'];
|
|
$item['gprice']=$row['guide_price'];
|
|
$item['price']=$row['seller_price'];
|
|
$item['video']=$row['video'];
|
|
$item['description']=$row['description'];
|
|
$item['photos']=isset($row['photos'])&&count($row['photos'])?implode(',', $row['photos']):'';
|
|
$item['status']=$row['status'];
|
|
$item['create_time']=time();
|
|
$item['sort']=$sort;
|
|
$check=db('product')->where(['code'=>$row['code']])->field('id')->find();
|
|
if($check){
|
|
$item['id']=$check['id'];
|
|
array_push($updlist,$item);
|
|
}else{
|
|
array_push($addlist,$item);
|
|
}
|
|
}
|
|
$finance=new Pro();
|
|
if(count($addlist))$finance->saveAll($addlist);
|
|
if(count($updlist))$finance->saveAll($updlist);
|
|
echo json_encode(['code'=>'200','msg'=>'success']);exit;
|
|
}
|
|
|
|
}
|
|
if(isset($params['data'])&&$params['type']=='category'){
|
|
$categorys=$params['data'];
|
|
if(count($categorys)){
|
|
|
|
$addplist=[];
|
|
$updplist=[];
|
|
$addlist=[];
|
|
$updlist=[];
|
|
|
|
foreach ($categorys as $row){
|
|
$pid=$row['parent'];
|
|
if($pid==0){
|
|
$item=[];
|
|
$name=trim($row['name']);
|
|
$item['title']=$name;
|
|
$item['status']=$row['status'];
|
|
$item['code']=$row['code'];
|
|
$check=db('proquarter')->where(['title'=>$name])->field('id')->find();
|
|
if($check){
|
|
$item['id']=$check['id'];
|
|
array_push($updplist,$item);
|
|
}else{
|
|
$item['create_time']=time();
|
|
array_push($addplist,$item);
|
|
}
|
|
}
|
|
}
|
|
|
|
$finance=new Proquarter();
|
|
if(count($addplist))$finance->saveAll($addplist);
|
|
if(count($updplist))$finance->saveAll($updplist);
|
|
|
|
foreach ($categorys as $row){
|
|
$pid=$row['parent'];
|
|
if($pid){
|
|
$pcode='tuku_'.$row['parent'];
|
|
$check=db('proquarter')->where(['code'=>$pcode])->field('id')->find();
|
|
$item=[];
|
|
$name=trim($row['name']);
|
|
$item['title']=$name;
|
|
$item['pid']=$check['id'];
|
|
$item['status']=$row['status'];
|
|
$item['code']=$row['code'];
|
|
$check=db('procategory')->where(['title'=>$name,'pid'=>$check['id']])->field('id')->find();
|
|
if($check){
|
|
$item['id']=$check['id'];
|
|
array_push($updlist,$item);
|
|
}else{
|
|
$item['create_time']=time();
|
|
array_push($addlist,$item);
|
|
}
|
|
}
|
|
}
|
|
|
|
$finance=new Procategory();
|
|
if(count($addlist))$finance->saveAll($addlist);
|
|
if(count($updlist))$finance->saveAll($updlist);
|
|
|
|
echo json_encode(['code'=>'200','msg'=>'success']);exit;
|
|
}
|
|
}
|
|
echo json_encode(['code'=>'404','msg'=>'failure']);exit;
|
|
}
|
|
/**
|
|
* 艺术品溯源簿
|
|
* @param Request $request
|
|
*/
|
|
public function importartbook(Request $request){
|
|
$params=$request->post();
|
|
|
|
$configs=config('artbook');
|
|
if(isset($params['data'])&&$params['type']=='product'){
|
|
$sort=db('finance')->where(['c_kind'=>9])->max('c_order');
|
|
$products=$params['data'];
|
|
if(count($products)){
|
|
$finance=new Finance();
|
|
$addlist=[];
|
|
$updlist=[];
|
|
foreach ($products as $row){
|
|
$sort++;
|
|
$item=[];
|
|
$item['c_code']=$row['code'];
|
|
$item['c_name']=$row['name'];
|
|
|
|
$pid='';
|
|
if(isset($row['category'])&&count($row['category'])){
|
|
$parents=array_column($row['category'],'parentid');
|
|
$childs=array_column($row['category'],'childid');
|
|
foreach ($childs as $jo){
|
|
$code='tuku_'.$jo;
|
|
foreach ($configs as $key=>$vo){
|
|
if($vo['code']==$code)$pid=$key;
|
|
}
|
|
}
|
|
}
|
|
$item['c_parent']=$pid;
|
|
$item['c_content']=$row['information'];
|
|
$item['c_size']=$row['size'];
|
|
$item['c_material']=$row['material'];
|
|
$item['c_year']=$row['period'];
|
|
$item['c_logo']=$row['poster'];
|
|
$item['c_photos']=isset($row['photos'])&&count($row['photos'])?implode(',', $row['photos']):'';
|
|
$item['c_status']=$row['status'];
|
|
$item['c_gptime']=isset($row['release_at'])&&$row['release_at']?$row['release_at']:time();
|
|
$item['c_infostime']=isset($row['stime'])?$row['stime']:time();
|
|
$item['c_infoetime']=isset($row['etime'])?$row['etime']:time();
|
|
$item['c_infostime']=time();
|
|
$item['c_kind']=9;
|
|
$item['c_time']=time();
|
|
$item['c_order']=$sort;
|
|
$item['c_num']=isset($row['num'])?$row['num']:1;
|
|
$item['c_class']=isset($row['style'])?$row['style']:'';
|
|
$check=Finance::where(['c_code'=>$row['code'],'c_kind'=>9])->field('c_id')->find();
|
|
if($check){
|
|
$item['c_id']=$check['c_id'];
|
|
array_push($updlist,$item);
|
|
}else{
|
|
array_push($addlist,$item);
|
|
}
|
|
}
|
|
if(count($addlist))$finance->saveAll($addlist);
|
|
if(count($updlist))$finance->saveAll($updlist);
|
|
echo json_encode(['code'=>'200','msg'=>'success']);exit;
|
|
}
|
|
|
|
}
|
|
if(isset($params['data'])&&$params['type']=='category'){
|
|
$categorys=$params['data'];
|
|
if(count($categorys)){
|
|
foreach ($categorys as $row){
|
|
$pid=$row['parent'];
|
|
if($pid==0){
|
|
$name=trim($row['name']);
|
|
$code=$row['code'];
|
|
$check=false;
|
|
foreach($configs as $k=>$jo){
|
|
if($jo['title']==$name){
|
|
$check=true;
|
|
$configs[$k]['code']=$code;
|
|
}
|
|
}
|
|
if(!$check){
|
|
array_push($configs,array('name'=>$name,'code'=>$code));
|
|
}
|
|
}
|
|
}
|
|
config('artbook',$configs);
|
|
|
|
$html="<?php\r\n";
|
|
$html.="return ";
|
|
if(count($configs)){
|
|
$html.=var_export($configs,true);
|
|
}
|
|
|
|
$html.=";";
|
|
$html.="\r\n?>";
|
|
$path =ROOT_PATH.'app/extra/';
|
|
$url=$path.'artbook.php';
|
|
file_put_contents($url, $html);
|
|
|
|
echo json_encode(['code'=>'200','msg'=>'success']);exit;
|
|
}
|
|
}
|
|
echo json_encode(['code'=>'404','msg'=>'failure']);exit;
|
|
}
|
|
/**
|
|
* 资产托管平台
|
|
* @param Request $request
|
|
*/
|
|
public function import(Request $request){
|
|
$params=$request->post();
|
|
$configs=config('tuoguan');
|
|
$pconfigs=$configs['parents'];
|
|
$cconfigs=$configs['childs'];
|
|
|
|
|
|
if(isset($params['data'])&&$params['type']=='product'){
|
|
$products=$params['data'];
|
|
$sort=db('finance')->where(['c_kind'=>4])->max('c_order');
|
|
if(count($products)){
|
|
$finance=new Finance();
|
|
$addlist=[];
|
|
$updlist=[];
|
|
foreach ($products as $row){
|
|
|
|
$sort++;
|
|
$item=[];
|
|
$item['c_code']=$row['code'];
|
|
$item['c_name']=$row['name'];
|
|
|
|
$parents=[];
|
|
$childs=[];
|
|
$childsstr='';
|
|
if(isset($row['category'])&&count($row['category'])){
|
|
$parentids=array_column($row['category'],'parentid');
|
|
|
|
foreach ($row['category'] as $ko){
|
|
$kpid=$ko['parentid'];
|
|
$kcid=$ko['childid'];
|
|
$kname=$ko['name'];
|
|
if(empty($kcid)){
|
|
$pindex=array_search($kname, $pconfigs);
|
|
if(!in_array($pindex, $parents))$parents[$kpid]=$pindex;
|
|
continue;
|
|
}
|
|
|
|
if(!empty($kcid)){
|
|
$pindex=isset($parents[$kpid])?$parents[$kpid]:'';
|
|
if($pindex){
|
|
$childslist=$cconfigs[$pindex];
|
|
$cindex=array_search($kname, $childslist);
|
|
if($cindex!=false){
|
|
if(!isset($childs[$pindex]))$childs[$pindex]=[];
|
|
array_push($childs[$pindex], $pindex.'-'.$cindex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(count($childs)){
|
|
foreach ($childs as $zo){
|
|
$childsstr.=implode(',', $zo).";";
|
|
}
|
|
$childsstr=rtrim($childsstr,";");
|
|
}
|
|
}
|
|
|
|
$item['c_parent']=implode(',', $parents);
|
|
$item['c_child']=$childsstr;
|
|
$item['c_price']=$row['seller_price'];
|
|
$item['c_gprice']=$row['guide_price'];
|
|
$item['c_tprice']=$row['third_price'];
|
|
$item['c_size']=$row['size'];
|
|
$item['c_video']=$row['video'];
|
|
$item['c_content']=$row['description'];
|
|
$item['c_material']=$row['material'];
|
|
$item['c_year']=$row['period'];
|
|
$item['c_logo']=$row['poster'];
|
|
$item['c_photos']=isset($row['photos'])&&count($row['photos'])?implode(',', $row['photos']):'';
|
|
$item['c_status']=$row['status'];
|
|
$item['c_gptime']=isset($row['release_at'])&&$row['release_at']?$row['release_at']:time();
|
|
$item['c_evaluation']=$row['comment'];
|
|
$item['c_infostime']=isset($row['stime'])?$row['stime']:time();
|
|
$item['c_infoetime']=isset($row['etime'])?$row['etime']:time();
|
|
$item['c_kind']=4;
|
|
$item['c_time']=time();
|
|
$item['c_order']=$sort;
|
|
$item['c_num']=isset($row['num'])?$row['num']:1;
|
|
$item['c_class']=isset($row['style'])?$row['style']:'';
|
|
$check=Finance::where(['c_code'=>$row['code'],'c_kind'=>4])->field('c_id')->find();
|
|
if($check){
|
|
$item['c_id']=$check['c_id'];
|
|
array_push($updlist,$item);
|
|
}else{
|
|
array_push($addlist,$item);
|
|
}
|
|
}
|
|
if(count($addlist))$finance->saveAll($addlist);
|
|
if(count($updlist))$finance->saveAll($updlist);
|
|
echo json_encode(['code'=>'200','msg'=>'success']);exit;
|
|
}
|
|
|
|
}
|
|
echo json_encode(['code'=>'404','msg'=>'failure']);exit;
|
|
}
|
|
}
|