123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace App\Servers;
- use App\Models\Member;
- use App\Models\MoneyDetail;
- use App\Models\MoneyRecord;
- use App\Models\ShopBean;
- use App\Models\ShopUser;
- /**
- * 订单管理
- * Class OrderServer
- * @package App\Servers
- */
- class MoneyDetailServer
- {
- private $type_arr = [
- 1 => '余额',
- ];
- 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'};
- }
- }
|