|
|
@@ -2,12 +2,13 @@
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
-use app\common\model\UserEnterLog;
|
|
|
+
|
|
|
use app\api\validate\Shop as ShopValidate;
|
|
|
use app\common\model\ShopList;
|
|
|
use app\common\model\ShopDelivery;
|
|
|
use think\Exception;
|
|
|
-use think\facade\Cache;
|
|
|
+use think\facade\Db;
|
|
|
+use app\common\service\SpecService;
|
|
|
use think\exception\ValidateException;
|
|
|
|
|
|
class Shops extends Base
|
|
|
@@ -50,42 +51,33 @@ class Shops extends Base
|
|
|
public function delivery(ShopDelivery $shopDelivery){
|
|
|
|
|
|
$data = $this->request->post();
|
|
|
- $result = false;
|
|
|
- try {
|
|
|
- validate(ShopValidate::class)->scene('add')->check($data);
|
|
|
-
|
|
|
- $data['user_id'] = $this->userinfo['id'];
|
|
|
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
|
|
|
- $result = $shopDelivery::create($data);
|
|
|
-
|
|
|
- }catch (ValidateException $e) {
|
|
|
- return $this->error($e->getError());
|
|
|
- } catch (\Exception $e) {
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- if ($result === false) {
|
|
|
- $this->error(__('没有新增任何数据'));
|
|
|
- }
|
|
|
+ $result = $shopDelivery::where($data)->select();
|
|
|
$this->success();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//添加记录
|
|
|
- public function create(UserEnterLog $userEnterLog)
|
|
|
+ public function create(ShopDelivery $shopDelivery, SpecService $specService)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
$data = $this->request->post();
|
|
|
$result = false;
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
validate(ShopValidate::class)->scene('add')->check($data);
|
|
|
-
|
|
|
- $data['user_id'] = $this->userinfo['id'];
|
|
|
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
|
|
|
- $result = $userEnterLog::create($data);
|
|
|
-
|
|
|
+
|
|
|
+ //发货数据
|
|
|
+ $resData = $specService::getDeliveryList($this->userinfo['id'], $data);
|
|
|
+
|
|
|
+ //扣除库存
|
|
|
+ $result = $shopDelivery->saveAll($resData);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
}catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
return $this->error($e->getError());
|
|
|
} catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
if ($result === false) {
|