110 行
3.3 KiB
PHP
可执行文件
110 行
3.3 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Business;
|
|
|
|
use Retail\Model\UnitLibraryModel;
|
|
//[1.7.90]
|
|
/**
|
|
* 单位库
|
|
* Class UnitLibrary
|
|
* [
|
|
* 批量添加单位 addUnit
|
|
* ]
|
|
* @package Common\Business
|
|
*/
|
|
class UnitLibrary
|
|
{
|
|
/**
|
|
* 批量添加单位
|
|
* @param $param
|
|
* [
|
|
* user_type 3商户 4门店
|
|
* merchant_id
|
|
* store_id
|
|
* company_arr 单位集合 json字符串
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function addUnit($param)
|
|
{
|
|
$VerifyClass = new VerifyParam();
|
|
$verifyResult = $VerifyClass->identityVerify($param);
|
|
if ($verifyResult['status'] != 1) {
|
|
return $verifyResult;
|
|
}
|
|
if (empty($param['company_arr'])) {
|
|
return callBack(statusCode()['error'], '请传入单位');
|
|
}
|
|
$arr = json_decode($param['company_arr'], true);
|
|
if (!is_array($arr)) {
|
|
return callBack(statusCode()['error'], '单位格式有误');
|
|
}
|
|
$where = [
|
|
'state' => 1,
|
|
];
|
|
$data = [
|
|
'state' => 1,
|
|
'merchant_id' => $param['merchant_id'],
|
|
'add_time' => $_SERVER['REQUEST_TIME']
|
|
];
|
|
switch ($param['user_type']) {
|
|
case 3:
|
|
$where[] = [
|
|
[
|
|
'merchant_id' => $param['merchant_id'],
|
|
'type'=>1
|
|
],
|
|
[
|
|
'type'=>0
|
|
],
|
|
'_logic'=>'or'
|
|
];
|
|
$data['type'] = 1;
|
|
break;
|
|
case 4:
|
|
$where[] = [
|
|
[
|
|
'store_id'=>$param['store_id'],
|
|
'merchant_id'=>$param['merchant_id'],
|
|
'type'=>2
|
|
],
|
|
[
|
|
'type'=>0
|
|
],
|
|
'_logic'=>'or'
|
|
];
|
|
$data['type'] = 2;
|
|
$data['store_id'] = $param['store_id'];
|
|
break;
|
|
}
|
|
$new_arr = [];
|
|
try {
|
|
M()->startTrans();
|
|
$UnitModel = new UnitLibraryModel();
|
|
$list = $UnitModel->getFindField($where,'name',true);
|
|
$list = $list?$list:[];
|
|
foreach ($arr as $val) {
|
|
if (!in_array($val,$list)) {
|
|
//不存在的
|
|
$list[] = $val;
|
|
$data['name'] = $val;
|
|
$new_arr[] = $data;
|
|
}
|
|
}
|
|
if (!empty($new_arr)) {
|
|
$id = $UnitModel->addAll($new_arr);
|
|
if ($id) {
|
|
M()->commit();
|
|
return callBack(statusCode()['success'], '单位添加成功');
|
|
} else {
|
|
M()->rollback();
|
|
return callBack(statusCode()['error'], '单位添加失败');
|
|
}
|
|
}
|
|
M()->commit();
|
|
return callBack(statusCode()['success'], '暂无可添加单位');
|
|
} catch (\Exception $e) {
|
|
return callBack(statusCode()['success'], '暂无可添加单位');
|
|
}
|
|
}
|
|
} |