'余额', ]; private $type_key = [ 1 => 'money', ]; private $add_reduce_arr = [ 1 => '增加', 0 => '减少', ]; private $status_arr = [ 1 => '代币分账', 2 => '公排出局', ]; static private $server = null; private function __construct() { } /** * 创建对象 * @return MoneyDetailServer */ static function creatServer() { if (empty(self::$server)) self::$server = new MoneyDetailServer(); return self::$server; } /** * @param $reduce * @return string */ public function getAddReduceArr($reduce) { return empty($this->add_reduce_arr[$reduce]) ? '' : $this->add_reduce_arr[$reduce]; } /** * @return string[] */ public function getStatus() { return $this->status_arr; } /** * @param $status * @return array|string */ public function getStatusArr($status) { return empty($this->status_arr[$status]) ? '' : $this->status_arr[$status]; } /** * 获取订单类型 * @param $type * @return array|string */ public function getTypeArr($type) { return empty($this->type_arr[$type]) ? '' : $this->type_arr[$type]; } /** * @return string[] */ public function getType() { return $this->type_arr; } /** * 会员余额变动 * @param $type * @param $status * @param $price * @param $addReduce * @param $m_id * @param $mark * @param int $fromID * @return MoneyDetail|false|\Illuminate\Database\Eloquent\Model */ public function write($type, $status, $price, $addReduce, $m_id, $mark = '', $fromID = 0) { $money_mode = Member::where('id', $m_id)->select(['id', 'money'])->first(); if (empty($money_mode)) { return false; } $remainder=$money_mode->{'money'}; if($addReduce==1){ $money_mode->increment('money', $price); }else{ if($remainder<$price){ return false; } $money_mode->decrement('money', $price); } $detail = MoneyDetail::create( [ 'type' => $type, // 货币类型 'status' => $status, // 来源 'price' => $price, // 数目 'add_reduce' => $addReduce, // 增加 | 减少 'm_id' => $m_id, // 被操作会员ID 'mark' => $mark, // 备注 'source_id' => $fromID, // 操作员备注 'remainder' => sprintf("%.2f", ($addReduce == 0 ? $price * -1 : $price) + $remainder),// 剩余数目 ] ); MemberServer::creatServer()->delMemberCache($m_id); return $detail->{'id'}; } }