// +---------------------------------------------------------------------- namespace app\common\dao\system; use app\common\dao\BaseDao; use app\common\model\system\Record; class RecordDao extends BaseDao { protected function getModel(): string { return Record::class; } /** * 根据类型自增 * @param string $type * @param int $linkId * @param $num */ public function incType(string $type, int $linkId, $num = 1, $data = []) { $data = [ 'uid' => $data['uid'] ?? 0, 'title' => $data['title'] ?? $type, 'type' => $type, 'link_id' => $linkId ]; $res = $this->findOrCreate($data); $res->num = $res['num'] + $num; $res->save(); } /** * 根据类型自减 * @param string $type * @param int $linkId * @param $num */ public function decType(string $type, int $linkId, $num = 1) { $this->getSearch(['type' => $type])->where('link_id', $linkId)->where('num','>=',1)->dec('num', $num)->update(); } }