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) { Db::rollback(); 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) { Db::rollback(); self::$error = $e->getMessage(); return false; } } // 删除 public static function del($id) { return GoodsSubsidy::update(['is_delete' => 1, 'delete_time' => time()], ['id' => $id]); } // 获取全局返补比例 public static function getSubsidyConfig() { return [ 'promote_user' => ConfigServer::get('subsidy', 'promote_user'), 'promote_store' => ConfigServer::get('subsidy', 'promote_store'), 'platform_services' => ConfigServer::get('subsidy', 'platform_services'), 'no_level' => ConfigServer::get('subsidy', 'no_level'), ]; } // 设置全局返补比例 public static function setSubsidyConfig($post) { try { if (empty($post['promote_user']) && empty($post['promote_store']) && empty($post['platform_services']) && empty($post['no_level'])) { self::$error = '所提交的字段内容不能为空'; return false; } Db::startTrans(); ConfigServer::set('subsidy', 'promote_user', str_replace('%', '', $post['promote_user'])); ConfigServer::set('subsidy', 'promote_store', str_replace('%', '', $post['promote_store'])); ConfigServer::set('subsidy', 'platform_services', str_replace('%', '', $post['platform_services'])); ConfigServer::set('subsidy', 'no_level', str_replace('%', '', $post['no_level'])); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::$error = $e->getMessage(); return false; } } }