58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
![]() |
<?php
|
||
|
namespace app\controllers\channel;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Yii;
|
||
|
use yii\web\Controller;
|
||
|
use app\models\Goods;
|
||
|
class CeshiController extends Controller{
|
||
|
//添加一个测试商品
|
||
|
public function actionSaveGoods(){
|
||
|
$result=axios_request();
|
||
|
//dd($result);die;
|
||
|
// 执行事务
|
||
|
$trans=YII::$app->db->beginTransaction();
|
||
|
try{
|
||
|
$goods=new Goods();
|
||
|
$goods->sort=$result['sort'];
|
||
|
$goods->typePid=$result['typePid'];
|
||
|
$goods->typeId=$result['typeId'];
|
||
|
$goods->name=$result['name'];
|
||
|
$goods->body=$result['body'];
|
||
|
$goods->icon=$result['icon'];
|
||
|
$goods->minNum=$result['minNum'];
|
||
|
$goods->unit=$result['unit'];
|
||
|
$goods->price=$result['price'];
|
||
|
$goods->boxMoney=$result['boxMoney'];
|
||
|
$goods->stock=$result['stock'];
|
||
|
$goods->crossedPrice=$result['crossedPrice'];
|
||
|
$goods->costPrice=$result['costPrice'];
|
||
|
$goods->salesType=$result['salesType'];
|
||
|
$goods->startTime=$result['startTime'];
|
||
|
$goods->endTime=$result['endTime'];
|
||
|
$goods->weekDay=$result['weekDay'];
|
||
|
$goods->hotsaleType=$result['hotsaleType'];
|
||
|
$goods->aloneType=$result['aloneType'];
|
||
|
$goods->details=$result['details'];
|
||
|
$goods->isMember=$result['isMember'];
|
||
|
$goods->maxNum=$result['maxNum'];
|
||
|
$goods->salesNum=$result['salesNum'];
|
||
|
$goods->uniacid=$result['uniacid'];
|
||
|
$goods->goodLabel=$result['goodLabel'];
|
||
|
$res=$goods->save();
|
||
|
|
||
|
if (!$goods->save(false)) {
|
||
|
|
||
|
throw new \Exception('保存商品失败!');
|
||
|
}
|
||
|
$trans->commit();
|
||
|
return true;
|
||
|
}catch(\Exception $e) {
|
||
|
//var_dump($goods->getErrors());die;
|
||
|
//如果语句中有一个执行失败,那么就将回滚
|
||
|
$trans->rollBack();
|
||
|
throw $e;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|