52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace common\jobs;
|
||
|
||
use common\models\oldDb\DrugStoreDrug;
|
||
use common\models\oldDb\Log;
|
||
use common\services\PlatformService;
|
||
use yii\db\Exception;
|
||
use yii\queue\JobInterface;
|
||
use yii\queue\Queue;
|
||
|
||
class SyncHospitalJob extends BaseJob implements JobInterface
|
||
{
|
||
|
||
public $type;
|
||
public $admin_id;
|
||
/**
|
||
* @param Queue $queue which pushed and is handling the job
|
||
*/
|
||
public function execute($queue)
|
||
{
|
||
Log::saveLog($this->admin_id,$this->type,'同步互医队列start');
|
||
$t = \Yii::$app->db->beginTransaction();
|
||
try {
|
||
$DrugStoreDrug = DrugStoreDrug::find()->select(['drug_id', 'price', 'stock', 'status'])->all();
|
||
if (!$DrugStoreDrug) throw new Exception('暂无数据');
|
||
foreach ($DrugStoreDrug as $value) {
|
||
$item= [
|
||
'platform_store_id' => 0,
|
||
'id' => $value['drug_id'],
|
||
'price' => $value['price'],
|
||
'stock' => $value['stock'],
|
||
'is_sale' => $value['status'] == 1 ? 0 : 1,
|
||
];
|
||
$response = (new PlatformService())->syncDrug($item);
|
||
if($response){
|
||
$success[]='药品ID:'.$value['drug_id'].'同步成功';
|
||
}else{
|
||
$error[] = '错误:药品ID:'.$value['drug_id'].'同步失败';
|
||
}
|
||
}
|
||
$t->commit();
|
||
Log::saveLog($this->admin_id,$this->type,'同步互医队列end');
|
||
}catch (\Exception $e){
|
||
|
||
$t->rollBack();
|
||
Log::saveLog($this->admin_id,$this->type,'同步互医队列异常:'.$e->getMessage());
|
||
return ;
|
||
}
|
||
|
||
}
|
||
} |