72 lines
2.0 KiB
PHP
72 lines
2.0 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\admin\model\v1\LanguageModel;
|
|
use app\admin\model\v1\ProductCategoryModel;
|
|
use app\admin\model\v1\ProductTcoCategoryModel;
|
|
use think\facade\Db;
|
|
|
|
class Operate_Of_ReceiveSync
|
|
{
|
|
const Add = 'add';
|
|
const Update = 'update';
|
|
const Enable = 'enable';
|
|
const Disable = 'disable';
|
|
}
|
|
|
|
/**
|
|
* 接收同步数据
|
|
*/
|
|
class ReceiveSync
|
|
{
|
|
public function product_category()
|
|
{
|
|
$data = request()->post();
|
|
if (empty($data)) return error('请确认同步数据');
|
|
|
|
$lang_id = LanguageModel::where('code', $data['lang'])->value('id');
|
|
$record = [
|
|
'language_id' => $lang_id,
|
|
'name' => $data['name'],
|
|
'tco_id' => $data['tco_id'],
|
|
'tco_pid' => $data['tco_pid'],
|
|
'tco_path' => $data['tco_path'],
|
|
'erp_id' => $data['erp_id'],
|
|
'erp_pid' => $data['erp_pid'],
|
|
'erp_code' => $data['erp_code'],
|
|
'erp_path' => $data['erp_path'],
|
|
'disabled' => 0,
|
|
'sync_time' => strtotime($data['created_at'])
|
|
];
|
|
|
|
if (Operate_Of_ReceiveSync::Disable == $data['operate']) {
|
|
$record['disabled'] = 1;
|
|
}
|
|
|
|
$validate = validate([
|
|
'name|分类名称' => 'require',
|
|
'erp_code|分类ERP编码' => 'require',
|
|
]);
|
|
if (!$validate->check($record)) {
|
|
throw new \Exception((string)$validate->getError());
|
|
}
|
|
|
|
$category = ProductTcoCategoryModel::language($lang_id)->erpCode($record['erp_code'])->find();
|
|
Db::startTrans();
|
|
try {
|
|
if (empty($category)) {
|
|
ProductTcoCategoryModel::create($record);
|
|
ProductCategoryModel::where
|
|
} else {
|
|
$category->save($record);
|
|
}
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
throw $th;
|
|
}
|
|
|
|
}
|
|
}
|