Merchant.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php namespace Pay\Yspay;
  2. use Dever;
  3. class Merchant
  4. {
  5. public function selectRelate_api()
  6. {
  7. $value = Dever::input('value');
  8. $id = Dever::input('id');
  9. $data = array();
  10. if ($id) {
  11. $data = Dever::db('pay/yspay_merchant')->find($id);
  12. if ($value != $data['project_id']) {
  13. $data['relate_id'] = -1;
  14. }
  15. }
  16. $config['relate_id'] = Dever::db('pay/yspay_merchant')->config['struct']['relate_id'];
  17. $config['relate_id']['update'] = 'select';
  18. $config['relate_id']['update_search'] = 'pay/yspay/merchant.search?project_id=' . $value;
  19. $result = Dever::load('manage/database')->update_struct(array('struct' => $config), false, $data, -1, '', true);
  20. return $result;
  21. }
  22. public function search_api()
  23. {
  24. $id = Dever::input('id');
  25. $keyword = Dever::input('keyword');
  26. $where = array();
  27. if ($keyword) {
  28. $where['name'] = $keyword;
  29. }
  30. $id = Dever::input('where_id');
  31. if ($id) {
  32. $where['id_no'] = $id;
  33. }
  34. $project_id = Dever::input('project_id', 1);
  35. $project = Dever::db('pay/yspay_project')->find($project_id);
  36. return Dever::search($project['table'], $where);
  37. }
  38. public function up($account_id, $yspay_main_id, $project_id, $id, $name)
  39. {
  40. $data = array();
  41. $data['account_id'] = $account_id;
  42. $data['yspay_main_id'] = $yspay_main_id;
  43. $data['project_id'] = $project_id;
  44. $data['relate_id'] = $id;
  45. $info = Dever::db('pay/yspay_merchant')->find($data);
  46. if (!$info) {
  47. $data['name'] = $name;
  48. $data['type'] = 1;
  49. $data['status'] = 2;
  50. return Dever::db('pay/yspay_merchant')->insert($data);
  51. }
  52. return false;
  53. }
  54. public function getOther($account_id, $yspay_main_id, $relate, $relate_id, $order_num, $cash, $fenzhang = 0)
  55. {
  56. $result = array();
  57. $yspay = Dever::db('pay/yspay')->find(array('account_id' => $account_id));
  58. if ($cash && $cash > 0 && $yspay && $yspay['type'] == 2) {
  59. # 分账拆单
  60. $merchant = array();
  61. if ($relate == 2) {
  62. $merchant = Dever::db('pay/yspay_merchant')->find(array('account_id' => $account_id, 'yspay_main_id' => $yspay_main_id, 'type' => 2));
  63. if (strstr($order_num, '_')) {
  64. $temp = explode('_', $order_num);
  65. $order_num = $temp[0];
  66. }
  67. $order_num .= '_O';
  68. } else {
  69. $project = Dever::db('pay/yspay_project')->find(array('table' => $relate));
  70. if ($project) {
  71. $merchant = Dever::db('pay/yspay_merchant')->find(array('account_id' => $account_id, 'yspay_main_id' => $yspay_main_id, 'project_id' => $project['id'], 'relate_id' => $relate_id));
  72. }
  73. }
  74. if ($merchant && $merchant['mid']) {
  75. $result = array(
  76. 'yspay_main_id' => $merchant['yspay_main_id'],
  77. 'merchant_id' => $merchant['id'],
  78. 'mid' => $merchant['mid'],
  79. 'order_id' => $order_num,
  80. 'amount' => $cash,
  81. 'fenzhang' => $fenzhang,
  82. );
  83. }
  84. }
  85. return $result;
  86. }
  87. public function getInfo($account_id, $yspay_main_id, $project_id, $id, $parent, $array = false)
  88. {
  89. list($project, $table) = explode('/', $parent);
  90. $where = array();
  91. $where['account_id'] = $account_id;
  92. $data['yspay_main_id'] = $yspay_main_id;
  93. $where['project_id'] = $project_id;
  94. $where['relate_id'] = $id;
  95. $data = Dever::db('pay/yspay_merchant')->find($where);
  96. if ($array) {
  97. return $data;
  98. }
  99. $html = '';
  100. if ($data) {
  101. if (!$data['mid']) {
  102. $data['mid'] = '编辑信息';
  103. }
  104. $url = Dever::url('project/database/update?project=pay&table=yspay_merchant&set=1&where_id='.$data['id'], 'manage');
  105. $html .= '<a style="cursor:pointer" onclick="fastEdit($(this),\''.$url.'\',\'编辑信息\', \'\')">'.$data['mid'].'</a>';
  106. $step = false;
  107. if ($data['status'] == 2) {
  108. $sign = Dever::db('pay/yspay_sign')->one(array('merchant_id' => $data['id']));
  109. if ($sign && $sign['step']) {
  110. $step = $sign['step'];
  111. }
  112. }
  113. if ($data['status'] == 1) {
  114. $url = Dever::url('project/database/list?project=pay&table=yspay_cash&search_option_merchant_id='.$data['id'].'&search_option_account_id='.$data['account_id'].'&oper_table='.$table.'&oper_project=' . $project, 'manage');
  115. $html .= '&nbsp;&nbsp;<a style="cursor:pointer" href="'.$url.'">[资金流水]</a>';
  116. }
  117. if ($data['status'] == 2) {
  118. $url = Dever::url('project/database/update?project=pay&table=yspay_sign&search_option_merchant_id='.$data['id'].'&search_option_account_id='.$data['account_id'].'&where_id='.$data['id'].'&oper_table='.$table.'&oper_project=' . $project, 'manage');
  119. $html .= '&nbsp;&nbsp;<a style="cursor:pointer" onclick="fastEdit($(this),\''.$url.'\',\'签约资料\', \'\')">[签约资料]</a>';
  120. if ($step == -1) {
  121. $content = '';
  122. $title = '';
  123. $url = Dever::url('pay/yspay/sign.handle?sign_id=' . $data['id']);
  124. $html .= '&nbsp;&nbsp;<a style="cursor:pointer" href="javascript:;" onclick="load(\'' . $url . '\', \'' . $content . '\', \'' . $title . '\')">[签约提审]</a>';
  125. }
  126. if ($step == 2) {
  127. $url = Dever::url('project/database/update?project=pay&table=yspay_sign&col=cashwhere_id='.$data['id'], 'manage');
  128. $html .= '&nbsp;&nbsp;<a style="cursor:pointer" onclick="fastEdit($(this),\''.$url.'\',\'签约打款\', \'\')">[签约打款]</a>';
  129. }
  130. if ($step == 4) {
  131. $url = Dever::load('pay/yspay/sign.getAgreement', $data['id']);
  132. $html .= '&nbsp;&nbsp;<a style="cursor:pointer" data-clipboard-text="'.$url.'" class="clipboard"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 ">[签约合同]</button></a>';
  133. }
  134. }
  135. return $html;
  136. } else {
  137. return '暂无';
  138. }
  139. }
  140. public function log($merchant_id, $account_id, $type, $cash, $name)
  141. {
  142. $merchant = Dever::db('pay/yspay_merchant')->one(array('id' => $merchant_id, 'clear' => true));
  143. if ($merchant) {
  144. if (!$merchant['hf_cash']) {
  145. $merchant['hf_cash'] = $cash;
  146. }
  147. $yue = $merchant['hf_cash'] - $merchant['hf_tx_cash'];
  148. $data = array();
  149. $data['account_id'] = $account_id;
  150. $data['merchant_id'] = $merchant_id;
  151. $data['type'] = $type;
  152. $data['cash'] = $cash;
  153. $data['yue'] = $yue;
  154. $data['name'] = $name;
  155. Dever::db('pay/yspay_merchant_log')->insert($data);
  156. }
  157. }
  158. # 更新提现状态
  159. public function updateLog($id, $name, $data)
  160. {
  161. $tixian_status = Dever::param('tixian_status', $data);
  162. if ($tixian_status) {
  163. $info = Dever::db('pay/yspay_merchant_log')->one($id);
  164. if ($info) {
  165. if ($tixian_status == 1) {
  166. $cash = $info['cash'];
  167. } else {
  168. $cash = $info['cash'] * -1;
  169. }
  170. Dever::db('pay/yspay_merchant')->updateTxCash(array('where_id' => $info['merchant_id'], 'hf_tx_cash' => $cash));
  171. }
  172. }
  173. }
  174. # 检测提现状态
  175. public function checkTixian()
  176. {
  177. $where['type'] = 3;
  178. $where['tixian_status'] = 2;
  179. $data = Dever::db('pay/yspay_merchant_log')->select($where);
  180. if ($data) {
  181. foreach ($data as $k => $v) {
  182. }
  183. }
  184. }
  185. }