Ejemplo n.º 1
0
 def new_agent(self, agent_name, agent_type, agent_price,
               agent_address, agent_protocol, agent_pin, agent_upline, pin):
     '''Add new agent'''
     bc = AgentNotifier()
     am = ManageAgentPrice(bc.dbconn, bc.cacheconn)
     new_id = am.newAgent(agent_name, agent_address, agent_type, agent_pin,
                          agent_upline, config.AGENT_DEFAULT_MARKUP,
                          agent_price, agent_protocol)
     if not new_id:
         return json.dumps({
                 'success': 0,
                 'agent_id': '',
             })
     bc.dbconn.commit()
     if am.registerProtocols(new_id, agent_protocol):
         bc.dbconn.commit()
     bc.writeNotifyOut(agent_protocol, 'add_agent_success', {
                             'agent_id': new_id,
                             'name': agent_name,
                             'pin': agent_pin,
                       })
     bc.dbconn.commit()
     return json.dumps({
             'success': 1,
             'agent_id': new_id,
         })
Ejemplo n.º 2
0
 def agent_preupdate(self, agent_id, pin):
     bc = AgentNotifier()
     c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor)
     c.execute('SELECT * FROM `agent` where `agent_id`=%s', (agent_id,))
     tmp = c.fetchone()
     if not tmp:
         return json.dumps({'success': 0,})
     self.agent_update[agent_id] = tmp
     # clear cache
     am = ManageAgentPrice(bc.dbconn, bc.cacheconn)
     am.clearAgentCache(agent_id)
     return json.dumps({'success': 1,})
Ejemplo n.º 3
0
 def agent_change_set_price(self, agent_id, set_price, pin):
     bc = AgentNotifier()
     c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor)
     c.execute ('''SELECT `product_id` FROM `agent_price`
                   WHERE `agent_id`=%s''', (agent_id,))
     to_del = c.fetchall()
     c.execute('''DELETE FROM `agent_price` WHERE `agent_id`=%s''',
                  (agent_id,))
     am = ManageAgentPrice(bc.dbconn, bc.cacheconn)
     am.generatePrice(agent_id, setpriceid=set_price)
     bc.dbconn.commit()
     c_price = DBCache(const.AGENTPRICE_PREFIX, config.DEFAULT_EXPIRE,
                       const.AGENTPRICE_SQL)
     for k in to_del:
         c_price.delete(bc.cacheconn, (agent_id, k['product_id']))
Ejemplo n.º 4
0
 def agent_postupdate(self, agent_id, pin):
     old_agent = self.agent_update.get(agent_id)
     if not old_agent:
         return json.dumps({'success': 0,})
     bc = AgentNotifier()
     c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor)
     c.execute('SELECT * FROM `agent` where `agent_id`=%s', (agent_id,))
     new_agent = c.fetchone()
     # TODO: other checks & post-update processes
     am = ManageAgentPrice(bc.dbconn, bc.cacheconn)
     if old_agent['markup'] != new_agent['markup']:
         am.changeGlobalMarkup(agent_id, int(new_agent['markup']),
           False)
     if old_agent['markup_upline'] != new_agent['markup_upline']:
         new_markup = int(new_agent['markup_upline'])
         old_markup = int(old_agent['markup_upline'])
         am.changeDownlineMarkup2(agent_id, old_markup,
           new_markup, False)
     bc.dbconn.commit()
     del self.agent_update[agent_id]
     return json.dumps({'success': 1,})
Ejemplo n.º 5
0
 def deposit_transfer(self, agent_id_from, agent_id_to, amount,
                      order, pin):
     '''Transfer deposit from one agent to another'''
     bc = AgentNotifier()
     dt = deptran.DepositTransfer(10, bc.dbconn, bc.cacheconn)
     result = {
             'success': 0,
             'balance_from': 0,
             'balance_to': 0,
         }
     am = ManageAgentPrice(bc.dbconn, bc.cacheconn)
     tmp = am.verifyAgent(agent_id_from, 'xxxx')
     if tmp['code'] != agent.AGST_WRONGPIN:
         result['message'] = 'AGENT {0} ERROR'.format(agent_id_from)
         return json.dumps(result)
     tmp = am.verifyAgent(agent_id_to, 'xxxx')
     if tmp['code'] != agent.AGST_WRONGPIN:
         result['message'] = 'AGENT {0} ERROR'.format(agent_id_to)
         return json.dumps(result)
     if dt.searchSameTransfer(agent_id_from, agent_id_to, amount, order):
         result['message'] = 'TRANSFER EXIST'
         return json.dumps(result)
     tmp = dt.transfer(agent_id_from, agent_id_to, amount, order, True)
     response = {
             deptran.AMOUNT_ZERO: 'AMOUNT IS ZERO',
             deptran.NOT_ENOUGH_BALANCE: 'NOT ENOUGH BALANCE',
             deptran.AMOUNT_NOT_NUMBER: 'AMOUNT NOT NUMBER',
             deptran.OVER_REVOKE: 'OVER REVOKE',
             deptran.SOURCE_DEST_SAME: 'SOURCE IS THE SAME AS DESTINATION'
         }
     if tmp in response:
         result['message'] = response[tmp]
         return json.dumps(result)
     dm = DepositMutation(20, bc.dbconn, bc.cacheconn)
     result['balance_from'] = dm.getBalance(agent_id_from)
     result['balance_to'] = dm.getBalance(agent_id_to)
     result['message'] = 'SUCCESS'
     result['success'] = 1
     return json.dumps(result)
Ejemplo n.º 6
0
 def set_price_change(self, pin):
     bc = AgentNotifier()
     am = ManageAgentPrice(bc.dbconn, bc.cacheconn)
     c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor)
     c.execute('SELECT DISTINCT `set_price_id` from `set_price`')
     spl = c.fetchall()
     for sp in spl:
         c.execute('SELECT `agent_id` from `agent` where `set_price`=%s LIMIT 1',
              (sp['set_price_id'],))
         ag = c.fetchone()
         if not ag:
             continue
         ag = ag['agent_id']
         c.execute('SELECT `product_id`, `sell_price` from `agent_price` '
             'WHERE `agent_id`=%s', (ag,))
         agprice = c.fetchall()
         c.execute('SELECT `product_id`, `sell_price` from `set_price` '
             'WHERE `set_price_id`=%s', (sp['set_price_id'],))
         sprice = c.fetchall()
         # find new
         old = map(lambda x: x['product_id'], agprice)
         new = map(lambda x: (x['product_id'], x['sell_price']), sprice)
         new_prod = [(x,y) for x,y in new if x not in old]
         for prod, new_price in new_prod:
             am.addProduct(sp['set_price_id'], prod, new_price, False)
         # find remove
         new = map(lambda x: x['product_id'], sprice)
         rem_prod = [x for x in old if x not in new]
         for prod in rem_prod:
             am.removeProduct(sp['set_price_id'], prod, False)
         # find changed price
         old = dict(map(lambda x: (x['product_id'], x['sell_price']), agprice))
         new = dict(map(lambda x: (x['product_id'], x['sell_price']), sprice))
         ch_price = [(x,new[x])for x in new.keys() if x in old.keys() and \
             old[x] != new[x]]
         for pid, price in ch_price:
             am.changePrice(sp['set_price_id'], pid, price, False)
     bc.dbconn.commit()
     return json.dumps({'success': 1, 'reason': ''})