| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\api\model\taxi;
- use app\common\model\BaseModel;
- use think\Model;
- class MotorRecord extends BaseModel
- {
- protected $name = 'users_motor_record';
- /**
- * @var array 资金变动日志
- */
- protected $money_log = [];
- public function getMoneyLog()
- {
- return $this->money_log;
- }
- /**
- * @param $value
- * @return false|string
- */
- public function getCreatedAtAttr($value)
- {
- return is_int($value)? ['val'=>$value,'text'=>date('m.d H:i', $value)] : $value;
- }
- /**
- * @desc 资金变动日志
- * @param Model $user 用户
- * @param string $field 字段
- * @param float $money 金额
- * @param int $type 类型
- * @param string $memo 备注
- * @param int $tag 收支
- * @return array|false
- * @date 2020/8/14/014
- */
- public function setMoneyLog(Model $user, string $field, float $money, int $type = 10, string $memo = '', int $tag = 1)
- {
- if (floatval($money) <= 0) {
- return false;
- }
- $before = 0;
- $after = 0;
- if ($tag == 2 && $field && isset($user->$field)) {
- $after = $user->$field;
- $before = $after + $money;
- }
- elseif ($tag == 1 && $field && isset($user->$field)) {
- $after = $user->$field;
- $before = $after - $money > 0 ? $after - $money : 0;
- }
- $this->money_log[] = [
- 'user_id' => $user['id'] ?? 0,
- 'money' => $money,
- 'before' => $before ?: 0,
- 'after' => $after ?: 0,
- 'tag' => $tag,
- 'type' => $type,
- 'memo' => $memo,
- ];
- return $this->money_log;
- }
- public function saveMoneyLog()
- {
- return $this->allowField(true)->saveAll($this->money_log);
- }
- public function getMonthTime($month)
- {
- //
- $firstday = date('Y-m-01', strtotime(date('Y') . '-' . $month . '-1'));
- $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
- return array($firstday,$lastday);
- }
- }
|