@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\Pharmacy;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatform;
|
||||
use App\Utils\Log;
|
||||
@@ -21,6 +22,18 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
#[Command]
|
||||
class getProductCommand extends HyperfCommand
|
||||
{
|
||||
protected array $active_pharmacies = [];
|
||||
|
||||
protected function getPharmacy(string $code)
|
||||
{
|
||||
if (empty($this->active_pharmacies)) {
|
||||
$list = Pharmacy::where('status', 1)->get();
|
||||
foreach ($list as $p) {
|
||||
$this->active_pharmacies[$p->pharmacy_code] = $p;
|
||||
}
|
||||
}
|
||||
return $this->active_pharmacies[$code] ?? null;
|
||||
}
|
||||
public function __construct(protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('getProduct:command');
|
||||
@@ -117,13 +130,8 @@ class getProductCommand extends HyperfCommand
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
|
||||
$pharmacy_code = \Hyperf\Config\config("prescription_platform.pharmacy_code");
|
||||
if (empty($pharmacy_code)) {
|
||||
$pharmacy_code = "JG-10009";
|
||||
}
|
||||
|
||||
// 非药店编码
|
||||
if ($pharmacy_code != $item['thirdCode']) {
|
||||
$pharmacy = $this->getPharmacy($item['thirdCode']);
|
||||
if (empty($pharmacy)) {
|
||||
Db::rollBack();
|
||||
return false;
|
||||
}
|
||||
@@ -133,6 +141,7 @@ class getProductCommand extends HyperfCommand
|
||||
$params['product_platform_code'] = $item['drugCode'];
|
||||
$params['product_pharmacy_code'] = $item['thirdDrugCode'];
|
||||
$params['license_number'] = $item['approvalNumber'];
|
||||
$params['pharmacy_code'] = $item['thirdCode'];
|
||||
$product_platform = ProductPlatform::getOne($params);
|
||||
if (!empty($product_platform)) {
|
||||
// 已存在,更新
|
||||
@@ -214,6 +223,10 @@ class getProductCommand extends HyperfCommand
|
||||
}
|
||||
}
|
||||
|
||||
$product_platform_data['pharmacy_code'] = $item['thirdCode'];
|
||||
$product_data['pharmacy_code'] = $item['thirdCode'];
|
||||
$product_data['pharmacy_id'] = (string)$pharmacy->pharmacy_id;
|
||||
|
||||
if (!empty($product_platform_data)) {
|
||||
// 更新商品表-处方平台
|
||||
$params = array();
|
||||
@@ -236,6 +249,7 @@ class getProductCommand extends HyperfCommand
|
||||
} else {
|
||||
// 不存在,创建
|
||||
$data = array();
|
||||
$data['pharmacy_code'] = $item['thirdCode'];
|
||||
// 商品名称
|
||||
if (isset($item['tradeName'])) {
|
||||
$data['product_name'] = $item['tradeName'];
|
||||
|
||||
@@ -48,7 +48,8 @@ class getProductStockCommand extends HyperfCommand
|
||||
|
||||
foreach ($product['data'] as $item){
|
||||
if (!empty($item['product_pharmacy_code'])){
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
||||
$pharmacy_code = $item['pharmacy_code'] ?? '';
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code'], $pharmacy_code);
|
||||
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +58,7 @@ class getProductStockCommand extends HyperfCommand
|
||||
for ($i = 2; $i <= $product['last_page']; $i++) {
|
||||
// 获取商品
|
||||
$params = array();
|
||||
$params['product_status'] = 1;
|
||||
$product = Product::getPage($params,['*'],$i,10);
|
||||
if (empty($product['data'])){
|
||||
$this->line("商品库存更新成功,无可更新库存商品");
|
||||
@@ -67,7 +69,8 @@ class getProductStockCommand extends HyperfCommand
|
||||
|
||||
foreach ($product['data'] as $item){
|
||||
if (!empty($item['product_pharmacy_code'])){
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
||||
$pharmacy_code = $item['pharmacy_code'] ?? '';
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code'], $pharmacy_code);
|
||||
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user