@@ -102,6 +102,11 @@ public class MainActivity extends AppCompatActivity { | |||
private boolean mRunning = false; | |||
private boolean mCartRunning = false; | |||
/** | |||
* 检测当前放入的餐盘是否有绑定订单 | |||
*/ | |||
private boolean IsBindingOrder=false; | |||
//endregion | |||
@Override | |||
@@ -251,30 +256,41 @@ public class MainActivity extends AppCompatActivity { | |||
spend_weight.setText(String.valueOf(DataBus.getInstance().xf_weight)+"g"); | |||
//本次消费金额 | |||
spend_price.setText("¥"+ String.format("%.2f",DataBus.getInstance().xf_price)); | |||
IsBindingOrder=true; | |||
} | |||
/** | |||
* 发送API进行消费 | |||
*/ | |||
public void SendApiConsume(){ | |||
if(DataBus.getInstance().xf_weight>=5)//5g以上开始计费 | |||
{ | |||
String orderId = DataBus.getInstance().weighOrderDto.id; | |||
String goodId = DataBus.getInstance().SelectFood.id; | |||
String goodsName=DataBus.getInstance().SelectFood.name; | |||
String chipCode = DataBus.getInstance().CurrentCart; | |||
APIServer.CreateOrder(new AddGoodInfo(orderId,goodId,goodsName,DataBus.getInstance().xf_weight,chipCode),null,(error)->{ | |||
this.runOnUiThread(()->{ | |||
T.show(MainActivity.this,error); | |||
}); | |||
}); | |||
}else | |||
{ | |||
DataBus.getInstance().xf_weight=0; | |||
DataBus.getInstance().xf_price=0; | |||
DataBus.getInstance().xf_sjprice=0; | |||
runOnUiThread(()->{ T.show(MainActivity.this,"消费重量小于5g,不予计费");}); | |||
if(!IsBindingOrder){ ReadApiUserInformation(); } | |||
if(IsBindingOrder){ | |||
IsBindingOrder=false; | |||
if(DataBus.getInstance().xf_weight>=ConfigName.getInstance().MinWeight)//5g以上开始计费 | |||
{ | |||
try{ | |||
String orderId = DataBus.getInstance().weighOrderDto.id; | |||
String goodId = DataBus.getInstance().SelectFood.id; | |||
String goodsName=DataBus.getInstance().SelectFood.name; | |||
String chipCode = DataBus.getInstance().CurrentCart; | |||
APIServer.CreateOrder(new AddGoodInfo(orderId,goodId,goodsName,DataBus.getInstance().xf_weight,chipCode),null,(error)->{ | |||
this.runOnUiThread(()->{ | |||
T.show(MainActivity.this,error); | |||
}); | |||
}); | |||
}catch(Exception e){ | |||
} | |||
}else | |||
{ | |||
DataBus.getInstance().xf_weight=0; | |||
DataBus.getInstance().xf_price=0; | |||
DataBus.getInstance().xf_sjprice=0; | |||
runOnUiThread(()->{ T.show(MainActivity.this,"消费重量小于 "+ConfigName.getInstance().MinWeight+"g,不予计费");}); | |||
} | |||
}else{ | |||
runOnUiThread(()->{ T.show(MainActivity.this,"请先打开小程序扫描餐盘码");}); | |||
} | |||
} | |||
/** | |||
@@ -304,6 +320,7 @@ public class MainActivity extends AppCompatActivity { | |||
RefreshConsumption(); | |||
}); | |||
},(error)->{ | |||
IsBindingOrder=false; | |||
this.runOnUiThread(()->{ | |||
T.show(MainActivity.this,error); | |||
}); | |||
@@ -74,6 +74,9 @@ public class Main { | |||
ConfigName.getInstance().Plate_Com_Name =ConfigUtil.read(DataBus.getInstance().dishesCon,"Plate_Com_Name", ConfigName.getInstance().Plate_Com_Name); | |||
ConfigName.getInstance().Plate_Com_Port =ConfigUtil.read(DataBus.getInstance().dishesCon,"Plate_Com_Port", ConfigName.getInstance().Plate_Com_Port); | |||
ConfigName.getInstance().Plate_Com_Format =ConfigUtil.read(DataBus.getInstance().dishesCon,"Plate_Com_Format", ConfigName.getInstance().Plate_Com_Format); | |||
ConfigName.getInstance().MinWeight =ConfigUtil.read(DataBus.getInstance().dishesCon,"MinWeight", ConfigName.getInstance().MinWeight); | |||
} | |||
/** | |||
@@ -96,6 +99,8 @@ public class Main { | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Plate_Com_Port", ConfigName.getInstance().Plate_Com_Port); | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Plate_Com_Format", ConfigName.getInstance().Plate_Com_Format); | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"MinWeight", ConfigName.getInstance().MinWeight); | |||
ToggleEnvironment(); | |||
} | |||
@@ -87,6 +87,11 @@ public class ConfigName { | |||
* 数据位、校验位、停止位 | |||
*/ | |||
public String Plate_Com_Format="8N1"; | |||
/** | |||
* 最小计费重量 | |||
*/ | |||
public int MinWeight=10; | |||
//endregion | |||
@@ -36,7 +36,7 @@ public class ParameterSetFragment extends Fragment { | |||
//region 界面变量 | |||
//店铺信息 | |||
private EditText Shop_Name,AutKey,Shop_DeviceId; | |||
private EditText Shop_Name,AutKey,Shop_DeviceId,et_min_weight; | |||
//菜品放置区 | |||
private Spinner Dishes_Com_Name,Dishes_Com_Port,environment; | |||
//菜品放置区 | |||
@@ -68,6 +68,7 @@ public class ParameterSetFragment extends Fragment { | |||
Plate_Com_Name=MainView.findViewById(R.id.tv_cpgy_com); | |||
Plate_Com_Port=MainView.findViewById(R.id.tv_cpgy_port); | |||
Plate_Com_Format=MainView.findViewById(R.id.tv_cpgy_jy); | |||
et_min_weight=MainView.findViewById(R.id.et_min_weight); | |||
Save=MainView.findViewById(R.id.parameter_save); | |||
@@ -90,6 +91,7 @@ public class ParameterSetFragment extends Fragment { | |||
Shop_Name.setText(ConfigName.getInstance().Shop_Name); | |||
AutKey.setText(ConfigName.getInstance().AutKey); | |||
Shop_DeviceId.setText(ConfigName.getInstance().Shop_DeviceId); | |||
et_min_weight.setText(String.valueOf(ConfigName.getInstance().MinWeight)); | |||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_item, new ArrayList<>(material_map.keySet())); | |||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
@@ -102,6 +104,7 @@ public class ParameterSetFragment extends Fragment { | |||
SelectText(Plate_Com_Name,ConfigName.getInstance().Plate_Com_Name); | |||
SelectText(Plate_Com_Port, Integer.toString(ConfigName.getInstance().Plate_Com_Port)); | |||
SelectText(Plate_Com_Format,ConfigName.getInstance().Plate_Com_Format); | |||
} | |||
/** | |||
@@ -150,6 +153,17 @@ public class ParameterSetFragment extends Fragment { | |||
T.show(MainView.getContext(),"餐盘感应区域数据位、校验位、停止位不能为空!"); | |||
return; | |||
} | |||
if (et_min_weight.getText().toString().isEmpty()) | |||
{ | |||
T.show(MainView.getContext(),"最小计费重量不能为空!"); | |||
return; | |||
} | |||
try{ | |||
ConfigName.getInstance().MinWeight= Integer.valueOf(et_min_weight.getText().toString()); | |||
}catch(Exception e){ | |||
T.show(MainView.getContext(),"输入的最小重量类型不匹配"); | |||
return; | |||
} | |||
ConfigName.getInstance().Environment = environment.getSelectedItem().toString(); | |||
ConfigName.getInstance().Shop_Name=Shop_Name.getText().toString(); | |||
ConfigName.getInstance().AutKey=AutKey.getText().toString(); | |||
@@ -159,6 +173,7 @@ public class ParameterSetFragment extends Fragment { | |||
ConfigName.getInstance().Plate_Com_Name=Plate_Com_Name.getSelectedItem().toString(); | |||
ConfigName.getInstance().Plate_Com_Port=Integer.valueOf(Plate_Com_Port.getSelectedItem().toString()).intValue(); | |||
ConfigName.getInstance().Plate_Com_Format=Plate_Com_Format.getSelectedItem().toString(); | |||
Main.getInstance().SavePZ(); | |||
T.show(MainView.getContext(),"配置保存成功!"); | |||
} | |||
@@ -199,6 +199,7 @@ | |||
android:spinnerMode="dropdown" | |||
android:textSize="@dimen/text_size" /> | |||
</LinearLayout> | |||
<!--称重区域连接端口配置 --> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
@@ -288,6 +289,54 @@ | |||
android:textSize="@dimen/text_size" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="20dp" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:layout_width="match_parent" | |||
android:layout_height="35dip" | |||
android:layout_gravity="center" | |||
android:background="@color/green_light" | |||
android:gravity="center" | |||
android:text="称重台配置" | |||
android:textColor="@color/white" | |||
android:textSize="@dimen/submit_text_size" /> | |||
<View | |||
android:layout_width="match_parent" | |||
android:layout_height="2dp" | |||
android:background="#369FE5" /> | |||
<LinearLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="center_horizontal" | |||
android:layout_marginTop="20dp" | |||
android:orientation="horizontal"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="最小重量:" | |||
android:textColor="#000" | |||
android:textSize="@dimen/text_size" /> | |||
<EditText | |||
android:id="@+id/et_min_weight" | |||
android:layout_width="440dp" | |||
android:layout_height="40dp" | |||
android:hint="请输入最小计费重量" | |||
android:inputType="number" | |||
android:singleLine="true" | |||
android:textSize="@dimen/text_size" /> | |||
</LinearLayout> | |||
</LinearLayout> | |||
<TextView | |||
android:id="@+id/parameter_save" | |||
android:layout_width="fill_parent" | |||