| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\api\model\massager;
- use app\api\model\BaseModel;
- class Bill extends BaseModel
- {
- // 表名
- protected $name = 'massager_bill';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'type_text'
- ];
- public function getTypeList()
- {
- return ['money' => __('Money'), 'score' => __('Score')];
- }
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function sumByMassagerAndThisMonth($m_id)
- {
- $sum = $this->query("
- SELECT
- SUM( `CHANGE` ) AS tp_sum
- FROM
- `ma_massager_bill`
- WHERE
- ( DATE_FORMAT( FROM_UNIXTIME( createtime ), '%Y-%m' ) = date_format( now(), '%Y-%m' ) )
- AND `massager_id` = {$m_id}
- AND `currency_type` = 'score'
- LIMIT 1
- ");
- return fixed2Float($sum[0]["tp_sum"]);
- }
- function fetchBill($m_id, $currency_type, $change_types, $page = 1, $size = 10)
- {
- $query = $this->where([
- "massager_id" => $m_id,
- "currency_type" => $currency_type
- ]);
- if (!in_array("*", $change_types)) {
- $query->where("change_type", "in", $change_types);
- }
- return $query->order("createtime", "desc")
- ->page($page)
- ->paginate($size);
- }
- }
|