| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\common\model;
- use EasyWeChat\Kernel\Support\Str;
- use think\Model;
- //用户求购出售
- class UserBuying extends Model
- {
- protected $name = "user_buying";
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'create_time_text',
- 'update_time_text'
- ];
-
- const DefaultAdders =0; //默认地址
- const TakeAdders =1; //收货地址
- const Waiting = 0;
- const Shipped = 1;
- const Finish = 2;
- /*
- * 订单状态 0代发货 1已发货 2完成
- */
- public $order_status = [
- '-1' => '全部',
- self::Waiting => '待发货',
- self::Shipped => '已发货',
- self::Finish => '完成'
- ];
- //出售记录
- public static function getCreateUserBuying(int $uid, int $orderId, int $fromId, float $amount)
- {
- $fee = bcmul(config('market_transfer.serve_fee'), $amount, 2);
- $income = bcsub($amount, $fee, 2);
- self::create([
- 'user_id' => $uid,
- 'order_id' => $orderId,
- 'from_id' => $fromId,
- 'amount' => $amount,
- 'fee' => $fee,
- 'income' => $income,
- ]);
- return $income;
- }
-
- public function getCreateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getUpdateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setCreateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setUpdateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- }
|