| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace app\common\model;
- use think\Model;
- use think\Request;
- use app\common\library\Auth;
- class ProductMarket extends Model
- {
- // 表名
- protected $table = 'product_market';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'create_time_text',
- 'update_time_text'
- ];
-
- //状态 normal, hidden
- const Hidden = 0;
- const Normal = 1;
-
- //收藏
- public function collect()
- {
-
- return $this->hasOne('UserCollect', 'market_id', 'id', [], 'LEFT')->where('user_id', Auth::instance()->getUser()['id']);
- }
-
-
- //产品
- public function products()
- {
- $header = Request::instance()->header('Accept-Language');
- $lan = !empty($header)? substr($header, 0, 2):'zh' ;
- return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->field('id,'.$lan .'_name as name,thum,details');
- }
- //寄售
- public function producttransfer()
- {
- $map = [];
- $transfer = input('post.transfer_id/d', 0);
- if($transfer > 0) $map['id'] = $transfer;
- $order = 'price asc';
- if(input('post.sort') == 1) $order = 'price desc';
- return $this->hasMany('ProductTransfer', 'product_id', 'product_id', [], 'LEFT')->where($map)->where('status', self::Normal)->order($order);
- }
- 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);
- }
- }
|