diff --git a/application/api/controller/wanlshop/Invoice.php b/application/api/controller/wanlshop/Invoice.php index 4285dba9db2cd64601ff95874c1614d99de89f65..78352d999ee61c4dc3eb5f78618c68f378d6600a 100644 --- a/application/api/controller/wanlshop/Invoice.php +++ b/application/api/controller/wanlshop/Invoice.php @@ -51,59 +51,15 @@ class Invoice extends Api $count = $Invoice->where(['user_id'=>$data['user_id']])->count(); // 操作 switch ($request['type']) { - case "edit": - if($count <= 1){ - $data['default'] = 1; - $Invoice->allowField(true)->save($data,['id' => $data['id']]); - $this->success('ok','成功(仅一个不许修改默认)'); - }else{ - // 更新 - $Invoice->allowField(true)->save($data,['id' => $data['id']]); - // 单独设置默认,避免非默认消耗资源 - if($data['default'] == 1){ - $list = \app\api\model\wanlshop\Invoice::all(['user_id'=>$data['user_id']]); - $list = collection($list)->toArray(); - $itemdata = []; - foreach($list as $item){ - if($item['id'] == $data['id']){ - $item['default'] = 1; - }else{ - $item['default'] = 0; - } - $itemdata[] = $item; - } - $Invoice->allowField(true)->saveAll($itemdata); - } - $this->success('ok'); - } - break; - case "add": - if($count == 0){ - // 新增 - $data['default'] = 1; - $Invoice->data($data); - $Invoice->save(); - $this->success('发票回调',$Invoice); - }else{ - $Invoice->data($data); - $Invoice->save(); - if($data['default'] == 1){ - $list = \app\api\model\wanlshop\Address::all(['user_id'=>$data['user_id']]); - $list = collection($list)->toArray(); - $itemdata = []; - foreach($list as $item){ - if($item['id'] == $Invoice->id){ - $item['default'] = 1; - }else{ - $item['default'] = 0; - } - $itemdata[] = $item; - } - $Invoice->saveAll($itemdata); - } - $this->success('新增成功',[]); - } + case "edit": + $Invoice->allowField(true)->save($data,['id' => $data['id']]); + $this->success('ok','成功(仅一个不许修改默认)'); break; + case "add": + $Invoice->data($data); + $Invoice->save(); + $this->success('新增成功',[]); + break; } } else { $this->error(__('非法请求'));