|
@@ -54,28 +54,33 @@ class Order extends Base
|
|
* @param addrid
|
|
* @param addrid
|
|
*/
|
|
*/
|
|
public function ist(){
|
|
public function ist(){
|
|
- $name = isset($this->post['name'])&&$this->post['name']!==""? intval($this->post['name']): "";
|
|
|
|
- if($name==""){
|
|
|
|
- return error_show(1004,'参数name');
|
|
|
|
- }
|
|
|
|
|
|
+ $ist = Db::name('unit')->where(["is_del" => 0,"status"=>1])->field("id,name,weight")->select();
|
|
|
|
+ return app_show(0,"获取成功",["list"=>$ist]);
|
|
}
|
|
}
|
|
public function add(){
|
|
public function add(){
|
|
$num = isset($this->post['num'])&&$this->post['num']!="" ? intval($this->post['num']):"";
|
|
$num = isset($this->post['num'])&&$this->post['num']!="" ? intval($this->post['num']):"";
|
|
if($num==""){
|
|
if($num==""){
|
|
return error_show(1004,"参数num 不能为空或0");
|
|
return error_show(1004,"参数num 不能为空或0");
|
|
}
|
|
}
|
|
- $id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['id']):"";
|
|
|
|
- if($id==""){
|
|
|
|
- return error_show(1004,"参数id不能为空");
|
|
|
|
|
|
+ $id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']): "";
|
|
|
|
+ if($id){
|
|
|
|
+ return error_show(1004,"unit_id不能为空");
|
|
|
|
+ }
|
|
|
|
+ $kg= Db::name('unit')->where(["is_del" => 0,"id"=>$id,"status"=>1])->field("id,name,weight")->find();
|
|
|
|
+ if(empty($kg)){
|
|
|
|
+ return error_show(1004,"单位不能为空");
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ $count=$num*$kg['weight'];
|
|
|
|
+ if($count==""){
|
|
|
|
+ return error_show(1004,"购买数量不能为空");
|
|
|
|
+ }
|
|
$addrid = isset($this->post['addrid'])&&$this->post['addrid']!="" ? intval($this->post['addrid']):"";
|
|
$addrid = isset($this->post['addrid'])&&$this->post['addrid']!="" ? intval($this->post['addrid']):"";
|
|
if($addrid==""){
|
|
if($addrid==""){
|
|
return error_show(1004,"参数addrid 不能为空");
|
|
return error_show(1004,"参数addrid 不能为空");
|
|
}
|
|
}
|
|
$stock = Db::name("account_stock")->where(['is_del'=>0,"accountid"=>$this->userinfo['id']])->find();
|
|
$stock = Db::name("account_stock")->where(['is_del'=>0,"accountid"=>$this->userinfo['id']])->find();
|
|
- if(empty($stock) || $stock['stock_balance']<$num){
|
|
|
|
|
|
+ if(empty($stock) || $stock['stock_balance']<$count){
|
|
return error_show(1004,"库存数量不足");
|
|
return error_show(1004,"库存数量不足");
|
|
}
|
|
}
|
|
$addr =Db::name("rela_addr")->alias('a')->join("addr b","a.addrid=b.id","left")->where(["a.accountid"=>$this->userinfo['id'],
|
|
$addr =Db::name("rela_addr")->alias('a')->join("addr b","a.addrid=b.id","left")->where(["a.accountid"=>$this->userinfo['id'],
|