finorderModel.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. class flow_finorderClassModel extends flowModel
  3. {
  4. public function orderstate()
  5. {
  6. //'未付款|red,已付款|green,待确认收款|#ff6600,没付款成功|red'
  7. $arr[] = array('value'=>'0','name'=>'待付款','color'=>'red');
  8. $arr[] = array('value'=>'1','name'=>'已付款','color'=>'green');
  9. $arr[] = array('value'=>'2','name'=>'待确认收款','color'=>'#ff6600');
  10. $arr[] = array('value'=>'3','name'=>'没付款成功','color'=>'gray');
  11. $arr[] = array('value'=>'4','name'=>'付款中','color'=>'blue');
  12. return $arr;
  13. }
  14. public function getorderzt($zt)
  15. {
  16. $arr = array();
  17. foreach($this->orderstate() as $k=>$rs){
  18. if($rs['value']==$zt)$arr = $rs;
  19. }
  20. return $arr;
  21. }
  22. public function flowrsreplace($rs, $lx=0)
  23. {
  24. if($rs['ispay']==3)$rs['ishui']=1;
  25. if($rs['isplat']=='0')$rs['isplat']='';
  26. if($rs['isplat']=='1'){
  27. $rs['isplat'] = '<font color=green>是</font>';
  28. }
  29. if(in_array($rs['ispay'], array('0','2','4')) && $this->openmode==4 && $lx==1 && c('rockpay')->isConfig()){
  30. $rs['isplat'] .= '&nbsp;<button onclick="js.loading(\'处理中...\');location.href=location.href+\'&gtype=pay\'" class="btn">在去支付</button>';
  31. $gtype = $this->rock->get('gtype');
  32. if($gtype=='pay'){
  33. $barr = c('rockpay')->createOrder($rs['ordernum'], $rs['money'], $rs['subject'], $rs['body'], array(
  34. 'platid' => $rs['platid']
  35. ));
  36. if(!$barr['success']){
  37. echo $barr['msg'];
  38. }else{
  39. $this->update('`isplat`=1,`ispay`=4,`paytype`=null', $rs['id']);
  40. $this->rock->location($barr['data']);
  41. }
  42. exit;
  43. }
  44. }
  45. $jzid = arrvalue($rs,'jzid');
  46. if($lx==1 && $jzid>0){
  47. $to = m('finjibook')->rows($jzid);
  48. if($to==0){
  49. $jzid = 0;
  50. $this->update('`jzid`=0', $rs['id']);
  51. }
  52. }
  53. if($jzid>0){
  54. $url = $this->getxiangurl('finjishou', $jzid, 'auto');
  55. $rs['jzid'] = '<a href="javascript:;" onclick="js.open(\''.$url.'\')">已生成</a>';
  56. }else if($jzid=='-1'){
  57. $rs['jzid'] = '<font color=#aaaaaa>不需要</font>';
  58. }else{
  59. $rs['jzid'] = '';
  60. }
  61. return $rs;
  62. }
  63. public function flowatypearr($atypea)
  64. {
  65. foreach($atypea as $k=>$rs){
  66. if($rs['num']=='alldaisk'){
  67. $atypea[$k]['stotal'] = $this->rows('`ispay`=2');
  68. }
  69. }
  70. return $atypea;
  71. }
  72. //付款成功
  73. public function paysuccess($ids)
  74. {
  75. $ida = explode(',', $ids);
  76. foreach($ida as $id){
  77. $this->loaddata($id, false);
  78. $this->changeOrder(1);
  79. }
  80. }
  81. /**
  82. * 付款状态更新
  83. */
  84. public function changeOrder($zt)
  85. {
  86. $ispay = $this->rs['ispay'];
  87. if($ispay==$zt)return;
  88. $orderbill = $this->rs['orderbill'];
  89. $this->update(array(
  90. 'ispay' => $zt,
  91. ), $this->id);
  92. if(isempt($orderbill))return;
  93. $arr = explode(',', $orderbill);
  94. foreach($arr as $arrs){
  95. $numa = explode('|', $arrs);
  96. $flow = m('flow:'.$numa[0].'');
  97. if(method_exists($flow, 'flowordersuccess')){
  98. $flow->flowordersuccess($numa[1], array(
  99. 'ispay' => $zt,
  100. 'paytype' => $this->rs['paytype'],
  101. 'paydt' => $this->rs['paydt'],
  102. ));
  103. }
  104. }
  105. }
  106. //回调的,$ors当前单据操作的信息,$crs提交过来的一些信息
  107. protected function flowoptmenu($ors, $crs)
  108. {
  109. if($ors['num']=='bssunoup'){
  110. $this->changeOrder(1);
  111. }
  112. if($ors['num']=='bssenoup'){
  113. $this->changeOrder(3);//没付款成功
  114. }
  115. }
  116. //这个方法写搜索
  117. public function flowbillwhere($uid, $lx)
  118. {
  119. $where = '';
  120. if($lx=='yzallworder' || $lx=='yzallorder'){
  121. $where = 'and 1=2';
  122. $yezhuid = m('wuye')->getyezhuid(); //此方法我们封装好的获取当前业主id
  123. $where = "and `mknum`='wyfee' and `platid`=$yezhuid";
  124. }
  125. return $where;//返回条件
  126. }
  127. /**
  128. * 创建内部的订单
  129. */
  130. public function createOrder($subject, $money, $orderbill, $cans=array())
  131. {
  132. $ordernum = 'ro'.date('Ym').''.$this->db->ranknum('[Q]finorder', 'ordernum', 8);
  133. $uarr['ordernum'] = $ordernum;
  134. $uarr['subject'] = $subject;
  135. $uarr['moneym'] = $money;
  136. $uarr['money'] = $money;
  137. $uarr['orderbill'] = $orderbill;
  138. $uarr['createdt'] = $this->rock->now;
  139. $uarr['optdt'] = $this->rock->now;
  140. $uarr['ispay'] = 2;
  141. $uarr['body'] = '';
  142. foreach($cans as $k=>$v)$uarr[$k] = $v;
  143. $uarr['id'] = $this->insert($uarr);
  144. return $uarr;
  145. }
  146. /**
  147. * 生成记账单
  148. */
  149. public function createJizhang($ids)
  150. {
  151. $zhangid = (int)$this->option->getval('finorderzhangid','0');
  152. if($zhangid <= 0)return returnerror('未设置收款帐号');
  153. $frs = m('finount')->getone($zhangid);
  154. if(!$frs)return returnerror('收款帐号不存在');
  155. $this->accountrs = $frs;
  156. $oi = 0;
  157. $ida = explode(',', $ids);
  158. foreach($ida as $id){
  159. if($this->id != $id)$this->loaddata($id, false);
  160. $bo = $this->createJizhangs();
  161. if($bo)$oi++;
  162. }
  163. return returnsuccess('成功生成'.$oi.'个记账单');
  164. }
  165. private $accountrs;
  166. private function createJizhangs()
  167. {
  168. $rs = $this->rs;
  169. if($rs['ispay'] != '1' && (int)$rs['jzid'] != 0)return false;
  170. $applydt = $rs['paydt'];
  171. if(isempt($applydt))$applydt = $rs['createdt'];
  172. $uarr['comid'] = $rs['comid'];
  173. $uarr['type'] = 0;
  174. $uarr['money'] = $rs['money'];
  175. $uarr['mknum'] = $this->modenum.'|'.$this->id;
  176. $uarr['custname'] = $rs['createname'];
  177. $uarr['applydt'] = $applydt;
  178. $uarr['optid'] = $this->adminid;
  179. $uarr['optname'] = $this->adminname;
  180. $uarr['optdt'] = $this->rock->now;
  181. $uarr['uid'] = $this->adminid;
  182. $uarr['xguid'] = '0';
  183. $uarr['xgname'] = '';
  184. $uarr['xgdeptid'] = '';
  185. $uarr['xgdeptname'] = '';
  186. $uarr['explain'] = '订单('.$rs['ordernum'].'.'.$rs['subject'].')';
  187. $uarr['accountid'] = $this->accountrs['id'];
  188. $uarr['zhangid'] = $this->accountrs['zhangid'];
  189. $uarr['jtype'] = '销售收入';
  190. $newid = m('finjibook')->insert($uarr);
  191. $this->update('jzid='.$newid.'', $this->id);
  192. return $newid;
  193. }
  194. }
粤ICP备19079148号