| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class OwnerOutStorageRule extends Model
- {
- protected $fillable = [
- "owner_price_operation_id", //作业计费ID
- "strategy", //出库策略
- "amount", //起步数
- "unit_id", //单位ID
- "unit_price", //单价
- "feature", //特征
- "priority", //优先级 值越大越高
- ];
- public $timestamps=false;
- public static $features = null;
- public static $columnMapping = null;
- public function unit()
- { //单位
- return $this->hasOne(Unit::class,"id","unit_id");
- }
- public function translateFeature(array $features)
- {
- $result = [];
- preg_match_all('/\d+|[\&\|\(\)]/',$this->feature,$result);
- foreach ($result[0] as &$str){
- if (is_numeric($str) && isset($features[$str]))$str = $features[$str]["type"].' '.$features[$str]["logic"].' '.$features[$str]["describe"];
- }
- $this->feature = implode("",$result[0]);
- }
- public function getFeatureAttribute($value)
- {
- if ($this->strategy == '默认')return "/";
- return $value;
- }
- /* 格式化依据静态参数,在调用前设置 */
- public function getFeatureFormatAttribute($value)
- {
- if ($this->strategy == '默认')return "/";
- if (!self::$features)return $value;
- $result = [];
- preg_match_all('/\d+|[\&\|\(\)]/',$value,$result);
- foreach ($result[0] as &$str){
- if (is_numeric($str) && isset(self::$features[$str])){
- $column = self::$features[$str]["type"];
- $logic = self::$features[$str]["logic"];
- $describe = self::$features[$str]["describe"];
- if (self::$columnMapping){
- $column = self::$columnMapping[$column] ?? $column;
- switch ($logic){
- case "包含":
- $logic = " like ";
- $describe = "%".$describe."%";
- break;
- case "不包含":
- $logic = " not like ";
- $describe = "%".$describe."%";
- break;
- case "等于":
- $logic = " = ";
- break;
- }
- $str = $column.$logic.$describe;
- }else $str = self::$features[$str]["type"].' '.self::$features[$str]["logic"].' '.self::$features[$str]["describe"];
- }
- if ($str == "&"){
- if (self::$columnMapping) $str = " and ";
- else $str = " 并且 ";
- }
- if ($str == "|"){
- if (self::$columnMapping) $str = " or ";
- else $str = " 或 ";
- }
- }
- return implode("",$result[0]);
- }
- }
|