| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\api\controller;
- use app\api\validate\Shop as ShopValidate;
- use app\common\model\ShopDelivery;
- use think\Exception;
- use think\facade\Db;
- use app\api\service\SpecService;
- use think\exception\ValidateException;
- class Shops extends Base
- {
- //protected $noNeedLogin = ['*'];
-
- //发货记录
- public function delivery(ShopDelivery $shopDelivery){
- $plat_id = $this->request->post('plat_id/d', 0); //平台
- $shop_id = $this->request->post('shop_id/d', 0); //店铺
- $variety_id = $this->request->post('variety_id/d', 0); //品种
- $limit = $this->request->post('limit/d', 15); //条数
- $where['a.user_id'] = $this->userinfo['id'];
- if($plat_id > 0) $where['a.plat_id'] = $plat_id;
- if($shop_id > 0) $where['a.shop_id'] = $shop_id;
- if($variety_id > 0) $where['a.variety_id']= $variety_id;
- $result = $shopDelivery::alias('a')
- ->leftjoin('shop_list b', 'a.shop_id = b.id') //店铺
- ->leftjoin('stock_config c', 'a.variety_id = c.id') //品种
- ->leftjoin('product_config d', 'a.spec_id = d.id') //规格
- ->field('a.id,a.plat_id,a.shop_id,a.createtime,a.num, b.name shop_name,c.title variety_name,d.title spec_name')
- ->where($where)
- ->paginate($limit);
- $this->success('ok', $result);
- }
- //添加记录
- public function create(ShopDelivery $shopDelivery, SpecService $specService)
- {
- $data = $this->request->post();
- $result = false;
- Db::startTrans();
- try {
- validate(ShopValidate::class)->scene('add')->check($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) {
- $this->error(__('没有新增任何数据'));
- }
- $this->success();
- }
-
- }
|