+
    7}j;                     n    ^ RI HtHt ^ RIHt ^ RIHtHtHt ^ RI	H
t
Ht ^ RIHt ^ RIHt R
R ltR tR	# )    )requestjsonify)get_db)get_user_id_from_tokenbuild_locationget_admin_from_token)error_responsebuild_search_conditions)get_config_value)check_sensitive_wordsc                   \        4       pVP                  4       p VP                  RV 34       VP                  4       pV'       g   RVP	                  4        # \        RV4      pV'       d   RVP	                  4        # V'       d!   VR,          V8w  d   RVP	                  4        # RVP	                  4        #   TP	                  4        i ; i)uZ   
检查用户是否有权限操作技能
返回 (has_permission, is_admin, error_message)
zCSELECT publisher_id FROM skills WHERE id = ? AND deleted_at IS NULLNpublisher_id)FF   技能不存在)TTN)FFu   无权操作此技能)TFN)r   cursorexecutefetchonecloser   )skill_iduser_idrequire_ownerconnr   skillis_admins   &&&    backend/routes/skills.pycheck_skill_permissionr      s    
 8D[[]F\_g^ij!2 	

 (g6 # 	

 U>2g=8 	

 !



s#   ,B9 B9 ?B9 B9 'B9 9Cc                   a	 V P                  R R.R7      V	3R l4       pV P                  RR.R7      R 4       pV P                  RR.R7      R 4       pV P                  R R.R7      R	 4       pV P                  RR
.R7      R 4       pV P                  RR.R7      R 4       pV P                  RR.R7      R 4       pR o	R pR# )z/api/skillsGET)methodsc            
        < \         P                  P                  R 4      p \        \         P                  P                  R^4      4      p\        \         P                  P                  R^
4      4      pV^,
          V,          p\	        4       pVP                  4       p . ROp\        W`4      w  rxV'       dJ   VP                  RV 2V4       VP                  4       ^ ,          p	VP                  RV R2. VOVNVN4       M;VP                  R4       VP                  4       ^ ,          p	VP                  RW#34       VP                  4       p
\        \        R V
 4       4      4      pS! V4      p. pV
 FK  p\        V4      pVP                  VR	,          R
4      VR&   \        VRR7      VR&   VP                  V4       KM  	  \        RVRV	RVRV/4      VP!                  4        #   TP!                  4        i ; i)searchpagelimitz8SELECT COUNT(*) FROM skills s WHERE s.deleted_at IS NULLz
                    SELECT s.*, u.phone as publisher_phone
                    FROM skills s
                    LEFT JOIN users u ON s.publisher_id = u.id
                    WHERE s.deleted_at IS NULLzQ
                    ORDER BY s.created_at DESC LIMIT ? OFFSET ?
                z4SELECT COUNT(*) FROM skills WHERE deleted_at IS NULLa  
                    SELECT s.*, u.phone as publisher_phone
                    FROM skills s
                    LEFT JOIN users u ON s.publisher_id = u.id
                    WHERE s.deleted_at IS NULL ORDER BY s.created_at DESC LIMIT ? OFFSET ?
                c              3   T   "   T F  qR ,          '       g   K  VR ,          x  K   	  R# 5i)r   N ).0rows   & r   	<genexpr><register_skill_routes.<locals>.get_skills.<locals>.<genexpr>K   s$     $`DSP^L_L_%8S%8%8Ds   ((r   -acceptor_rating_rateTinclude_detaillocationitemstotal)zs.titlezs.descriptionz
s.provincezs.cityz
s.districtzs.street)r   argsgetintr   r   r
   r   r   fetchalllistsetdictr   appendr   r   )r    r!   r"   offsetr   r   search_fieldssearch_condsearch_paramsr/   rowspublisher_idsacceptor_rating_mapr.   r&   r   get_bulk_user_rating_ratess                   r   
get_skills)register_skill_routes.<locals>.get_skills&   s   !!(+7<<##FA./GLL$$Wb12(e#x-	jM)@)W&K!YZeYfgivw)!, $/ 0;m <	  5}4e4V46 UV)!,  
 _& ??$D $`D$`!`aM"<]"KES	0C0G0GNH[]`0a,-$25$Nj!U#	  	  JJLDJJLs   D5G$ $G6z/api/skills/<int:skill_id>c                 Z   \        4       pVP                  4       p VP                  R V 34       VP                  4       pV'       g   \	        R4      VP                  4        # \        V4      p\        VRR7      VR&   \        V4      VP                  4        #   TP                  4        i ; i)z8SELECT * FROM skills WHERE id = ? AND deleted_at IS NULLr   Tr+   r-   )	r   r   r   r   r	   r   r6   r   r   )r   r   r   r&   results   &    r   	get_skill(register_skill_routes.<locals>.get_skill^   s    x	NNUX`Wbc//#C%&78 JJL #YF!/t!LF:6?JJLDJJLs   5B "%B B*z/api/skills/countc                      \         P                  P                  R 4      p V '       d   V P                  R4      '       g   \	        RR4      # V P                  R4      ^,          p\        V4      pV'       g   \	        RR4      # \        4       pVP                  4       p VP                  RV34       VP                  4       ^ ,          p\        \        RR4      4      p\        R	VR
V/4      VP                  4        #   TP                  4        i ; i)AuthorizationBearer 	   未登录      登录已过期ISELECT COUNT(*) FROM skills WHERE publisher_id = ? AND deleted_at IS NULLmax_publish_skills1countmax)r   headersr1   
startswithr	   splitr   r   r   r   r   r2   r   r   r   )auth_headertokenr   r   r   current_count
max_skillss          r   get_skill_count.register_skill_routes.<locals>.get_skill_countp   s    oo))/:+"8"8"C"C!+s33!!#&q)(/!"3S99x	NNfiphrs"OO-a0M-.BCHIJG]E:FGJJLDJJLs   AC; ;DPOSTc                     \         P                  p \        V P                  R 4      V P                  R4      V P                  R4      4      w  rV'       d   \	        R4      # \        4       pVP                  4       p Rp\         P                  P                  RR4      P                  RR4      pV'       d   VP                  RV34       VP                  4       pV'       d   VP                  R	VR
,          34       VP                  4       pV'       d   VR,          ^8w  d   \	        RR4      VP                  4        # VR,          p\        \        RR4      4      p	VP                  RV34       VP                  4       ^ ,          p
W8  d    \	        RV	 R24      VP                  4        # VP                  RV P                  R 4      V P                  R4      V P                  R4      V P                  R4      V P                  R4      V P                  R4      V P                  R4      VV P                  R4      V P                  R4      3
4       VP                  pVP                  4        \!        RV/V C4      VP                  4        #   \"         d   pTP%                  4        ThRp?ii ; i  TP                  4        i ; i)titledescriptiondetail_location0   文字中存在敏感词，请修改后再发布NrG    rH   z,SELECT user_id FROM sessions WHERE token = ?z7SELECT * FROM users WHERE id = ? AND deleted_at IS NULLr   enabledu'   账户已被禁用，无法发布技能  idrN   rO   rM   u   已发布的技能数最多为u   个，暂时无法发布z
                INSERT INTO skills (title, description, province, city, district, street, detail_location, publisher_id, publisher_name, contact)
                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            provincecitydistrictstreetpublisher_namecontact)r   jsonr   r1   r	   r   r   rR   replacer   r   r   r2   r   	lastrowidcommitr   	Exceptionrollback)datafoundwordr   r   r   
auth_tokensessionuserrX   rW   r   es                r   create_skill+register_skill_routes.<locals>.create_skill   s^   || ,HHWHH]#HH&'

 !"TUUx.	L ,,_bAII)UWXJMPZ}] //+NN#\_fgp_q^st!??,D	?a/#12[]`#aF JJLC (,Dz%()9:NPS)T%U
'r  vB  uD  E(.(9!(<(6#14RS]R^^v2w#x4 JJL1 NN  !'$ $"*+)*#  ''HKKMD(3d34
 JJL	  	MMOG	 JJLs?   ;A$J  1J J <AJ )CJ J)J$$J))J, ,J>PUTc                    \         P                  P                  R 4      pV'       d   VP                  R4      '       g   \	        RR4      # VP                  R4      ^,          p\        V4      pV'       g   \	        RR4      # \        WRR7      w  rEpV'       g   \	        VR4      # \         P                  p\        VP                  R	4      VP                  R
4      VP                  R4      4      w  rV'       d   \	        R4      # \        4       p
V
P                  4       p . p. pR	V9   d*   VP                  R4       VP                  VR	,          4       R
V9   d*   VP                  R4       VP                  VR
,          4       RV9   d*   VP                  R4       VP                  VR,          4       RV9   d*   VP                  R4       VP                  VR,          4       RV9   d*   VP                  R4       VP                  VR,          4       RV9   d*   VP                  R4       VP                  VR,          4       RV9   d*   VP                  R4       VP                  VR,          4       V'       g   \	        R4      V
P                  4        # VP                  V 4       VP                  RRP                  V4       R2V4       V
P!                  4        VP                  RV 34       VP#                  4       p\%        V4      p\'        V4      VR&   \)        V4      V
P                  4        #   \*         d   pT
P-                  4        ThRp?ii ; i  T
P                  4        i ; i)rG   rH      请先登录rJ   rK   !   登录已过期，请重新登录Tr   rc   r]   r^   r_   r`   ztitle=?zdescription=?re   z
province=?rf   zcity=?rg   z
district=?rh   zstreet=?zdetail_location=?u   没有需要更新的字段zUPDATE skills SET z, z WHERE id = ?z!SELECT * FROM skills WHERE id = ?r-   N)r   rR   r1   rS   r	   rT   r   r   rk   r   r   r   r7   r   r   joinrn   r   r6   r   r   ro   rp   )r   rU   rV   r   has_permissionr   	error_msgrq   rr   rs   r   r   update_fieldsupdate_valuesupdated_skillrC   rw   s   &                r   update_skill+register_skill_routes.<locals>.update_skill   s    oo))/:+"8"8"C"C!.#66!!#&q)(/!"EsKK /EXfj.k+)!)S11|| ,HHWHH]#HH&'

 !"TUUx+	MM$$$Y/$$T']3$$$_5$$T-%89T!$$\2$$T*%56~$$X.$$T&\2T!$$\2$$T*%564$$Z0$$T(^4 D($$%89$$T*;%<= %&CD  JJL   *NN/		-0H/IWYfgKKMNN>L"OO-M-(F!/!7F:6?
 JJL	  	MMOG	 JJLs2    EL4 <
L4 BL4 4M?MMM M+z/api/skills/myc                  N   \         P                  P                  R 4      p V '       d   V P                  R4      '       g   \	        RR4      # V P                  R4      ^,          p\        V4      pV'       g   \	        RR4      # \        4       pVP                  4       p VP                  RV34       VP                  4       p. pV F/  p\        V4      p\        VRR7      VR	&   VP                  V4       K1  	  \        V4      VP                  4        #   TP                  4        i ; i)
rG   rH   rI   rJ   rK   rL   zy
                SELECT * FROM skills WHERE publisher_id = ? AND deleted_at IS NULL ORDER BY created_at DESC
            Tr+   r-   )r   rR   r1   rS   r	   rT   r   r   r   r   r3   r6   r   r7   r   r   )	rU   rV   r   r   r   r<   skillsr&   r   s	            r   get_my_skills,register_skill_routes.<locals>.get_my_skills  s    oo))/:+"8"8"C"C!+s33!!#&q)(/!"3S99x	NN  ??$DFS	$25$Nj!e$ 
 6?JJLDJJLs   A$D D$DELETEc                 z   \         P                  P                  R 4      pV'       d   VP                  R4      '       g   \	        RR4      # VP                  R4      ^,          p\        V4      pV'       g   \	        RR4      # \        WRR7      w  rEpV'       g   \	        VR4      # \        4       pVP                  4       p VP                  R	V 34       VP                  4        \        R
RRR/4      VP                  4        #   \         d   p	TP                  4        T	hRp	?	ii ; i  TP                  4        i ; i)rG   rH   r|   rJ   rK   r}   Tr~   rc   z;UPDATE skills SET deleted_at = datetime('now') WHERE id = ?successmessageu   删除成功N)r   rR   r1   rS   r	   rT   r   r   r   r   r   rn   r   r   ro   rp   )
r   rU   rV   r   r   r   r   r   r   rw   s
   &         r   delete_skill+register_skill_routes.<locals>.delete_skill1  s    oo))/:+"8"8"C"C!.#66!!#&q)(/!"EsKK /EXfj.k+)!)S11x		NNZ]e\ghKKMItYGH
 JJL	  	MMOG	 JJLs$   1D D%D  D%%D( (D:c                 
   V '       g   / # \        4       pVP                  4       p R P                  R.\        V 4      ,          4      pVP	                  RV R2V 4       VP                  4       p/ pV FS  pVR,          ^ 8  d8   \        VR,          VR,          ,          ^d,          4      pV R2WVR,          &   KH  RWVR,          &   KU  	  V  F  pW9  g   K  RWX&   K  	  VVP                  4        #   TP                  4        i ; i)	,?a;  
                SELECT
                    acceptor_id,
                    COUNT(*) as total,
                    SUM(CASE WHEN rating = 'good' THEN 1 ELSE 0 END) as positive_count
                FROM task_ratings
                WHERE rating_type = 'publisher_to_acceptor'
                  AND acceptor_id IN (z3)
                GROUP BY acceptor_id
            r/   positive_count%acceptor_idr)   r   r   r   lenr   r3   roundr   	user_idsr   r   placeholdersr<   
rating_mapr&   rater   s	   &        r   r?   9register_skill_routes.<locals>.get_bulk_user_rating_ratesP  s    Ix	88SECM$9:LNN  ' (4n 5	 	 ??$DJw<!# #&6"7#g,"F#!MND8<vQZJ=1258J=12  $,*-J' $ JJLDJJL   B+C0 	C0 0Dc                 
   V '       g   / # \        4       pVP                  4       p R P                  R.\        V 4      ,          4      pVP	                  RV R2V 4       VP                  4       p/ pV FS  pVR,          ^ 8  d8   \        VR,          VR,          ,          ^d,          4      pV R2WVR,          &   KH  RWVR,          &   KU  	  V  F  pW9  g   K  RWX&   K  	  VVP                  4        #   TP                  4        i ; i)	r   r   a|  
                SELECT
                    t.publisher_id,
                    COUNT(*) as total,
                    SUM(CASE WHEN tr.rating = 'good' THEN 1 ELSE 0 END) as positive_count
                FROM task_ratings tr
                JOIN tasks t ON tr.task_id = t.id
                WHERE tr.rating_type = 'acceptor_to_publisher'
                  AND t.publisher_id IN (z6)
                GROUP BY t.publisher_id
            r/   r   r   r   r)   r   r   s	   &        r   get_bulk_publisher_rating_rates>register_skill_routes.<locals>.get_bulk_publisher_rating_ratest  s    Ix	88SECM$9:LNN  * +7 8
 
 ??$DJw<!# #&6"7#g,"F#!MND9=ajJ>2369J>23  $,*-J' $ JJLDJJLr   N)route)
appr@   rD   rY   rx   r   r   r   r   r?   s
   &        @r   register_skill_routesr   %   s   YY}ugY.5 /5n 	YY+eWY= >" 	YY"UGY4 5. 	YY}vhY/< 0<| 	YY+eWY=I >IV 	YY%Y1 2: 	YY+hZY@ A<"H#    N)T)flaskr   r   utils.databaser   
utils.authr   r   r   utils.helpersr	   r
   utils.configr   utils.sensitive_filterr   r   r   r$   r   r   <module>r      s%    " ! S S A ) 8:rr   