where('checked', 1)->sum(function (PreOrderDeduction $orderDeduction) { return $orderDeduction->getMinDeduction()->getMoney(); }); } public function usedAmount() { return $this->where('checked', 1)->sum('amount'); } /** * 过滤掉不可抵扣的 * @return $this */ public function filterNotDeductible() { $this->items = $this->filter(function (PreOrderDeduction $orderDeduction) { return $orderDeduction->deductible(); })->values()->all(); return $this; } public function toArray() { $this->filterNotDeductible(); return parent::toArray(); // TODO: Change the autogenerated stub } public function lock() { $this->each(function (PreOrderDeduction $orderDeduction) { return $orderDeduction->lock(); }); return $this; } /** * 按照必选排序 * @return $this */ public function sortOrderDeductionCollection() { // 按照选中状态排序 $this->items = $this->sortByDesc(function (PreOrderDeduction $preOrderDeduction) { return $preOrderDeduction->mustBeChecked(); })->all(); return $this; } /** * @param mixed $value * @return $this */ public function push($value) { parent::push($value); sort($this->items); return $this; } /** * @return $this */ public function validate() { $this->each(function (PreOrderDeduction $orderDeduction) { $orderDeduction->validateCoin(); }); return $this; } }