withAttr('discount', function ($value) { $arr = explode('.', $value); if ($arr[1] > 0) { return $value . '%'; } return intval($value) . '%'; }) ->withAttr('subsidy', function ($value) { $arr = explode('.', $value); if ($arr[1] > 0) { return $value . '%'; } return intval($value) . '%'; }) ->paginate([ 'list_rows'=> $get['limit'], 'page'=> $get['page'], ]); return ['count' => $lists->total(), 'lists' => $lists->getCollection()]; } // 添加返补比例设置 public static function add($post) { try { Db::startTrans(); GoodsSubsidy::create([ 'discount' => str_replace('%', '', $post['discount']), 'subsidy' => str_replace('%', '', $post['subsidy']), ]); Db::commit(); return true; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } /** * Notes: 编辑 * @param $post * @return bool *@author 段誉(2021/4/15 10:54) */ public static function edit($post) { try { Db::startTrans(); GoodsSubsidy::update([ 'discount' => str_replace('%', '', $post['discount']), 'subsidy' => str_replace('%', '', $post['subsidy']), ], ['id' => $post['id']]); Db::commit(); return true; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } // 删除 public static function del($id) { return GoodsSubsidy::update(['is_delete' => 1, 'delete_time' => time()], ['id' => $id]); } }